Can't get MPU-9250 Sensor to work as compass

Hello there!

After several hours of trying to get my MPU-9250 to output it's heading, I thought maybe someone in this forum is able to help me. I am using it with an Arduino Uno R3.

I have tried every MPU-9250 library I found, especially SparkFun's (GitHub - sparkfun/SparkFun_MPU-9250_Breakout_Arduino_Library: Arduino sketch for MPU-9250 9DoF with AH) which is based on kriswiners. I also tried kriswiners library and the Bolderflight library, but never got correct results. The heading is sometimes negative, never over 180°, and so on... I have calibrated it with a figure 8 movement several times, still, no correct results.

Is there any good tutorial I could follow? All I want is the compass heading, nothing else.

Would greatly appreciate any help!

You need to properly calibrate the magnetometer for it to work at all. After that, the code is pretty simple, no library needed.

heading = atan2(mag_y, mag_x)*180./PI; //in degrees, magnetometer held level, Z straight down.

Here is an overview of the calibration process.

It seems like the SparkFun program also does a calibration process in the beginning, but my heading is always negative, so is that calibration just not good enough?

Correct.