Menu

Home

Wes Peters

Compass? Who uses a compass?

Boats do. In particular, electronic navigation programs like to know what direction the boat is pointed, along with a GPS track, this allows them to calculate a critical piece of information known as the 'cross-track error.' Since boats (and airplanes) move in a fluid medium, the direction the boat (plane) is travelling is influenced by current (wind). Knowing what direction the boat (plane) is headed allows the navigation program to calculate how much effect the current (wind) is having on the boat (or plane.)

This was an afternoon exercise to create a compass module that can communicate using the NMEA format used by a lot of boat (or ship) navigation equipment. At this time, this is quite a simple program. It can only accept a single network connection at a time, which meets my current needs. It does handle the network connection terminating, it will listen for a new connection and resume reporting the heading.

No provision is made at this time to compensate for the orientation of the physical compass sensor. The typical HMC5883L breakout board will have the X/Y axis marked on the board, this assumes the board X axis is accurate and aligned with the centerline of the boat.

I will probably make this fancier once we've had a change to install it and test it on an actual boat. There is a fair bit of calibration you should do to use one of these with any accuracy. It is also possible to compensate for pitching and yawing on the boat using only the magnetometer data, so I expect at some point to improve this a fair bit.

How to use

It's a pretty simple python3 script. It has been tested on a Raspberry Pi 3B+. For now, the listen address and TCP port are hard-coded, I will parameterize those. The TCP port was chosen to be 1 more than the usual port for a GPS, to make NMEA muxing simple.

You can watch it with nc:

% nc -v 192.168.1.221 2948
Connection to 192.168.1.221 port 2948 [tcp/wap-push] succeeded!
$HCHDM,351.9,M*27
$HCHDM,351.9,M*27
$HCHDM,343.9,M*24
$HCHDM,345.3,M*28
$HCHDM,345.8,M*23
$HCHDM,347.7,M*2e
$HCHDM,352.8,M*25
$HCHDM,15.5,M*18
$HCHDM,17.0,M*1f
$HCHDM,19.6,M*17
$HCHDM,21.1,M*1b
$HCHDM,24.0,M*1f
$HCHDM,24.6,M*19
$HCHDM,32.0,M*18
$HCHDM,36.2,M*1e

The changing heading came from turning the protoboard the module is currently mounted on my desktop.

Project Members:


MongoDB Logo MongoDB