First steps with the HMC5843 with Arduino: verify the accuracy of its results
I finally got an HMC5843 magnetometer breakout board. I wasn't able to make a DIY breakout board for this chip (but I'm still willing to try that again) so I had to buy one. Of course I ended up with one made by Sparkfun sold by watterott.com.
So now I'm moving my first steps with this chip. I'm now verifying the accuracy of its readings. I found a nice Arduino library on Arduino forum which contains a calibration routine (there is a copy in the attachments below). It looks like it simply uses an internal calibration feature. I'm still not sure on how this actually works.
However I ended up plotting some graphs from the readings from the chip while rotating it around the Z axis and while moving it in 3d rotations. Ideally, in a perfectly calibrated device these graphs should be respectively a circle and a sphere centered in the origin.
These are the resulting pictures:
As you can see the picture are not perfect circle and spheres so a more complex calibration routine its probably needed to get very precise readings.
I still don't know if the precision I'm currently getting would be enough or not for my needs. I asked for clarification on a Sparkfun forum thread on the topic but I still didn't got a reply.
Thanks to newbee on Arduino forum I found this nice paper by ST Microelectronics called Using LSM303DLH for a tilt compensated electronic compass which describe quite well a procedure to calibrate a magnetometer (it actually covers tilt compensating a magnetometer with an accelerometer, so it might came handy in further developments).
I attach here the gnuplot "programs" I implemented to create the above graphs. If you are working with the HMC5843 they may come useful.
makeplot3d.p reads data from a datafile. It expects data to be comma separated in the X,Y,Z form
makeplot.p instead expect a datafile with space as separator.
Save it, rename it to test_serial.py then simply run python test_serial.py > dump.txt so you will have all the values coming from the Arduino in the dump.txt file ready to be used by gnuplot.
EDIT: On Sparkfun forum user pvmellor asked what typical variance and standard deviations we get from the HMC5843. So, I created a simple octave (matlab) script to compute the std and variance from a csv file containing (not so) calibrated readings from the HMC5843 (see above).
My results, of a 3 minutes dump (HMC5843_steady.data) of the readings coming from the Arduino code _11_hmc5843_calibrazione.tar_.gz while keeping the device steady, computed with the Octave script HMC5843_statistics.m were (X Y Z):
STD = 8.8842 5.5359 15.1949 VAR = 78.929 30.646 230.885