Tilt compensated Compass sharing same socket with a Accelerometer module on a Cerberes

Hi fellow Gadgeteers.

After @ taylorza alerted me this this article in another post:


The weekend I used that article and got the tilt compensated compass working using Gadgeteer modules. As a side note, I also managed to share the same socket (1) of my Cerberus board between the compass and the accelerometer modules using some breakout boards. This has the advantage of saving one socket on my already pretty busy Cerberes board.

If other people think this information could be useful to them, then I will make sample project and share the info on Community Codeshare here on the GHI website. It would be my first codeshare submission here so I still have to figure out how to do all of that.


@ KiwiSaner - I hope you share the code

@ KiwiSaner - That is great. In my view it is always worth sharing the code, I have a compass module, which I have not used at all yet, and an accelerometer so I would definitely like to have a reference to some working code so that I can integrate the compass into my FEZ Cerbot.

Ok, I will do so. It will probably be better to split into two shares. Once for the compensation and one for sharing the modules on the same socket.

It actually worked quite well. I displayed the compensated and uncompensated headings alongside each other. Then I tilt the development board in any direction by as much as 40%. The uncompensated direction changes drastically, but the compensated one stays within a degree or two of the original value. I noticed however that the more south I point the compass, the bigger the difference between the compensated and uncompensated values.

The Tilt compensation method is share now at http://www.ghielectronics.com/community/codeshare/entry/741

I will make a separate codeshare of how to combine both Accelerometer and Compass on the same socket. In this example they are plugged in separate sockets to make it easier to test.

Hi KikiSaner,

Thank you so much for the tilt compensation. I’d been trying to solve this with no luck. I was actually thinking of using a gimbal to hold it level.

The issue I’m having now is I’d like to get tilt and acceleration from the accelerometer. I can place it on a table, shift it back and forth and get acceleration values- but the moment I tilt and shift it the output becomes difficult to understand.

The only solution I’ve been able to think of was having two accelerometers. One in a gimbal to measure acceleration, and the other that would tilt with the device just for tilt.

Am I way off here? Any suggestions would be appreciated.

Thank you,

At least the influence from acceleration stops as soon it is moving at a constant speed again. For my purposes it was sufficient to only take gravity (tilt ) into account and ignore the real acceleration component. It is because my application does not care too much that the compass reading is momentarily wrong, as long as the average reading is approximately right.

Sounds like the precision you require is a bit beyond my experience. Your gimbal idea sounds interesting, but I can unfortunately not comment whether its the best way to tackle the problem or not. Hopefully there is someone else on this forum that can provide some suggestions.