Yaw value isn't correct with MPU9250.

I got an MPU9250,. I wanted to determine accurate yaw ,roll, and pitch values to use it in my project. I have used a lot of libraries and I have tried almost all the solutions posted on github and arduino forum but It didn't work. I bought another mpu9250 but it didn't help. Can anyone help me?

Since there is no information in your post, we can't help. Please read and follow the instructions in the "How to use this forum" post.

For accurate yaw angles, you must carefully calibrate the magnetometer, and take into account your magnetic declination.

I have used Kriswiner code.It was giving values but not accurate especially in yaw .

This is the Serial port readings.


MPU9250
9-DOF 16-bit
motion sensor
60 ug LSB
MPU9250 I AM 73 I should be 71
MPU9250 is online…
x-axis self test: acceleration trim within : -1.8% of factory value
y-axis self test: acceleration trim within : -2.7% of factory value
z-axis self test: acceleration trim within : 0.4% of factory value
x-axis self test: gyration trim within : 0.2% of factory value
y-axis self test: gyration trim within : -0.8% of factory value
z-axis self test: gyration trim within : -0.8% of factory value
MPU9250 bias
x y z
-187-14-151mg-7.7-2.5-3.1o/s
MPU9250 initialized for active data mode…
AK8963 I AM 48 I should be 48
AK8963 initialized for active data mode…
Mag Calibration: Wave device in a figure eight until done!
Mag Calibration done!
X-Axis sensitivity adjustment value 1.20
Y-Axis sensitivity adjustment value 1.20
Z-Axis sensitivity adjustment value 1.16
AK8963
ASAX
1.20
ASAY
1.20
ASAZ
1.16
Yaw, Pitch, Roll: 81.21, 22.64, 166.46
Yaw, Pitch, Roll: 79.48, 21.49, 166.18
Yaw, Pitch, Roll: 77.13, 21.30, 166.18
Yaw, Pitch, Roll: 74.47, 23.28, 165.75
Yaw, Pitch, Roll: 72.63, 25.11, 165.92
Yaw, Pitch, Roll: 70.80, 26.35, 165.97
Yaw, Pitch, Roll: 69.12, 28.14, 166.10
Yaw, Pitch, Roll: 67.96, 29.91, 166.74
Yaw, Pitch, Roll: 67.19, 30.65, 166.53
Yaw, Pitch, Roll: 67.46, 30.38, 166.32
Yaw, Pitch, Roll: 67.09, 30.55, 166.17
Yaw, Pitch, Roll: 67.64, 30.85, 167.98
Yaw, Pitch, Roll: 70.68, 30.42, 171.85
Yaw, Pitch, Roll: 73.07, 32.21, 174.18
Yaw, Pitch, Roll: 74.01, 34.44, 174.14
Yaw, Pitch, Roll: 74.12, 36.15, 173.44
Yaw, Pitch, Roll: 73.84, 36.52, 172.29
Yaw, Pitch, Roll: 73.80, 36.90, 170.18
Yaw, Pitch, Roll: 72.88, 36.31, 166.47
Yaw, Pitch, Roll: 71.71, 34.19, 163.31
Yaw, Pitch, Roll: 70.02, 34.39, 160.42
Yaw, Pitch, Roll: 68.95, 33.69, 157.95
Yaw, Pitch, Roll: 68.31, 33.28, 155.62
Yaw, Pitch, Roll: 66.40, 33.72, 153.34
Yaw, Pitch, Roll: 64.95, 33.76, 151.47
Yaw, Pitch, Roll: 64.45, 33.73, 150.66
Yaw, Pitch, Roll: 63.78, 33.90, 149.69
Yaw, Pitch, Roll: 63.06, 33.99, 147.94
Yaw, Pitch, Roll: 62.52, 33.80, 146.62
Yaw, Pitch, Roll: 62.14, 33.37, 145.82
Yaw, Pitch, Roll: 61.68, 33.04, 145.09
Yaw, Pitch, Roll: 61.07, 32.93, 144.65
Yaw, Pitch, Roll: 60.77, 32.65, 144.75
Yaw, Pitch, Roll: 60.27, 33.37, 145.05
Yaw, Pitch, Roll: 60.20, 34.11, 145.45
Yaw, Pitch, Roll: 59.81, 34.88, 145.29
Yaw, Pitch, Roll: 59.24, 36.08, 144.94
Yaw, Pitch, Roll: 58.85, 36.61, 144.86
Yaw, Pitch, Roll: 58.86, 36.57, 144.40
Yaw, Pitch, Roll: 58.58, 36.45, 144.08
Yaw, Pitch, Roll: 58.45, 36.44, 143.86
Yaw, Pitch, Roll: 57.92, 36.40, 143.33
Yaw, Pitch, Roll: 57.93, 35.99, 143.02
Yaw, Pitch, Roll: 57.34, 36.29, 142.57
Yaw, Pitch, Roll: 56.86, 36.46, 142.05
Yaw, Pitch, Roll: 56.41, 36.57, 141.55
Yaw, Pitch, Roll: 56.12, 36.34, 141.78
Yaw, Pitch, Roll: 55.17, 36.34, 141.61
Yaw, Pitch, Roll: 54.40, 35.98, 141.27
Yaw, Pitch, Roll: 53.75, 35.36, 140.63
Yaw, Pitch, Roll: 53.36, 34.70, 139.68
Yaw, Pitch, Roll: 57.16, 33.47, 138.86
Yaw, Pitch, Roll: 53.69, 34.27, 138.02
Yaw, Pitch, Roll: 54.01, 33.84, 138.49
Yaw, Pitch, Roll: 55.28, 33.60, 139.81
Yaw, Pitch, Roll: 55.27, 33.74, 140.50
Yaw, Pitch, Roll: 54.50, 33.11, 138.85
Yaw, Pitch, Roll: 54.62, 33.14, 138.95
Yaw, Pitch, Roll: 54.90, 33.18, 138.67
Yaw, Pitch, Roll: 54.82, 32.95, 137.52
Yaw, Pitch, Roll: 54.67, 32.82, 136.33
Yaw, Pitch, Roll: 54.66, 32.53, 135.61
Yaw, Pitch, Roll: 54.27, 32.65, 135.11
Yaw, Pitch, Roll: 54.03, 32.50, 134.70
Yaw, Pitch, Roll: 53.39, 32.59, 133.93
Yaw, Pitch, Roll: 53.17, 32.47, 133.41
Yaw, Pitch, Roll: 53.07, 32.36, 133.06
Yaw, Pitch, Roll: 53.08, 32.31, 132.62
Yaw, Pitch, Roll: 53.12, 32.03, 132.21

absoluteMagnetoCalib.ino (1.71 KB)

MPU_fux_BNO_mBias.ino (50.5 KB)

quaternionFilters.ino (9.19 KB)

Kris Winer's code for the MPU9250 has NEVER worked properly, because it has a fundamental error in assigning the magnetometer axes. Winer's work was a complete waste of many people's time.

The error and the correction are described here. You still need to calibrate the magnetometer properly, and take into account your magnetic declination.

Thanks.
One of Mpu9250 showing "I am 73 I should be 71" then it abort. What does it means and how to fix it,if it's possible?

Wrong I2C address. Fix the code, or check for bad solder connections to the sensor.

In a MPU register there is a number stored that is used to reply to the WhoAmI register querry. Typically, if the WhoAmI fails a fatal error should be produced and initialization stops. What appears to be happening is that your library in use does do the WhoAmI querry but continues on with the initialization regardless.

I would expect your MUP9250 MMU unit is not being initialized properly with the WhoAmI failure.

I have encountered this issue when writing my own MPU9250 library. If you were to look at the MPU9250 Register data sheet, you will find that WhoAmI register can return a range of numbers.

Your yaw values looks like you are being given numbers from a discharging gyro, slowly being bled off from an improper setup.

The MPU9250 works very well with SPI communications.

Your yaw values looks like you are being given numbers from a discharging gyro, slowly being bled off from an improper setup.

The yaw values are wrong for a completely different reason.