Dual MPU9250 Magnetometer

Hello, I am trying to get the Yaw readings from 2 MPU9250s using this library ( GitHub - hideakitai/MPU9250: Arduino library for MPU9250 Nine-Axis (Gyro + Accelerometer + Compass) MEMS MotionTracking™ Device ). The problem I am getting is that when I added another MPU9250, the output becomes quite unpredictable. What I mean is, when I rotate one MPU, it seems to affect the values of the other even though it is stationary. And the values of the other MPU is also quite unresponsive and all in all, it is unpredictable and I cannot understand why. My codes for this is attached as a file…

Attempted solutions I tried was using another library from ( https://github.com/bolderflight/MPU9250.git ) however, when I try to change the xyz values to degrees using this formula, angles = atan2(IMU.getMagY_uT(), IMU.getMagX_uT()) *180 /3.14), derived from (Converting three axis magnetometer to Degrees - Arduino Stack Exchange) The results I got from testing just one MPU9250 were not exactly accurate and thus I did not move on to try it with 2 modules.

Another attempt was to try using another library from (GitHub - kriswiner/MPU9250: Arduino sketches for MPU9250 9DoF with AHRS sensor fusion) but I could not get it to work due to my inexperience.

Any help would be great! Thank you :slight_smile:

DualMPU.ino (1.5 KB)

The Kriswiner library for the MPU-9250 does not work.

You need to declare two instances of the library object, but here you declare only one.

MPU9250 mpu;
//MPU9250 mpu2;

No library will work properly to get orientation angles, until you calibrate the sensor.

Hello, thank you for the reply! The declaration of the second object was a mistake I made when trying to troubleshoot and I forgot to uncomment it so sorry for the misunderstanding.

Regarding the calibration of the sensor, I have a couple of questions. In order to calibrate, it seems I must wave the sensor in a figure 8 pattern, however, the project I am working on would not allow the user to wave the sensor in a figure 8 pattern, so the question am I suppose to hardcode the measured calibrated values before I implement the sensor and if so how do I do it?

Here is the very best overview on accelerometer and magnetometer calibration. There are simpler procedures, but they don't work as well.

To calibrate the gyro, just collect and average several hundred readings for each axis at startup, with the sensor held still, then compute the averages and subtract them from subsequent readings.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.