NMEA2000 Library
0.1
Library to handle NMEA 2000 Communication written in C++
|
Roughly you need at last 8 kB ram and 40 kB ROM to fullfill all required NMEA2000 features with your own logic. Even requirements can be squeezed I do not prefer to do that to avoid unnecessary issues.
With version 11.06.2017 I measured and got results:
This was with simple TemperatureMonitor example. This can be squeezed by setting:
With those setting you can go down to appr. 19 kB ROM and 1.9 kB RAM. So for 2 kB RAM devices like Arduino Uno, there is not much for your own code.
NMEA2000 is inherited from CAN. Many MCUs like Teensy >3.1, ESP32, Arduino Due has internal CAN controller. If your MCU does not have internal CAN controller or you need second external CAN controller, you can use e.g. MCP2515 CAN controller, which is supported by library (mcp_can).
For final connection to the bus you need CAN bus_transceiver chip. Devices on NMEA2000 bus should be isolated to avoid ground loops. If you take power from NMEA2000 bus and your device is not connected to ground anywhere else, you can use unisolated tranceiver like MCP2551, MCP2562 or SN65HVD234. If you instead feed power to your device directly or e.g. use engine own sensors for measuring, you have to use isolated tranceivers like ISO1050. Remember also use isolated power supply, if you take power from bus and have any unisolated connection to anywhere on your whole system.
Easiest for connecting to NMEA2000 bus is to use some ready shield. For more information on how to wire everything to the bus please see Setting Up Hardware Environment
I prefer isolated connection NMEA2000 bus. See more Isolated transceiver.
For beginner simplest board would be board with MCU (like ESP32 or Teensy 4.0) with isolated transceiver. Unfortunately I have found only one Teensy 4.0 board with unisolated tranceiver. Next simplest is breakout board that fits directly to main board pins, but even those does not exist isolated. But it is not much work to connect 4 wires and use existing isolated board.
This can be used with any main board having internal CAN controller like Teensy 4.0, 4.1 (or 3.2, 3.5, 3.6 which are at end of life), ESP32 Arduino DUE boards.
Note that there are several different shields for CAN bus available and others may use 8 MHz chrystal instead of default 16 MHz chrystal. This must be set before including NMEA2000_CAN.h
In case you build your tranceiver connection by yourself there are some connection examples under documents.
Library has been also used with Maple Mini board.
You need at least Arduino Software 1.8.19 for this sample. I'll expect you are familiar with Arduino and using libraries. When your Arduino environment is ready.
CAN library is included to the code so you do not need any extra CAN library with this. NMEA2000_Teensyx library will replace NMEA2000_teensy library in future. You can already start to use it with all Teensy boards by forcing it with define (see NMEA2000_CAN.h comment).
I prefer to move to use libraries as Teensy 4.0/4.1 boards with internal CAN and force it by define. Old libraries are still as default.
NMEA2000_teensy has been originally forked from NMEA2000_teensy contributed by Thomas Sarlandie
C:\Program Files(x86)\Arduino\hardware\teensy\avr\libraries\FlexCAN
. ESP32 CAN driver by Thomas Barth has been implemented inside NMEA2000_esp32 so you do not need other drivers for that.
You can use mcp_can with boards where you connect MCP2515 CAN bus controller with SPI. You can also use it as secondary CAN for e.g. Teensy 3.2 or ESP32.
mcp_can library is developed version of original mcp_can library. This allows also to use 8MHz clock and has been tested with Maple Mini. mcp_can library can be originally found on https://github.com/Seeed-Studio/CAN_BUS_Shield, but check library status has all improvements been implemented to Seeed-Studio. At least 18.09.2017 it was up to date.
NMEA2000_socketCAN library.
NMEA2000_socketCAN has been originally forked from https://github.com/thomasonw/NMEA2000_socketCAN
There is a document Preparing your Raspberry Pi for the NMEA2000 library.pdf for starting up with RPi. Hopefully I have time to write more complete document. There is example NMEA2000ToNMEA0183, which has been tested with RPi 3B.
Install all libraries to your Arduino IDE (Sketch-Include Library-Add .ZIP library).
NMEA2000\Examples\TemperatureMonitor
.If you have Multi Function Display (e.g. Garmin GMI-20) on your NMEA2000 bus, you should see on it's NMEA2000 bus devices new device "Simple temp monitor" on the list.
Now you are ready to play with your own device. Check also the NMEA2000\Examples\ActisenseListener
, which reads all data from NMEA2000 bus and sends it to PC. NMEA2000/Examples/ArduinoGateway
allows you to mimic Actisense NGT-1 and connect e.g. a Raspberry Pi running Signal-K to the NMEA2000 bus with an Arduino or Teensy.
In examples there are simple includes:
If above can not be used (like with Arduino IDE older than 1.6.6) or you would like to control naming and used "driver", you can manually include necessary files. Specially you need that, if you want to use secondary CAN bus on your system.
Your file should start with:
Your file should start with:
Your file should start with:
Your file should start with:
Your file should start with:
Your file should start with: