LSM303DLH Compass Reading, Non Linear

Hello All,

Got a few questions and comments regarding the performance of the LSM303 as a compass:

I had to hard solder the SCL and SDA to my Arduino inputs to reduce strain induced heading errors. The header pins just were not sufficient for my application.

The compass is now consistent in its calibration readouts (min,max) and subsequently, its heading.

What I am having trouble with is the linearity from 0-360deg. 0deg is perfect N but if I rotate it 90deg at a time the reading is off by 10% until ~315deg then it becomes correct again. Has anyone encountered this before and is there a preferred routine to calibrate this out?

The chip is consitent, so I can write an offset routine to correct it but I am worried about the other 50 chips I may use in the future. I really dont want to characterize and adjust each one using the code.

Any thoughts or suggestions?

I have not encountered this, but I don’t think I have really inspected the output of the magnetometer enough to figure out if is off by 10%. It will usually be off by some amount because the magnetic field does not point exactly north, so make sure you account for that.

My preferred method to calibrate the magnetometer is to take a couple thousand readings while turning the IMU in all possible directions, and then plot the results using a spreadsheet program. To get an idea of what the raw data will look like, take a look at the plot in this blog post by one of our customers:

bot-thoughts.com/2011/04/qui … on-in.html

As you can see, most of the points are close to the surface of an ellipsoid (stretched sphere), but there are some outliers. It’s not a great idea to just use the minimum and maximum readings for your calibration because your calibration would be unduly affected by those outliers. Just by eyeballing some plots of the raw data, you should be able to tell what the bounds of the ellipsoid are and use those as your calibration values. You want to pick calibration values that make the scaled vectors look like a sphere of radius 1 centered at 0,0,0.

If you’re going to be calibrating 50 boards, you might want to use this python program I wrote to automatically choose a calibration. I expect it will be faster and less error-prone than eyeballing. This script is still under development and we cannot really support it, but if you know what you are doing you can probably figure it out: github.com/DavidEGrayson/imu-calibrator

–David

David,

Thank You for the calibration script. We will likely crib off that in our future efforts.

As far as the non-linear compass concern, we could not duplicate the problem with any other lsm303 chips. The problem was the result of a damaged chip due to the exhaust of a gas pen soldering iron.

For now the issue is closed.

Thanks for the response and help.