Hello, I'm new here, looking for some answers to our beloved MPU 6050. I had the same problem before but a friend gave me a hand and explain something about that it wasn't aligned. At the processing code, not at the arduino code. What he did was to realign if is not aligned. I don't know how it really works but it works.
while (port.available() > 0) {
int ch = port.read();
print((char)ch);
if (aligned < 4) {
// make sure we are properly aligned on a 14-byte packet
if (serialCount == 0) {
if (ch == '$') aligned++; else
{
aligned = 0;
serialCount=0;
}
} else if (serialCount == 1) {
if (ch == 2) aligned++; else
{
aligned = 0;
serialCount=0;
}
} else if (serialCount == 12) {
if (ch == '\r') aligned++; else
{
aligned = 0;
serialCount=0;
}
} else if (serialCount == 13) {
if (ch == '\n') aligned++;else
{
aligned = 0;
serialCount=0;
}
}
//println(ch + " " + aligned + " " + serialCount);
serialCount++;
if (serialCount == 14) serialCount = 0;
} else {
if (serialCount > 0 || ch == '$') {
teapotPacket[serialCount++] = (char)ch;
if (serialCount == 14) {
serialCount = 0; // restart packet byte position
// get quaternion from data packet
q[0] = ((teapotPacket[2] << 8) | teapotPacket[3]) / 16384.0f;
q[1] = ((teapotPacket[4] << 8) | teapotPacket[5]) / 16384.0f;
q[2] = ((teapotPacket[6] << 8) | teapotPacket[7]) / 16384.0f;
q[3] = ((teapotPacket[8] << 8) | teapotPacket[9]) / 16384.0f;
for (int i = 0; i < 4; i++) if (q[i] >= 2) q[i] = -4 + q[i];
// set our toxilibs quaternion to new data
quat.set(q[0], q[1], q[2], q[3]);
Maybe this can be helpful, or maybe not. But just in case, it didn't work and now it works (with some other issues)