Magnetix - a digital compass with NMEA2000


I've always found the idea of not only showing the course on my plotter when the boat is moving, but also when it's bobbing along quietly, I've always found it exciting.

After searching the I-Net for different manufacturers, it quickly became clear that I might not need an e-compass on board at current prices. Due to the corona restrictions and the more free time being spent at home, the idea of building the compass myself came up.

The construction of the electronic compass with an output to the NMEA2000 network was inspired by a post by Andreas in the "" forum.
Thanks to many tips in different forums, it was successful. The compass is ready, but not yet tested on the boat (status: 2022.01).


Magnetix is an electronic compass that transmits its data on the MNEA2k bus. A CMPS14 serves as a basis as a sensor, an ESP32 as a calculator, a Waveshare SN65HVD230 (don't forget to break out the resistor) as a link to the bus and an LM2596 as a voltage converter. A 0.91 inch OLED with 132×32 pixels is used for the display in the housing.

The housing for the electronics is a Bocube from "". Both the bracket and the housing were 3D printed for the sensor. The brackets for the OLED and the touch sensors (VA screws) were also created with a 3 printer.

The connection between the compass sensor and the ESP is made via a KAT5 network cable, in which two cables are always connected to form a pair. Although the protocol between the CMPS and the ESP is a short range protocol (I2C), I have no problems with a cable length of ~70cm

Power is supplied via the NMEA bus and is ~1LEN. A built-in plug from Techno-Spark is used to connect to the network.

The ESP gets the data via the I2C bus, converts the whole thing into an NMEA2K data set (127250) and sends it to the network.

The compass identifies itself on the bus as "Magnetix Alpha" and can also be found under that name in the network's sources.

variables in the code

Complete source code
devotion []
is an array with 36 possible entries. A deviation table can be stored in it, which automatically corrects the given course for the respective courses.
This can be used to set a - horizontal - correction for a deviation of the compass line from the boat axis.

[-] Values for a port correction

[+] Values for a starboard correction


Operation is limited to the two touch surfaces (screws):

touch surface function
1 auto calibration on
2 autocalibration off
1 & 2 initiate new calibration


The display is divided into three areas:

Left (in 90° rotated font)
Current function of the sensor
"calib" the sensor is currently being calibrated, which was triggered by touch 1&2.
"inacc" if the sensor is not fully calibrated (not all sensor responses are 1) “inaccurate” will appear. The HDM data was not switched off, as messages 0 occur very often.

It may have to be adjusted after field tests on board

"ON" The sensor is in "autocalibration" mode
OFF The "autocalibration" mode is switched off
S Sensor system status followed by two numbers
A. 'Status of the accelerometer
M Magnetic sensor status
The three details are each specified by the following numbers:
00 nothing is OK
11 everything OK
01 or 10 partially OK
(Unfortunately, what these numbers mean exactly is not clear from the documentation of the CMPS14)
Right of the line
M magnetic course
R roll of the sensor
P pitch of the sensor

construction and assembly

I built the whole thing in a standard housing in which I built a base plate as a support for the perforated plate and the voltage converter. The only thing to note when assembling is that the terminating resistor on the CAN module (Waveshare SN65HVD230) has to be broken out. Otherwise the Waveshare SN65HVD230 terminates the entire NMEA bus. The wiring can be in the Circuit diagram to be checked.

Unfortunately, in the first version, I placed my brackets for the display and the touch surfaces flush with the upper edge of the case. However, since the cover “pulls” itself completely over the lower housing, it no longer closes. 🙁


2022-03-01 New bracket for the case with a wall bracket to compensate for a wrong horizontal installation -> Thingiverse


the libraries used appear in the header of the INO file and are not discussed further here.

Links and Materials

All 3D printing components
ESP-32 Dev Kit C V4
Wave share SN65HVD230
0.91 inch OLED I2C display 128 x 32 pixels
LM2596S DC-DC power supply adapter step down module
PCB Board Set breadboard breadboard circuit board×4-stuck

However, I can't find my measurements in the list there!

PG - bushings

(think of mother)

Micro-C chassis connector
basics This year's winter tinkering: A NMEA heading sensor or electronic compass pitch and roll compensated

touch functions
NMEA basics AK Homberger Workshop (ESP -> NMEA2k)

Examples I2C NMEA