IMU - MPU-9250

Hello, dear geniuses,

I am working with an IMU model MPU-9250 and I am able to read data from it but I just want to ask if there is some sort of a filter or something to give me more accurate data with least fluctuations.

It is my first post on this website so I am so sorry if I did anything wrong.


I only care about yaw readings which I want it to give me the angle of rotation from 0-359 degrees, the IMU will be later mounted on a robotic ground vehicle.
I am using the code attached below.

Thank you so much in advance :slight_smile:

IMU_3.ino (1.98 KB)


I use the Boulder Flight Systems 9250 library.

I read from the FIFO buffer and then average the FIFO buffer readings to get the values to send to the MahonyQuaternionUpdate function.

I use the MahonyQuaternionUpdate function to generate Quaternion values from the IMU data. I then use the Quaternion values to obtain Euler angles.

Euler Angle code using Quaternion values.

float yaw   = atan2(2.0f * (q[1] * q[2] + q[0] * q[3]), q[0] * q[0] + q[1] * q[1] - q[2] * q[2] - q[3] * q[3]);
float pitch = -asin(2.0f * (q[1] * q[3] - q[0] * q[2]));
float roll = atan2(2.0f * (q[0] * q[1] + q[2] * q[3]), q[0] * q[0] - q[1] * q[1] - q[2] * q[2] + q[3] * q[3]);

Do not double post.