Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPU6050 DMP - Reading the whole packet #284

Open
AbdullahAhmed3 opened this issue Dec 30, 2016 · 2 comments
Open

MPU6050 DMP - Reading the whole packet #284

AbdullahAhmed3 opened this issue Dec 30, 2016 · 2 comments

Comments

@AbdullahAhmed3
Copy link

Hi everyone,

I am running the DMP6 example sketch successfully to read yaw, pitch and roll (https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/examples/MPU6050_DMP6/MPU6050_DMP6.ino).

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.

@jrowberg
Copy link
Owner

jrowberg commented Jan 1, 2017

Reading only 14 bytes won't work if the DMP is still generating 42-byte packets, since the remaining data will remain in the FIFO buffer and the next 14-byte read will get something which is not DMP data. You have to read the entire packet out each time, even if you ignore some of the data.

What you actually want to do is reconfigure the DMP such that it doesn't put anything except the DMP quaternion into the output stream. However, I am unsure how to do this (although I believe it's technically possible).

@AbdullahAhmed3
Copy link
Author

Hi Jeff,

Thanks for the reply. I might have found a way around this, I am reading only the 14 bytes and then I reset the FIFO this way the new data that appears is always the correct 42-byte DMP data. This isn't of course the best way but seems to be working so far. Reason for reading just the 14 bytes is of course to save the time.

I just had another query, that is it possible to rearrange the FIFO data like if I want to swap the gyro readings in the FIFO with the acceleration data. Because I don't want the gyro readings, I only need the accel and quaternions so if they could both be present in the first 26 bytes so I could just read that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants