NMEA 2000 Shield

Hi Timo
First o all, thank you for your fantastic work.

I'm using a Arduino Mega with MCP2515 Can modified with a 16Mzh crystal. When I’m running your example ActisenseListener everything works great together with Actisense reader!

But when I run DataDisplay2 I get different results every time in my serial port. Sometime I only get 1 sentence, other times I get 10-20 sentences and sometimes I get 200 sentences.
When I restart the Arduino it works directly again and I get some sentences.

Do you have any idea why I’m getting different amount of data?

Where you are getting the data and how much there is data? How many different PGNs and devices?

Just now I do not have idea. I have tested DataDisplay2 with MessageSender on Teensy and it still can catch all that traffic. The serial port may get stuck, if it gets data from PC to Mega direction. But this should not be the case, if you just follow the serial monitor and do not send any data to other direction. The stuck problem can be handled by adding while ( Serial.available() ) Serial.read(); after NMEA2000.ParseMessages(); But I would be surpriced, if that would be the case.

For now I only have one device connected to the NMEA 2000 network, my engine, as you can see in the attached file.

I’m not sending any data on the serial port, just watching the information send in the example code.

As you can see in the attachment it just stops sending data in the middle of a sentences, and when I restart the serial port I will receive data from start again.

Data 2018-03-24.txt (35.4 KB)

Do you use Arduino Serial monitor? Could you try same with e.g. Putty.

Since you system works fine with Actisense NMEA Reader, I think that the Mega itself handles messages right. I have time to time seen different problems with Arduinos USB-Serial drivers.

Which OS you have?

I have mostly used Arduino serial monitor but also Putty both with the same result, unfortunate.
I use win 10. Maybe it’s a problem with receiving in windows and not the Mega?

I have W10 too, so it is difficult to say. Please confirm that with ActisenseListener - Actisense NMEA reader it runs without stopping - let it run long. In principle there is not much difference on handling between ActisenseListener and DataDisplay2. You could also try with ActisenseListener in text mode by uncommenting line NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); and then use putty or serial monitor.

Yes, the ActisenseListener runs without stop for 15 min. When I uncommenting the text line so I get text-mode I only get 200 sentences again exactly as the DataDisplay2 and it works in 10 seconds….

I have tried another serial converter and connected it with wires to tx0 and Rx0 and get the same resultate as USB port. Both on Putty and Arduino serial monitor.

When I run AtisenseListener and connect it with USB to Actisense Reader and in the same time connect serial reader with wires to Tx0/Rx0 I read data there too, but nothing I can understand.

Is there any buffer in the Mega that is filling up with data when it’s in text-mode?

Now I have some progress!

When I set the speed of the serial port to 230400 in the arduino program ActisenseListener and DataDisplay2 it runs without any problem when connected to my computer!

I don't now why and how but it works. Any idea?

No ideas. As I mentioned I have transmitted data with Messagesender and received all with Mega 115200 on DataDisplay2. And Message sender sends much more than on yours sample. One difference can be that your data had several 1 frame messages, which can be send faster. But I have not had time to simulate that.

I am writing NMEA2000 -> NMEA0183 converion for Rasberry Pi for my friend. With this you just need RPi 3, PiCAN2 (or alternative) and the code for getting GPS data from N2k to e.g. OpenCPN.

Just note, if anybody is interested.

Timo,

This looks really great. I just stumbled onto your thread as i'm interested in using an arduino to listen on my Seatalk NG network and pull info off to transmit to an mqtt broker. I have tried to look at the entire thread I have been unable to find if I can use your work to listen to the Seatalk network, either by native seatalk or using a NMEA 2000 converter and connecting the arduino to that? Any direction would be very much appreciated.

Thanks

Scott

Seatalk NG is actually same as NMEA2000. There is a simple adapter cable to convert Seatalk NG to NMEA2000, but as far as I know it is just cable with different connectors - so no logic on it. Do not mix Seatalk and Seatalk NG. From Seatalk to Seatalk NG you need converter or device, which supports both like I have Autopilot. Then you see at least some Seatalk data also on Seatalk NG and NMEA 2000.

Waht is mqtt broker? If you do not yet have any Arduino board, I prefer Teensy 3.2 or up.

I’m interested in a raspberry Pi solution. I have checked your guide on Github to connect the MCP2515 to the Pi, do you have any code example like the Arduino example, Datadisplay2, to read the NMEA2000 sentences in text mode? Or is that what you are working on now?

I added yesterday new example NMEA2000ToNMEA0183. I made it for my my friend for use with OpenCPN to get NMEA0183 data from NMEA2000 network. It also provides all NMEA2000 data to other port in Actisense format e.g. for SignalK server. The example has been tested on RPi3B with home made "PiCAN2" and also on DUE, Mega and Teensy boards.

On RPi3 I used CodeBlocks 16.01, which seem to install easily to Raspberry. The only trick was that one has to do: Plugins-Manage plugins... disable Code completition on CodeBlocks. Otherwise it will just close time to time without any save. I did not made simple makefile yet. I like IDE programming.

For "serial ports" on RPi I used tty0tty "virtual null modem cable". So my example writes data to one serial port so the other program can read it on other. You can find more about tty0tty on tty - How can I set up virtual serial ports (Linux null modem emulator) using tty0tty - Ask Ubuntu and download it from GitHub - freemed/tty0tty: Null modem emulator. I am not sure would it have been possible to use pipes instead of tty0tty.

This was my first RPi solution and it took 2 days to get it up - well I spent some hours trying to get Atom for RPi. Anyway the instructions are not complete and one has to google some small tricks to get things working. I may redo everything and write simple step by step guide to get example up and running. But before that I should try to get ESP32 CAN running.

timolappalainen:
Seatalk NG is actually same as NMEA2000. There is a simple adapter cable to convert Seatalk NG to NMEA2000, but as far as I know it is just cable with different connectors - so no logic on it. Do not mix Seatalk and Seatalk NG. From Seatalk to Seatalk NG you need converter or device, which supports both like I have Autopilot. Then you see at least some Seatalk data also on Seatalk NG and NMEA 2000.

Waht is mqtt broker? If you do not yet have any Arduino board, I prefer Teensy 3.2 or up.

Thanks Timo my install has Seatalk NG not seatalk I was not careful in my post. So I think I can simply make up a connector and go directly to the arduino. If I get this right though I need to put a CAN "device" like MCP2562 or similar between the Seatalk NG cable and the arduino? I'm trying to visualize the connections. If I do this I do not need an NGT-1 have I got that right?

MQTT is transport telemetry language developed for communication between IOT devices FAQ I'm looking at using the wind and gps info from the Seatalk NG bus along with sensor data that I build from mysensors.org type sensors. Sending all that through mqtt to a database and displaying via node red.

Thanks for all of your work!

Definetely NGT-1 is not necessary. MCP2562 is CAN tranceiver and it is enough with boards with internal CAN controller like Teensy 3.2/3.5/3.5 or Arduino DUE. Also ESP32 has internal CAN controller, but I am just writing drivers for it, so it is not good choice yet.

If you connect your device directly to the ST NG, make sure to connect right wires. Also be carfull with power, if you are going to use it. If you have your "Arduino" allways connected to PC, you can just use USB power and connect only CAN L/CAN H wires. If you are going to use bus power, you need to take care that you do not feed them against from bus and USB.

ThanksTimo,

So if If I get the teensy do I still need the CAN transceiver? It sounds like I do. I saw your boards you made and it looks like you used both. Initially I just want to listen to the STNG bus and redistribute the data, but I'm sure I'll want to end up putting data onto it at some point. It will only be connected to a PC to troubleshoot. Thanks for your advice. I appreciate it!

You allways need tranceiver. Tranceiver is ready only on extension shied/breakout boards. If you are handy with electronics, you can use schematic for Teensy from NMEA2000/Examples/TeensyActisenseListenerSender/Documents at master · ttlappalainen/NMEA2000 · GitHub and make board simply by yourself. This has extra USB, which you do not need.

Other option is to buy ready board http://skpang.co.uk/catalog/teensy-canbus-breakout-board-include-teensy-32-p-1507.html. That uses linear DC-DC converter instead of scwithed one as I have on my schematics. As far as I see you should not power that breakout at same time from bus or USB. On my above docs there is also instructions how to separate USB power.

Other options are bigger on size and draws more current.

Timo,

Is there a place where all of the libraries required to run this on teensy 3.2 reside? I followed your instructions in the nmea 2000 reference but there are libraries missing on compile. I don't want to just go find those individually as I'm afraid of finding out of date files.

Thanks!

UPDATE: I think I got it... It mostly compiles but since I don't have my board yet it appears it won't complete the compile. I am used to being able to compile without a board attached but it looks like it doesn't work like that for this board. I will know better when my board arrives.

Thanks!

For Teensy NMEA2000 you need:

Note that on Teensyduino install you should not install FlexCAN. If you did, delete folder:
"C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\FlexCAN"

It should complete compilation without board and there should not be any errors/warning, if you use just compile button at leftmost on Arduino IDE.