"MPU6050_DMP6.ino" and "MPUTeapot.pde"

Hello,

I have 2 questions concerning Sketch “MPU6050_DMP6.ino” for Arduino and “MPUTeapot.pde” for Processing.

https://github.com/sparkfun/MPU-9150_Breakout

I have read these documents, but I have not figured these out yet:

  1. What do these values (fifoBuffer[0], [1], [4], [5], [8], [9], [12], [13]) in “MPU6050_DMP6.ino” correspond to the values of FIFO of MPU6150 or MPU9150 (or Gyro-X, Y, Z, Accelometer-X, Y, Z, etc.)?

(from line 337)
#ifdef OUTPUT_TEAPOT
// display quaternion values in InvenSense Teapot demo format:
teapotPacket[2] = fifoBuffer[0];
teapotPacket[3] = fifoBuffer[1];
teapotPacket[4] = fifoBuffer[4];
teapotPacket[5] = fifoBuffer[5];
teapotPacket[6] = fifoBuffer[8];
teapotPacket[7] = fifoBuffer[9];
teapotPacket[8] = fifoBuffer[12];
teapotPacket[9] = fifoBuffer[13];
Serial.write(teapotPacket, 14);
teapotPacket[11]++; // packetCount, loops at 0xFF on purpose
#endif

  1. What do these lines in “MPUTeapot.pde” actually do (Shifts bits, bitwise OR, and / 16384.0f ???) ?

(from line 169)
// 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 >= 2) q = -4 + q*;*
Thank you in advance.

Hello jicx,

For question 1, these values correspond to quaternion values calculated by the mpu.

By definition, a quaternion has 1 real part and 3 imaginary parts, hence a total of 4 uint16_t values.

Serial.write() function transmits bytes (i.e. 8bits) while a uint16_t is 16 bits hence you have 8 bytes transmitted, two for each quaternion part.

As for question 2, at processing, the << and | are bitwise operators, which are used to reconstruct each of the uint16_t quaternion values from two 8bit values.