I am trying to build a 9-DOF IMU using the MPU-9250 chip which contains a gyro, accelerometer and compass. I have successfully realized 6-DOF sensor fusion using the DMP chip and Sparkfun's library, but I still have some yaw drift which is why I want to use its onboard compass for 9-DOF.

The DMP unfortunately can't do that so I tried kriswiner's work on 9-DOF sensor fusion which seemed to work but after I rotate the PCB, the yaw moves in the correct direction but it then slowly returns back to where it started, without me moving the PCB any more. This happens with many different sensor fusion libs, some more some less severe.

I have also tried just reading the raw mx and my values and reading the heading using atan2(my, mx) which made things a little better but still a 360° real-life rotation did not correspond at all to a 360° rotation on the chip.

Is this a known problem with the MPU-9250 and I am missing something completely obvious, or what could be wrong here?

Thank you for any help!

1 Answer 1


Ok, I have finally found the issue, and I am feeling very, very stupid.

  1. I needed to calibrate the magnetometer with the figure-8 movement
  2. I put a gigantic solid-metal 18650 Li-ion cell right next to the magnetometer chip...

EDIT: after replacing the 18650 with a polymer battery that is far away from the chip, things got a little better but both sensors in both devices still return garbage values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.