Magnetix - a digital compass with NMEA2000

why

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.

Der Bau des elektronischen Kompasses mit einem Ausgang in das NMEA2000 Netzwerk wurde inspiriert durch einen Beitrag von Andreas in dem „segeln-forum.de“ 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).

description

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 "www.bopla.de". 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 https://open-boat-projects.org/wp-content/uploads/2022/01/compass_NMEA2k_V05_01.zip
https://open-boat-projects.org/wp-content/uploads/2022/07/compass_NMEA2k_V05_02.zip
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.
CorrectionMountingAngle
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

service

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

touch surface function
1 Autocalibration on / off
2 autocalibration off Save performed calibration
1 & 2 initiate new calibration

screen

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
center
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 Magnetischer Kurs  (nach dem Druck auf T2 erscheint für 2sec. „…stored…“ [v5.02])
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.

Leider habe ich in der ersten Version meine Halterungen für das Display und die Touchflächen bündig an die Oberkante des Gehäuses gesetzt. Da der Deckel sich aber komplett über das untere Gehäuse „stülpt“ ging er nicht mehr zu. 🙁

updates

2022-03-01 New bracket for the case with a wall bracket to compensate for a wrong horizontal installation -> Thingiverse
2022-07-02 After some testing I noticed that the sensor starts again from zero after a power loss (despite having saved the calibration). I have now changed the touch surfaces so that T2 saves the previously performed calibration. After the first tests with a restart of Magnetix it seems to be working now. (V5.02)

libraries

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

Links and Materials

All 3D printing components https://www.thingiverse.com/thing:5207953
ESP-32 Dev Kit C V4 https://www.az-delivery.de/products/esp-32-dev-kit-c-v4
CMPS14 datasheet
Wave share SN65HVD230 https://www.amazon.de/gp/product/B00KM6XMXO/ref=ppx_yo_dt_b_asin_title_o01_s01?ie=UTF8&th=1

cheaper at:

https://www.robotshop.com/de/de/waveshare-can-board-sn65hvd230.html

0.91 inch OLED I2C display 128 x 32 pixels https://www.az-delivery.de/products/0-91-zoll-i2c-oled-display
LM2596S DC-DC power supply adapter step down module https://www.az-delivery.de/products/lm2596s-dc-dc-step-down-modul-1
PCB Board Set breadboard breadboard circuit board https://www.az-delivery.de/products/pcb-board-set-lochrasterplatte-platine-leiterplatte-4×4-stuck
casing https://www.bopla.de/gehaeusetechnik/product/bocube/pc-ul-94-v0-glasklarer-deckel.html

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

PG - bushings https://www.conrad.de/de/p/kvpg9gr-kabelverschraubung-verschraubbar-mit-zugentlastung-pg9-pg9-polyamid-grau-1-st-1521121.html

(think of mother)

Micro-C chassis connector https://technospark.de/nmea-2000-panel-mount-connector?number=SW1153
basics This year's winter tinkering: A NMEA heading sensor or electronic compass pitch and roll compensated

https://www.segeln-forum.de/thread/66453-diesj%C3%A4hrige-winterbastelei-ein-nmea-heading-sensor-oder-auch-elektronischer-komp/?pageNo=1

touch functions https://www.wiegleb.org/2018/09/22/esp32-ttgo-mit-touch-funktion/
NMEA basics AK Homberger Workshop (ESP -> NMEA2k)

https://github.com/AK-Homberger/NMEA2000-Workshop

Examples I2C NMEA https://www.robot-electronics.co.uk/htm/arduino_examples.htm#CMPS12/11%20I2C

https://www.robot-electronics.co.uk/files/arduino_cmps12_i2c.ino

gallery