Ok after getting this little HMC stamp, and after adding a cap otherwise it didn't work properly, i modified/extended the HMC lib to get it easy going.The output values of the HMC need to be scaled, as the documentation describes, the new calibrate function does just that. The output values are scaled after calibration but still just a vector so for yaw pitch and stuff you need some calculations.

Is your library just written for arduino mega boards since you include twi.h in HMC.h file? I am new to programming so I might be wrong! If yes how do I adopt the code to an arduino uno board or are no modifications needed?

the readings don't look all that good I think: They should make up a circle, not an ellipse around the origin.If you have one diameter larger than the other, it is an idication that the system should be calibrated. As the ellipse doesn't look tilted, a calibration should not be difficult.

Read more about calibration in a publ. by ST Microelectronics:AN3192Application noteUsing LSM303DLH for a tilt compensated electronic compass

I am trying to build an electronic compass. So far I have programmed a three axis accelerometer to output roll and pitch and this morning I got the HMC5843 to run, with the wire library.

I am not sure, how good the computated heading will be if the compass is moved, and therefore one might need to calculate motion from the accel for compensation ( I found a reference on that) or integrate a gyro.

Sure, I know that they should made a circle not an ellipse.. but I'm wondering how much error this miscalibration will lead to.. I guess that it would be around 4/5 degrees of error.. so I wonder if it's really worth implementing a sophisticated calibration routine.. for my needs I mean

The document you pointed me to looks quite good written and I will surely have a look at it. This is the direct link if anyone else is interested: http://www.st.com/stonline/products/literature/an/17353.pdf

You should also read http://forum.sparkfun.com/viewtopic.php?f=14&t=18510 .. there are quite a good number of references there.

I just created a 3d version of the 2d graph above. It's all described at http://www.varesano.net/blog/fabio/first-steps-hmc5843-arduino-verify-accuracy-its-results and you'll also find all the sources I used to create those graphs.

I thought about calibrating the magnetometer, and I think it is easy:From your plot you already have all data necessary, but you can easily read the necessary calibration data (which are essentially the minima and maxima of the X and Y readings of the single axis sensors) during a calibration routine and save them to program memory, as follows (no guarantee for correctness): you measure X and Y readings during a slow circle you perform with the compass, and save Xmin, Xmax, Ymin, Ymax. Then you calculate the offset from the centre to be:

You could do that during setup of the compass.It would be interesting to know if the correction depends on the compass system or if it changes if you do the calibration in different environments like outdoor, too.

it took me some time to figure out how to exactly calibrate this chip. From what I understand one needs to calibrate it to the minima and maxima in the three axes. This implies to hold it in every axis parallel to the earth's magnetic field vector which in inclined in our area about 60° from the horizontal. If one sticks to the horizontal and vertical plane one gets reults that are smaller and thus a wrong sensitivity, or, rather, a sensitivity that is OK only for the exact calibration planes. If one would like to use the chip in a mobile application this approach in my view does not yield the correct sensitivity.David Schultz published a code that allows the calculation of sensitivities and offsets from 6 values. In the code he suggests to take these values at positions that are exactly horizontal and vertical (at the minima and maxima of the accelerometer readings).

My view is to collect the readings of many random positions in space and filter them for the minimal and maximal value in each axis and record only these values. This way one can will end up with the true minima and maxima of the ellipsoid to describe, and the calibration factors thus obtained are not bad.

Any remaining error is likely due to having missed the precise position of minima and maxima during calibration.