Hello everybody, i have some trouble rotating a 3D box in processing with data from a arduino with a BNO055 module (sensor module, gyro), and the thing is that if i run my window, the first ~5 seconds are perfect, after that, rotateZ() is getting bugged and its acting exactly like rotateX() and it never recoveres, if i restart the program (only the program, not the Arduino) the thing keeps happening and i don’t know why, does somebody have an idea? Thanks in advance! (also, this is my first post, sorry if the category is wrong)
EDIT: Also, i’m 99.99% sure that each axis its receiving its correct data (its looking like it does, nothing wrong).
The processing code:
import processing.serial.*;
Serial myPort;
void setup() {
myPort = new Serial(this, "COM5", 9600);
size(800, 400, P3D);
background(200, 200, 200);
frameRate(60);
}
void draw() {
if ( myPort.available() > 0)
{
String val = myPort.readStringUntil('\n');
if(val != null)
{
println(val); //the data will be received as: X, Y, Z
String[] allValues = split(val, ',');
if(allValues.length > 2)
{
background(0, 0, 0);
lights();
pushMatrix();
translate(width/2, height/2, 100);
rotateX(radians(float(allValues[1])));
rotateY(radians(float(allValues[0]))); //pitch
rotateZ(radians(float(allValues[2]))); //roll
stroke(255, 255, 255);
strokeWeight(16);
noFill();
box(100);
popMatrix();
textSize(32);
text("X: " + allValues[1] + " Y: " + allValues[0] + " Z: " + allValues[2], 4, height - 8);
}
}
}
}
The arduino code:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#define sampleRateDelay 20
Adafruit_BNO055 bno = Adafruit_BNO055(55);
void setup() {
Serial.begin(9600);
if(!bno.begin())
while(1);
delay(1000);
bno.setExtCrystalUse(true);
}
void loop() {
sensors_event_t event;
bno.getEvent(&event);
String outputData = (String((float)event.orientation.x) + "," +
String((float)event.orientation.y) + "," + String((float)event.orientation.z));
Serial.println(outputData);
delay(sampleRateDelay);
}