Ive come across some potentially useful calibration commands for the MPU 9250 9DOF accelerometer that are not working as I think they should.
Im using the MPU9250-master library (MPU9250.h) on an Arduino Mega. The ifdefs for the Teensy have been commented out.
My program simply exercises the loadCalibration and saveCalibration routines from the "emprom_utils.h" library. There are no errors but the mag scale and bias values that come back after a "loadCalibration" are not the values from the saveCalibration.
Could it be the Mega is unable to use eeprom_utils do you see a problem ?
The code:
#include "MPU9250.h"
#include "eeprom_utils.h"
#include <SoftwareSerial.h>
#include <SabertoothSimplified.h>
MPU9250 mpu;
SoftwareSerial SWSerial(NOT_A_PIN, 4); //declare the Pin 4 to be used to communicate with Sabertooth
SabertoothSimplified ST(SWSerial); //open a serial COM on previously identified pin
int foo =1;
void setup()
{
Serial.begin(115200);
Wire.begin();
SWSerial .begin(9600);
delay(2000);
mpu.setup(Wire);
// load from eeprom
Serial.println("LOAD calibration 3");
loadCalibration();
delay(2000);
Serial.println("print init calibration 1");
mpu.printCalibration();
Serial.println(" ");
// calibrate
mpu.calibrateAccelGyro();
mpu.calibrateMag();
delay(1000);
// save to eeprom
Serial.println("SAVE calibration 2");
saveCalibration();
Serial.println("print calibration 2");
mpu.printCalibration();
Serial.println(" ");
// load from eeprom
Serial.println("LOAD calibration 3");
loadCalibration();
Serial.println("print calibration 3");
mpu.printCalibration();
}
void loop()
{
}
OUTPUT:
MPU9250 WHO AM I = 71
MPU9250 is online...
AK8963 WHO AM I = 48
Calibration values:
X-Axis sensitivity adjustment value 1.22
Y-Axis sensitivity adjustment value 1.23
Z-Axis sensitivity adjustment value 1.18
X-Axis sensitivity offset value 0.00
Y-Axis sensitivity offset value 0.00
Z-Axis sensitivity offset value 0.00
LOAD calibration 3
calibrated? : NO
load default values
print init calibration 1
< calibration parameters >
accel bias [g]:
5.00, -8.00, -1.00
gyro bias [deg/s]:
1.50, -0.50, 0.70
mag bias [mG]:
186.41, -197.91, -425.55
mag scale []:
1.07, 0.95, 0.99
MPU9250 bias
x y z
-86 -37 -11 mg
-0.9 0.3 0.8 o/s
Mag Calibration: Wave device in a figure eight until done!
mag x min/max:
196
-77
mag y min/max:
179
-76
mag z min/max:
108
53
Mag Calibration done!
AK8963 mag biases (mG)
108.16, 93.79, 141.04
AK8963 mag scale (mG)
0.71, 0.76, 3.58
SAVE calibration 2
print calibration 2
< calibration parameters >
accel bias [g]:
-86.91, -37.84, -11.17
gyro bias [deg/s]:
-0.95, 0.25, 0.84
mag bias [mG]:
108.16, 93.79, 141.04
mag scale []:
0.71, 0.76, 3.58
LOAD calibration 3
calibrated? : NO
load default values
print calibration 3
< calibration parameters >
accel bias [g]:
5.00, -8.00, -1.00
gyro bias [deg/s]:
1.50, -0.50, 0.70
mag bias [mG]:
186.41, -197.91, -425.55
mag scale []:
1.07, 0.95, 0.99