home‎ > ‎

Tilt Compensated Compass

Compasses are great devices for navigation. But they often don't work so well when tilted around the vertical plane. This is before we start worrying about the local angle of magnetic declination vs the angle where the compass was designed for use. The clever folk who build digital compasses work around this by using magnetometers set around 3 axis then processing the data to compensate for the tilt angle.

A good explanation of how this works can be found in Paul Coulton's blog here.


OS4000-T compass module, BlueSmirf module and battery module.

Hardware

I was tasked to kludge together a couple of ready made boards to make a compact tilt compensated compass which can be read using bluetooth. As the Paul Coulton's link shows, this technology is already built into mobile phones, but we needed something with a bit more resolution. Don't ask me why, I just make the stuff.

So I wired together an OS4000-T module, bought from Sparkfun here to a BlueSmirf module bought from Sparkfun here. I stuck the OS4000-T module directly on top of the BlueSmirf module and airwired them together. Data sheets for the devices can be found on the links. It is a case of wiring the Rx and Tx lines for the two boards together and supplying voltage. So long as you get the 'T' version of the compass it can be wired directly to the blue tooth board - the 'T' stands for TTL logic levels.

The only real bit of engineering I did is the DC-DC converter that boosts the AA battery voltage to a steady 3.3V. This is the green board on the photos. I made this for an earlier project and it is a masterpiece of compact but over engineering. It even has a low battery level LED  - which you can't see in the photos as it is on the base of the board. I drilled holes in the case for the indicator LEDs to be visible to the user.

In all, a nice little project. Took a morning to wire it together and dremel out the case. The unit is being used by Sonja Rumelin for her diploma thesis under the ruthless supervision of Enrico Rukzio. The unit is read from a Motorola phone running the Android platform. Note the artistic use of hot melt glue to hold it all in place.

OS4000-T compass module, BlueSmirf module and battery module.

Android

All of the Android coding was done by Sonja Rumelin. I took half of an Android course in 2009, before realising that I needed to know a whole lot more Java! Hopefully I have remedied that now as I have plans for Android...

Android interface by Sonja Rumelin

In Sonja's words:
The first setting that has to be made to get the combination of the OS4000-T module and the BlueSmirf bluetooth module running is to set them both on the same baud rate. The compass module comes with a default setting of 19200 while the BlueSmirf 's is 115200. We chose to set the BlueSmirf to 19200 which works fine.

The easiest way to start and post the commands is by using a PC with bluetooth connection and something like Putty. Just need to pair the device (default pincode is 1234) and check to which COM port the bluetooth is connected, then set up the connection and enter "$$$" (just three dollar signs) to get into the command mode of the bluetooth module. There will already be a lot of data coming in, but it should work. If it doesn't work make sure you tried it in the first 60 seconds after you turned the module on (can be set to "always" with the command "ST,255"). Then change the baud rate to 19200 by entering "SU,19". Get out of command mode by entering "---" and you should be able to communicate with the compass.
Getting into the command mode of the compass is done by entering <ESC>, that also stops the data coming in.
To make the parser of our application work, the "output data field selection" has to be set to 15 (means outputs heading, pitch,roll and temperature), the "output sentence format" that's needed is 2 ($OHPR sentence, comma delimited).

To receive and send data from and to the compass, you can also use the android program. Since Android 2.0 (API Level 5) it's supported to set up bluetooth connections. All you need is to enable your mobile's bluetooth adapter, connect to the bluetooth module's address and create a BluetoothSocket. Then get input and output streams on this socket and you are able to communicate with the compass module.


Comments