mpu-9250 IMU- starting pitch and yaw help

Im using the mpu-9250 IMU and the arduino nano. I need help figuring out how to get the program to use the starting pitch angle (currently if the IMU is started at an angle, the pitch reads 0 and moves from there).

Also the yaw does not seem to work and I need help fixing it. It just seems to stay around the same figure no matter what direction I point the IMU- it will only fluctuate slightly for a moment, then goes back.

Im using this example (I have removed the LCD code):

https://github.com/sparkfun/SparkFun_MPU-9250_Breakout_Arduino_Library/blob/master/examples/MPU9250BasicAHRS/MPU9250BasicAHRS.ino

Attached is my current code

MPU9250minimum.ino (8.17 KB)

You need to go through the calibration procedure, at the very least for the magnetometer.

jremington:
You need to go through the calibration procedure, at the very least for the magnetometer.

Thanks, I'll try that for the yaw issue.

This also solved the starting pitch issue- well kind of. The code always calibrates the gyro and accelerometer causing the pitch to start at zero. By commenting out the line below I now get a starting pitch figure.

myIMU.calibrateMPU9250(myIMU.gyroBias, myIMU.accelBias);

I think I will just run the calibration one time on a level surface, then hard code the gyroBias and accelBias that it comes up with. If that makes sense.