MPU6050 DMP Example - Packet Size Issue

Hi everyone,

I am using the Jeff rowberg I2cdev library to access my MPU6050. I am running the DMP6 example sketch successfully to read yaw, pitch and roll (i2cdevlib/MPU6050_DMP6.ino at master · jrowberg/i2cdevlib · GitHub).

I was wondering that in the following code where a 42 byte packet is read:

else if (mpuIntStatus & 0x02) {
        // wait for correct available data length, should be a VERY short wait
        while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

        // read a packet from FIFO
        mpu.getFIFOBytes(fifoBuffer, packetSize);
        
        // track FIFO count here in case there is > 1 packet available
        // (this lets us immediately read more without waiting for an interrupt)
        fifoCount -= packetSize;

Is it possible to replace this line

mpu.getFIFOBytes(fifoBuffer, packetSize);

with this

mpu.getFIFOBytes(fifoBuffer, packetSize-28);

Because the quaternions are only present in the first 14 bytes which are being used to calculate ypr. Rest contains the raw accel and raw gyro readings which I don't need.

Thanks in advance.

Johnny1010:
Hi everyone,

I am using the Jeff rowberg I2cdev library to access my MPU6050. I am running the DMP6 example sketch successfully to read yaw, pitch and roll (i2cdevlib/Arduino/MPU6050/examples/MPU6050_DMP6/MPU6050_DMP6.ino at master · jrowberg/i2cdevlib · GitHub).

I was wondering that in the following code where a 42 byte packet is read:

else if (mpuIntStatus & 0x02) {

// wait for correct available data length, should be a VERY short wait
       while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

// read a packet from FIFO
       mpu.getFIFOBytes(fifoBuffer, packetSize);
       
       // track FIFO count here in case there is > 1 packet available
       // (this lets us immediately read more without waiting for an interrupt)
       fifoCount -= packetSize;




Is it possible to replace this line 

mpu.getFIFOBytes(fifoBuffer, packetSize);

with this

mpu.getFIFOBytes(fifoBuffer, packetSize-28);


Because the quaternions are only present in the first 14 bytes which are being used to calculate ypr. Rest contains the raw accel and raw gyro readings which I don't need.

Thanks in advance.

You may be able to collect the 14 bytes and then trigger a reset to discard the remaining bytes:

mpu.resetFIFO();// clear the buffer and start over to discard the remaining bytes.

You would have to retrieve all 48 bytes or get what you need and reset the buffer to discard the remaining bytes in the FIFO buffer.

Modification of the fifo buffer packet size would require you to modify the already compiled program you are loading into the MPU6050. (I wish I could find the source code for this) see Line : 89 in file MPU6050_6Axis_MotionApps20.h

/* Source is from the InvenSense MotionApps v2 demo code. Original source is

  • unavailable, unless you happen to be amazing as decompiling binary by
  • hand (in which case, please contact me, and I'm totally serious).
  • Also, I'd like to offer many, many thanks to Noah Zerkin for all of the
  • DMP reverse-engineering he did to help make this bit of wizardry
  • possible.
    */

PacketSize = 42; referenced in MPU6050_6Axis_MotionApps20.h Line 527
See Line 120 for the FIFO buffer structure

The compiled binary code loaded into the mpu6050 starts on line 133

Let us know if you find a way to change the fifo buffer structure

Z