Another great post from Hackaday. This is very similar to the technique we now use in ArduPlane/ArduCopter.
We don’t have much personal experience with DOF hardware, but this Arduino library which reads and compensates for three-axis magnetometer and accelerometer...looks very impressive. It should work for existing hardware, but there’s also a demo design using a Honeywell HMC5883L compass and a Freescale MMA8453Q accelerometer which you can build yourself.
What’s so special about this library? Watch the video above (use 720p in fullscreen to get the full effect) and you’ll see three different scatter plots of the output data. The image above is a capture of the third example, which is using the hard iron offset and accelerometer compensation. That is to say, metal on and around the board is accounted for, as well as the physical orientation of the device. Even if you have no prior experience with this type of hardware it’s easy to see the usefulness of this kind of software compensation.