LIS3MDL BANNED Calibration

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bhf
 
Posts: 3
Joined: Mon Apr 27, 2020 11:50 pm

LIS3MDL BANNED Calibration

Post by bhf »

I have been wanting to build a digital compass from MEMS magnetometers for a while and was hugely excited to see the Clue with it's prepackaged built in display and assortment of sensors, including the LIS3MDL. I am new to Python, Circuit Python, and magnetometers, so I hope I am not treading over old ground.

I wrote a quick program to record the maximum and minimum values for each axis and I rotated the Clue board around all three axis multiple times. I tried to keep the Clue away from known iron (at least to the limit of the USB cable) and got the following max and min values for each axis:
X; +80.74, -28.5
Y: +21.10, -88.76
Z: 120.3, +10.89

I was concerned when I saw that the ranges were nowhere close to each other. But possible good news is that the range of values is almost the same for each axis:
X: 109.7 (0.03% from average or ranges)
Y: 109.9 (0.24% from average of ranges)
Z: 109.4 (0.21% from average of ranges)

So it looks like a simple offset for each axis will bring them all into the same range of values. The LIS3MDL was calibrated at the factory, and while I wouldn't expect the absolute values to be the same (different magnetic declination, different sources of hard/soft iron), I am surprised at how different the ranges for each axis are.

Questions:
1. Has anyone made a compass from the Clue, and if so can they share pointers (pun intended)?

2. Are the max/min values I am seeing normal? The ST datasheet says the magnetometer was calibrated at 2.5V, and the Clue runs it at 3.3V. Could this account for the difference?

3. If I computed X. Y, Z offsets so that all three axis are on the same range, should I put these offsets in the LIS3MDL internal calibration table, or store the corrections in an external table in my program?

4. Is it likely that this calibration will have to be run every time I use the Clue as a compass to account for different magnetic conditions at each location?

User avatar
kevinjwalters
 
Posts: 1025
Joined: Sun Oct 01, 2017 3:15 pm

Re: LIS3MDL BANNED Calibration

Post by kevinjwalters »

There's some discussion in this area on: Two CLUEs, two very different magnetometer readings.

It would be nice if there was some way of doing a simple calibration on the CLUE's lis3mdl. Even if it was another uf2 that was temporarily plonked on the board that would be ok and would be easier for CircuitPython programmers who aren't familiar with the Arduino build process. I think the lis3mdl has its own nvram for storing this?

This video suggests there's a calibration program somewhere: Sensor Saturday - On-device Magnetometer Calibration. It says Sensor Lab on it...

User avatar
kevinjwalters
 
Posts: 1025
Joined: Sun Oct 01, 2017 3:15 pm

Re: LIS3MDL BANNED Calibration

Post by kevinjwalters »

@bhf Did you get any further with this?

I find myself reading through https://github.com/lancaster-university ... brator.cpp - MicroPython's MicroBitCompass.calibrate looks like it stores the values in non-volatile memory and from my tests it survives a power cycle.

User avatar
kevinjwalters
 
Posts: 1025
Joined: Sun Oct 01, 2017 3:15 pm

Re: LIS3MDL BANNED Calibration

Post by kevinjwalters »


User avatar
kevinjwalters
 
Posts: 1025
Joined: Sun Oct 01, 2017 3:15 pm

Re: LIS3MDL BANNED Calibration

Post by kevinjwalters »

I've been playing with some visual calibration code along the same lines, see Magnetometer calibration with visualisation in CircuitPython.

I'm interested in the answer to Q3 too. I'd suspect for Q4 it only matters if you put the CLUE in a very different environment - vehicles would be an interesting test. Having said that, I have metal supports in my desk which affect it a lot.

I've noticed the BBC micro:bit has tilt compensation with the aid of the accelerometer. There's also a ticket for how this doesn't work well if there's vibrations from movement possibly including smooth non-accelerating movement.

User avatar
kevinjwalters
 
Posts: 1025
Joined: Sun Oct 01, 2017 3:15 pm

Re: LIS3MDL BANNED Calibration

Post by kevinjwalters »

I've almost finished some code now that stores the values using CLUE's nvm to let a basic calibration be done once and preserved. I hadn't realised this but it's how the humble micro:bit works.

In terms or practical use, I was surprised by some 20-30 degree deviation on a traditional compass as I walk around my abode. There must be a certain art to using these for heading in the real world at ground level. I've also seen some notes somewhere that suggest battery packs can have a significant effect on the magnetometer reading.

Locked
Please be positive and constructive with your questions and comments.

Return to “CLUE Board”