NMEA 2000 Shield

I just attached a logic analyser and can see endless loop retransmitting the following....

Pri:6 PGN:126996 Source:13 Dest:255 Len:134 Data:14,5,9A,2,4E,4D

So this retransmitting seems to prevent sending the next sentences...

Do you mean example ActisenseListenerSender? That has been tested to work only on Due, since it uses two USB:s - one for sending and other for listening. I had problems with single USB that it stops responding, when you are sending and reaceiwing binary data throug it. But this should not be your case.

Are you writing with NMEA Simulator? It may be that sending buffers will overflow and it can not send all messages. You coud try add NMEA2000.SetN2kCANSendFrameBufSize(500); on beginning of setup(). Note that value 500 is frames, so this is taking 4k of memory. So you have to adjust value according to your memory. Default is 40 as documentead.

But also I am not sure that does MCP2515 chip fail to send anything, if it is not connected to the bus. Then everything will be just bufferd, until it fills out and start to give error.

Also if you using NMEA Simulator, you can disable sending product information for each device. I prefer to first test with one device and one PGN and then add PGNs.

I had to modify your sketch slightly in order for it to work on my setup.

So I am using a NodeMCU ESP8266 with 4MByte flash.
Using the std com port as programming interface and normal Serial output for debugging
I then attach one more USB serial and drive this throught the software Serial driver.
This software serial is now receiving the messages from the NMEA Simulator
Im not using interrupts

I have to modify NMEA2000_mcp.cpp because there is no SREG on the ESP8266

So I use noInterrupts() & interrupts() instead for the ESP8266.

In my logic analyser it seems like the 2515 is repeating the last frame (8 bytes) over and over again.

I have read an errata on the chip mentioning that CS should go hi within 78us after the last transmission or the chip could begin repeating.

I will try upping my transmit buffer as you suggested later today.

My sketch is looking like this:

=============================

// Demo: NMEA2000 library. Bus listener and sender.
// Sends all bus data to serial in Actisense format.
// Send all data received from serial in Actisense format to the N2kBus.
// Use this e.g. with NMEA Simulator (see. Kave Oy) to send simulated data to the bus.

#define USE_N2K_CAN 1
#define N2k_SPI_CS_PIN 15
#define USE_MCP_CAN_CLOCK_SET 16
//#define N2k_CAN_INT_PIN 4

#include <Arduino.h>
#include <N2kMsg.h>
#include <NMEA2000_CAN.h>
#include <ActisenseReader.h>
#include <SoftwareSerial.h>

tActisenseReader ActisenseReader;

SoftwareSerial swSer(2, 0, false, 256);

void setup() {
Serial.begin(115200);
swSer.begin(115200);

NMEA2000.SetForwardStream(&Serial); // PC output on due programming port
NMEA2000.SetMode(tNMEA2000::N2km_SendOnly);
NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text
NMEA2000.Open();

// I had problem to use same Serial stream for reading and sending.
// It worked for a while, but then stopped.
ActisenseReader.SetReadStream(&swSer);
ActisenseReader.SetMsgHandler(HandleStreamN2kMsg);
}

void HandleStreamN2kMsg(const tN2kMsg &N2kMsg) {
N2kMsg.Print(&Serial);
NMEA2000.SendMsg(N2kMsg,-1);
}

void loop() {
NMEA2000.ParseMessages();
ActisenseReader.ParseMessages();
}

SUCCESS!!!!

Now I build a complete setup!
NMEA2000 Simulator -> ESP8266 -> MCP2515 -> CAN-BUS -> MCP2515 -> ESP8266

And guess what.... It works :slight_smile:

So I guess the reason for the errors in transmission was because I didn't have a complete CAN-BUS setup...

1 Like

Kudo's to you timolappalainen,
That was a lot of work on your part.

I have my arduino (Mega + 2515) up and running and I am very impressed so far with all the coding on your part. My 2515 was 8mhz and that took a little trouble shooting. Being able to output to the terminal and NMEA 2000 simultaneously solved a lot of problems. I had a lot of trouble with my other NMEA devices not being able to read 130316, Temperature for EGT. This being the Actisense NGT-1 USB and the iKommunicate and Raymarine I70. All my work is being done at home prior to any installation on the boat.
So far I have output voltages for 3 batteries voltages and 3 environment temperatures and 1 EGT. Adding 3 more EGT's should be easy. I need 4 EGT's total. Twin engine and a turbo on each side of each engine.

It should be straight forward to apply all the other sensors to the engines now. I will probable use a few arduino's to do so, one for temp the other pressure, resisitive etc.

Has anyone coded for a display? Having your own helm display.

Thinking I may do just that with my 5 inch Nextion NX8048T050 TFT display.
Any advice that someone wants to share

Larry

Hi Timo,
Thanks for the response! I was occupied trying to rebuild my nav-PC as my M2 SSD in my intel NUC just decided to quit.
I'm back on the project now and I will try to source some parts to build few different units. I do agree- separate units will be cleaner to install.
On different note: Is there some PGN that reports bilge pumps cycles in the Nmea 2k? I have some n2k documentation that I can send you in email. Send me your email address so I can fwd you what I have.
My is MVseawitch at gmail. Send me quick email and I will fwd you what I have.

flemmingdjensen:
SUCCESS!!!!

Now I build a complete setup!
NMEA2000 Simulator -> ESP8266 -> MCP2515 -> CAN-BUS -> MCP2515 -> ESP8266

And guess what.... It works :slight_smile:

So I guess the reason for the errors in transmission was because I didn't have a complete CAN-BUS setup...

Good that you got it running. I have to design a way for NMEA2000_mcp to avoid SREG problem.

It should be straight forward to apply all the other sensors to the engines now. I will probable use a few arduino's to do so, one for temp the other pressure, resisitive etc.

Has anyone coded for a display? Having your own helm display.

Thinking I may do just that with my 5 inch Nextion NX8048T050 TFT display.
Any advice that someone wants to share

Larry
[/quote]
Hi Larry and all,

I quickly looked in to the Nextion and it has same problem as with all these cheap displays - only max 250 nits. I think that for outside you need 600 nits or even more. Sunlight readable systems are normally providing 800-1300 nits.

For more devices I prefer to look Teensy 3.2 board. That draws less current than Mega or Due boards. You can find link to schemas on my earlier post.

Thanks for the reply,
I am going to abort doing a display. This was purchased for use inside the boat on the watermaker. Instead I will find a sunlight readable monitor and use a windows based machine. Actisense will be coming out with an update to NMEA 2000, soon I hope. Going to look at building the arduino actisense reader, I have not looked at the code to see what it may output. Starting to read up on OpenSkipper?

If you find reasonable priced sunlight monitor, please inform - I have tried to find one and they allways starts over several hundred euros. I found HANTRONIX, INC. - TFT LCD, Ultra-bright TFT LCD having some nice displays, but don't know has anybody used them with Arduinos. Then I just bought Garmin GMI 20 for showing data outside.

Since I have PC as navigator I also thought to use e.g. tablet with VNC outside and OpenSkipper as web server. But I have not yet found bright enough tablet either. See my OpenSkipper webserver sample running on kavettl.dynalias.com:2222 - menu icons does not work over internet for some reason.

Other option would be to use SignalK server. See e.g. Home · SignalK/specification Wiki · GitHub

timolappalainen:
For more devices I prefer to look Teensy 3.2 board. That draws less current than Mega or Due boards. You can find link to schemas on my earlier post.

Hi Timo,
I don't mind ordering the Teensy 3.2, but it is very hard to ship stuff to Mexico, and I'm not going back to Canada for a while so getting parts is hard and I will try to make it with what I have...

I have few UNO and few NANO boards kicking around in my bag of goodies here on the boat. As I managed to get the MEGA + Can shield working perfect without any issues, I decided to try with UNO + CAN shield.
I figured that the CAN Shield is designed to fit on the Uno, so I did not need to bend pin 10,11,12,13 as I needed to do on the MEGA setup in order to get it working

MEGA setup with patch wires
10->53
11->51
12->50
13->52
UNO straight through
10->10
11->11
12->12
13->13

I switched the board type in IDE and the code that ran well on MEGA compiles fine for UNO.
I did not see any error messages but with the UNO, I don't see the new node on my N2K network via NGT-1 that I use for monitoring. I see the PWR, Rx, Tx and Int flashing when its all working with the MEGA, but with the UNO only the receive LED on the CAN blinking.
I'm not sure if what i need to adopt in which files to get it working with the UNO boards.
I hope you can point me in the right direction?

NMEA2000_CAN.h tries to automatically select suitable libraries and settings for you according to board. Now it selects mcp_can for your Uno board, but on 105 line it uses default #define N2k_SPI_CS_PIN 53. So in the beginning of your .ino file before #include <NMEA2000_CAN.h> add line #define N2k_SPI_CS_PIN 10 so it will use pin 10 for SPI chip select.

Timo,
I just did add #define N2k_SPI_CS_PIN 10 and uploaded to the board. The Int LED on the CAN shield starts blinking for a while, then goes ON solid, but the Tx LED is not blinking and the node is not found on the N2K bus. I think this is better, but still something missing... is there something to do with the interrupt pin? I just noticed in NMEA2000_CAN.h the next line after
#define N2k_SPI_CS_PIN 53
is
#define N2k_CAN_INT_PIN 21
as far as I'm aware the interrupt pins for uno are D2 and D3
does it have to be changed fro 21 to 2 and do I need to rewire to diferent pin on the Can Shield?
Any thoughts?

Another thing that i just noticed is that with that edit, the serial monitor starts outputting normal and then in few seconds it stops to output (I'm using the "BatteryMonitor" example)

seamaster:
On different note: Is there some PGN that reports bilge pumps cycles in the Nmea 2k?

There is no PGN for that. For your own system you can use e.g. PRN 127489 "Engine Parameters, Dynamic" and show it as second engine instance and use "Engine hours" parameter. That PGN is so common that MDF:s can show it. But this is of coarse very confusing way.

Right way would be to use some of reserved proprietary PGNs (like 61184 - 61439), but then you have to also build display, which can parse and show that PGN content. On single frame proprietary PGNs you have 6 bytes data, which you can freely define.

seamaster:
Timo,
I just did add #define N2k_SPI_CS_PIN 10 and uploaded to the board. The Int LED on the CAN shield starts blinking for a while, then goes ON solid, but the Tx LED is not blinking and the node is not found on the N2K bus. I think this is better, but still something missing... is there something to do with the interrupt pin? I just noticed in NMEA2000_CAN.h the next line after
#define N2k_SPI_CS_PIN 53
is
#define N2k_CAN_INT_PIN 21
as far as I'm aware the interrupt pins for uno are D2 and D3
does it have to be changed fro 21 to 2 and do I need to rewire to diferent pin on the Can Shield?
Any thoughts?

Another thing that i just noticed is that with that edit, the serial monitor starts outputting normal and then in few seconds it stops to output (I'm using the "BatteryMonitor" example)

Hi,
I had success, but regardless, I'm not quite happy with that as i have no idea why it works now :confused:

After long struggle, I finally got it working on UNO. I'm not sure if I did the right thing, but it seems to be working.
It ended up that I needed to add another line after the line Timo instructed me to add in my .ino file
Here is what I added in my .ino file:

#define N2k_SPI_CS_PIN 10 // as per Timo's instructions
#define N2k_CAN_INT_PIN 21 // lucky guess?

I'm not sure exactly why it works, because as far as I know the interrupt pins for UNO are 2 and 3.
Can someone explain as I'm trying to understand?

There is no definition for interrupt as default on NMEA2000_CAN.h. If you want to use interrupt, you have to define it before including NMEA2000_CAN.h. And if you define wrong pin, it won't work at all.

If you have interrupt definition on NMEA2000_CAN.h, check that you have downloaded the sources from my githup.

Hi Timo,
Excuse my ignorance but I'm not exactly clear what sources I need to download?

In my original, updated and "official" version of NMEA2000_CAN.h there is no definition for interrupt as default. So if you look NMEA2000_CAN.h on my Github (https://github.com/ttlappalainen/NMEA2000/blob/master/NMEA2000_CAN.h) there is not #define N2k_CAN_INT_PIN 21 after #define N2k_SPI_CS_PIN 53 exept as informative. So I was just wondering, where you had downloaded that version and will it have other changes related to some system.

Hi Again,

Today I went down to my boat in order to try and get my ESP8266 with MCP2515 NMEA2000 logger up and running.

So I experience the following... All boat electronics is up and running, I can see fx Wind Speed in my ChartPlotter and the MCP2515 is attached to the Simnet network but not turned on yet.

All works!

Then I turn on the Canbus controller and ESP8266 with just opens the NMEA2000 for listening.

I watch the updates from the Wind speed indicator on the chart plotter AND after 5 secs the communication on the BUS halts completely.

If I then turn off the 2515 and ESP8266 the BUS runs again....

I can see that I have configured the MCP2515 as 16 Mhz but there is only 8 Mhz crystal on the board.

So maybe that is the problem?
So maybe using this define is the way forward?

#define USE_MCP_CAN_CLOCK_SET 8

But why the bus stops with wrong clock is beyond me

If i measure the voltages on L / H with 2515 off the voltages is: 2.5 V and 2.5V

With 2515 on: 2.7V and 3V only measured with a digital voltage meter...

Any suggestions?

If you e.g. shortcut the L/H, communication will stop. So either you 2515 is failing (or driver after 2515) or wrong clock set will cause the failure.