LISMDL AltImu-10 v5 and Teensy 3.2 Magnetometer accuracy issues

I am trying to get the magnetometer to read the field off a induced coil and I am getting largely varying values where the magnitude of the magnetic usually varies up and down 10% but occasionally doubles. I calibrated using this method and used the calibration program that was included in the LSMDL arduino library. Attached is the code IMU_Test.ino (1.8 KB) used this code to get readings. Here is an attachment of some sample data as wellimutesting.txt (22.9 KB)

I am not sure what to try now to improve the accuracy. Any suggestions would be appreciated.


Hello, Ori.

We don’t have any experience with that calibration method, but I took a quick look at your Arduino code and there a couple things you are doing that might help make your results more accurate. In particular, it looks like some of the calculation you are doing to account for soft-iron distortion is not accurately reflecting the reference you linked to:

const float magScale_X = delt_x/delt;
const float magScale_Y = delt_y/delt;
const float magScale_Z = delt_z/delt;

should be:

const float magScale_X = delt/delt_x;
const float magScale_Y = delt/delt_y;
const float magScale_Z = delt/delt_z;

Also, it looks like you are trying to calculate the magnitude of the resultant magnetic field vector in magAll and magA, but in magA, you end up using a multiplication sign instead of a plus sign. You wrote:

float magA = sqrt(xV*xV+yV*yV*zV*zV);

and I suspect you want:

float magA = sqrt(xV*xV + yV*yV + zV*zV);

Outside of those changes, it looks like you are sampling every second, which is pretty slow. You might try sampling faster and taking a running average of those samples.


1 Like

thanks, i fixed it and my numbers are looking better, but still seem to vary more than I would like.
How much would you suggest I sample?
Also, if it is reading at a specific non-zero value at a position when the coil is not inducting a field, does that mean I calibrated it incorrectly? I guess I am confused on how the zero-guass level works.

You could start at something like ten times as fast (10Hz) and see how that goes.

If your non-zero values are pretty close to zero, then your calibration might have been fine. One thing to keep in mind is that while the calibrate sketch is running, you should rotate the AltIMU in all directions. If it helps, you can imagine that the AltIMU is a paintbrush, and you are trying to paint the entire inside of a basketball.


How would I verify the accuracy of the magnetometer? I have been calibrating it and I have it fairly similar to that of the readings of my phone.

Checking one sensor’s measurements against another, known-working sensor like what you are doing seems like a reasonable way to check the accuracy.


You should verify that as you rotate the compass through 360 degrees, the X and Y magnetometer readings map to a circle centered on the XY plane, as discussed here and shown below: Tutorial: How to calibrate a compass (and accelerometer) with Arduino | Underwater Arduino Data Loggers

This compass is centered and scaled, but still needs to have the elliptical aberration corrected. If the correction is not made, the compass may exhibit directional errors of 10 degrees or more, in certain directions.