LSM 303 Compass Calibration

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
jtraynor
 
Posts: 14
Joined: Fri Feb 07, 2014 3:27 pm

LSM 303 Compass Calibration

Post by jtraynor »

I have bought this compass to use as a setup reference for a rotating motor project. (ton of details)
short story is that I want to align the motor direction true north. then do a rotation with the motor(no compass), then after the rotation, do another calibration, repeat, repeat and so on. I have added the calibration sketch from the tutorial and got it to compile and everything, I need to do the physical rotation part since I skipped it ( over read it ) and then see if it calibrates it better.

So to the question. Once I calibrate this compass, How often should it be calibrated? before every use? once a month etc.

Also, should I loop the calibration function so it will continuously calibrate while I physically rotate it or what is the best way to do it? ( cause it runs through the script in about 50ms)

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM 303 Compass Calibration

Post by adafruit_support_bill »

At the silicon die level, these devices are pretty stable. The primary reason for calibration is to compensate for any positioning offset incurred during packaging the chip, soldering it to the board and/or mounting the board to your project. If your installation is subject to strong vibrations that might cause mountings to drift, then you might want to calibrate periodically, or after some number of hours of operation. But for most purposes, you should be able to calibrate once on installation.

jtraynor
 
Posts: 14
Joined: Fri Feb 07, 2014 3:27 pm

Re: LSM 303 Compass Calibration

Post by jtraynor »

when I run the calibration sketch, should I loop it constantly until I can get it spun on all axes ?

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM 303 Compass Calibration

Post by adafruit_support_bill »

That depends. If you will only be rotating it in one axis in actual use, you only need to find the min and max points for rotation on that axis. If it will be free to move on more than one axis (e.g. an arial drone), you will need to keep measuring until you register the min and max on all axis.

jtraynor
 
Posts: 14
Joined: Fri Feb 07, 2014 3:27 pm

Re: LSM 303 Compass Calibration

Post by jtraynor »

Ok that makes sense. Mainly I'll be using this to find true north on a leveled platform. So how many rotations would you need to run it to call it safe? 3?

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM 303 Compass Calibration

Post by adafruit_support_bill »

If it is mounted to a platform, you could do it with as little as one (slow) rotation.

waltr
 
Posts: 306
Joined: Wed Jun 12, 2013 5:01 pm

Re: LSM 303 Compass Calibration

Post by waltr »

What the calibration is doing is finding the Min and Max values of each axis. This will then calculate the OFFSET ERROR of each axis so that the trig used to calculate the angle is correct. With a slow rotation the sampling will get the min and max values.
To get a TRUE heading you will need to look up the local magnetic deviation for where you live and add this to the magnetometer angle calculation (magnetic North).

jtraynor
 
Posts: 14
Joined: Fri Feb 07, 2014 3:27 pm

Re: LSM 303 Compass Calibration

Post by jtraynor »

Yeah I knew that it would be true north but I think magnetic north will be fine for this project. Later I might get more precise with the true north. Thanks for all of your help, Jonathan

jtraynor
 
Posts: 14
Joined: Fri Feb 07, 2014 3:27 pm

Re: LSM 303 Compass Calibration

Post by jtraynor »

Since I have been unable to work on my project, left it at school and school was cancelled due to snow, I've been looking into correcting the true north magnetic factors. so I've found source from NOAA which im sure are pretty accurate dealing with the degree of change. Where in the calibration code would I add in this factor. I'm using the calibration sketch from the tutorials. I'm guessing that I would just have to say something like

magmaxval_x = magmaxval_x + offsetvalue;

or something similar to that in both x and y ?

Thanks in advance for the help, Jonathan

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM 303 Compass Calibration

Post by adafruit_support_bill »

Usually the magnetic declination is given in degrees. You would simply add that value to your calculated heading.

Note that magnetic declination is not a static value - The Earth's magnetic field is always changing and the magnetic poles are slowly moving. For a short-term project, you can get away with hard-coding it. But in a few years it will most likely have shifted a bit.

jtraynor
 
Posts: 14
Joined: Fri Feb 07, 2014 3:27 pm

Re: LSM 303 Compass Calibration

Post by jtraynor »

Yes I am aware of the slow changes. It'll just have to be something that will be kept up with and constantly changed. But it doesn't have to go in the calibration sketch, but it's just added to the heading direction correct? Cause if that is the cause then technically we don't have to hard code it as we could just set it up and off set it by a number of degrees that matches the current magnetic field

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM 303 Compass Calibration

Post by adafruit_support_bill »

but it's just added to the heading direction correct?
Yes. Same as you would with a regular compass.

User avatar
spork99
 
Posts: 48
Joined: Mon Jul 25, 2011 3:27 pm

Re: LSM 303 Compass Calibration

Post by spork99 »

You can get updated magnetic declination for your exact position from NOAA on the web. Also many airports also publish the precise declination daily. Keep in mind that in some places, like BANNED, the declination can be as much as 20 degrees from true North. Depending on where you are, things like iron ore or lodestone deposits can affect a compass too.

I'd also be concerned about EM interference from your project affecting your compass. I know a guy who failed a nighttime land navigation trial because he held his light next to his compass when taking a bearing and the light pulled the compass needle about 20 degrees off.

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

Return to “Other Arduino products from Adafruit”