Skip to content

MPU6050_DMP6 Example Improvements #15

@wolfmanjm

Description

@wolfmanjm

Following up on the fixes from issue #13...

In the example as you suggested fifoCount should be converted to uint16_t.
This is important because occasionally, for whatever reason, the fifoCount is more than 42, quite often around 300 which would overflow the 8 bit fifoCount.

Related to this, and something that was causing me grief by corruption, there needs to be a check that when/if fifoCount is bigger than expected we do not overflow the fifoBuffer.. I added this check to protect against that.

   // read FIFO content, make sure we do not overflow our buffer
    if(fifoCount <= sizeof fifoBuffer) {
            accelgyro.getFIFOBytes(fifoBuffer, fifoCount);

    }else{
            Serial.print("Trying to read too much FIFO ");
            Serial.println(fifoCount);
            accelgyro.resetFIFO();
            return;
    }

I think at least one reason for fifoCount being bigger than expected is if something causes the interrupt to be delayed (like a delay(1000)) in the loop.

Maybe the fifo could be read in the interrupt handler itself? That would avoid the fifo filling up.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions