Some time ago I bought a cheap 9DOF board on Ebay. The board has 3 sensors, an ADXL345 accelerometer, HMC5883L magnetometer and an ITG3200 gyroscope. All 3 sensors are of the digital kind and use the I2C bus to communicate. These sensors need a voltage of 3,3V to work, luckily the board has an onboard voltage regulator and level converter that converts the 5V I2C signals from my micro controller to 3,3V. So I could just hook it up with 4 wires to my Dagu Red Back Spider robor controller.
These 3 sensors are quite advanced with lots of features. These are all explained in their extensive datasheets. My programming skills are not up to the task of programming them on my own. Thankfully some smart people have written a nice library for these things so that I can do something useful with my little board. I found a nice tilt compensated compass sketch and libraries for the ADXL345 and HMC5883L sensor at the Love electronics website. This sketch takes calculates the heading from the magnetometer and applies tilt compensation. The tilt is measured from the accelerometer.
I integrated the sketch in to my existing sketch and sent the heading that is calculated from the reading of the 2 sensors to my remote control. That way I can see the heading on my LCD, 2 values are shown. The HNC value is the heading without the compensation by the accelerometer and the HC value is the compensated heading.