Go Down

Topic: NMEA 2000 Shield (Read 87244 times) previous topic - next topic

timolappalainen

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 http://www.hantronix.com/page/index/products/tft 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. https://github.com/signalk/specification/wiki/Raspberry-Pi-Installation-(Java-Server)

seamaster

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?
 

timolappalainen

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.

seamaster

#168
Feb 21, 2017, 08:06 am Last Edit: Feb 21, 2017, 08:58 am by 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)

timolappalainen

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  :smiley-confuse:

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?



timolappalainen

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.

seamaster

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

timolappalainen

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.

flemmingdjensen

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?

timolappalainen

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.

flemmingdjensen

#176
Mar 20, 2017, 08:57 pm Last Edit: Mar 20, 2017, 09:07 pm by flemmingdjensen
Hi Timo (and others)

The problem was indeed the faulty clock setup. After I changed to 8Mhz - the same as the xtal - everything works and the bus continues...

Success....

So now I am logging some different parameters and fetching Wind speed / direction from the NMEA 2000 BUS.

See my logger here:
https://thingspeak.com/channels/198625/


The depth is not correct yes. This I have to investigate

// BR Flemming

r2d290

#177
Apr 12, 2017, 10:51 pm Last Edit: Apr 12, 2017, 10:58 pm by r2d290
Alright, my turn to try to get this working. Some struggles, so any help would be highly appreciated.

Hardware Setup:
  • N2K-bus
  • NGT-1 ISO (the one without USB-cabel)
  • A home-made DP-9 connector soldered to the end of the NGT-1 ISO cabel.
  • USB-to-serial cabel (IC199A-R3)
  • Arduino Uno
  • Micro USB-cabel
  • Can-Bus shield v1.2 by DiyMore
  • MFD: 2x SIMRAD (NSS12 ev2)

Note: I have not connected any interrupt. Also, I have not connected digital pin 0-7 on the CAN-BUS shield to the Arduino, since one of the 8-pin sockets were missing when I got it.

  • I have been abel to use NMEA reader to read all the existing information on the bus (pic1). As you can see, the temperatures comes from both SRC 3 and SRC 4. SRC 3 is gone when I turn off the aft MFD. The plan in the beginning is to try to have the Arduino to send this signal instead.
  • I have been abel to upload the temperatureMonitor example to the UNO. When it is in debug-mode, I am abel to read the ISO Address claim, Temperature and Environmental Parameters. Note from the code attached bellow - I have no idea why, but I have to have those 4 randomly added Serial printlines in the setup to get it to work. If I try to remove or add any of them, it does not work. I would be greatly happy to get an explaination of this, as it makes no sense.
  • I have been abel to get the PWR, TX and RX to light up.


From my MFD I select settings for my Water temp. I can then select "Data sources" and then I can select between getting this from one of the two MFDs. When I turn of the aft MFD, I'm only allowed to select "This equipment". When I turn off the aft MFD, and then connected my NGT-1 Iso's DB-9 plug to the CAN-BUS Shield, I would expect the arduino to appear as one of the Data sources, but does not. Also, only one of the LEDs on the NGT-1 is blinking.

Also, I'm not abel to get the NMEA-simulator to work. Connecting the NGT-1 to computer via the Serial-to-USB cabel, and with the settings as you can see attached. Still no device available on the MFD.
With the NMEA-simulator (as well as with the NMEA-reader) two LEDs are blinking on the NGT-1.

Any further suggestions for troubleshooting?

And by the way - Thanks for a great job creating and supporting this! :)

Code: [Select]

// Demo: NMEA2000 library. Send main cabin temperature to the bus.

#include <Arduino.h>
#define N2k_SPI_CS_PIN 10
#include <NMEA2000_CAN.h>  // This will automatically choose right CAN library and create suitable NMEA2000 object
#include <N2kMessages.h>

// List here messages your device will transmit.
const unsigned long TransmitMessages[] PROGMEM={130310L,130311L,130312L,0};

void setup() {
  // Set Product information
  NMEA2000.SetProductInformation("00000001", // Manufacturer's Model serial code
                                 100, // Manufacturer's product code
                                 "Simple temp monitor",  // Manufacturer's Model ID
                                 "1.1.0.21 (2016-12-31)",  // Manufacturer's Software version code
                                 "1.1.0.0 (2016-12-31)" // Manufacturer's Model version
                                 );
  // Set device information
  NMEA2000.SetDeviceInformation(112233, // Unique number. Use e.g. Serial number.
                                130, // Device function=Temperature. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                75, // Device class=Sensor Communication Interface. See codes on  http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                2040 // Just choosen free from code list on http://www.nmea.org/Assets/20121020%20nmea%202000%20registration%20list.pdf                              
                               );
  // Uncomment 2 rows below to see, what device will send to bus. Use e.g. OpenSkipper or Actisense NMEA Reader                          
  Serial.begin(115200);
  NMEA2000.SetForwardStream(&Serial);
  Serial.println("1");
  Serial.println("2");
  Serial.println("3");
  Serial.println("4");
  // If you want to use simple ascii monitor like Arduino Serial Monitor, uncomment next line
  //NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text. Leave uncommented for default Actisense format.

  // If you also want to see all traffic on the bus use N2km_ListenAndNode instead of N2km_NodeOnly below
  NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly,3);
  //NMEA2000.SetDebugMode(tNMEA2000::dm_Actisense); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega
  //NMEA2000.EnableForward(false); // Disable all msg forwarding to USB (=Serial)
  // Here we tell library, which PGNs we transmit
  NMEA2000.ExtendTransmitMessages(TransmitMessages);
  NMEA2000.Open();
}


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

double ReadCabinTemp() {
  return CToKelvin(22.5); // Read here the true temperature e.g. from analog input
}

double ReadWaterTemp() {
  return CToKelvin(15.5); // Read here the true temperature e.g. from analog input
}

#define TempUpdatePeriod 2000

void SendN2kTemperature() {
  static unsigned long TempUpdated=millis();
  tN2kMsg N2kMsg;

  if ( TempUpdated+TempUpdatePeriod<millis() ) {
    TempUpdated=millis();
    SetN2kTemperature(N2kMsg, 1, 1, N2kts_MainCabinTemperature, ReadCabinTemp());
    NMEA2000.SendMsg(N2kMsg);
    SetN2kEnvironmentalParameters(N2kMsg, 1, N2kts_MainCabinTemperature, ReadCabinTemp());
    NMEA2000.SendMsg(N2kMsg);
    SetN2kOutsideEnvironmentalParameters(N2kMsg, 1, ReadWaterTemp());
    NMEA2000.SendMsg(N2kMsg);
    // Serial.print(millis()); Serial.println(", Temperature send ready");
  }
}



timolappalainen

Hi,

First. Unfortunately NMEA-Simulator does not currenty send through any NGT. It reaquires some initialization message, which I have not yet done. I have the work on table but too much to do. There is example code ActisenseSender, which I use with simulator, but it requires at least Mega board. With DUE you can use ActisenseListenerSender - one USB for receiving and other for sending.

With Arduino Uno there is some unsolved problem. There is e.g. issue https://github.com/ttlappalainen/NMEA2000/issues/20 , where user finally gave up. I have only Due, Mega and Teensy boards for testing. Since Teensy size I like it most.

I do not see any reason why Uno should not work. You could first try some things:
- Comment  #define N2k_SPI_CS_PIN 10 -> // #define N2k_SPI_CS_PIN 10 . If you interrupt wire is not connected or right, it won't work, if interrupt pin has been defined. Without definition library will not use interrupt.

- Is there enough memory as default? Uno has only 2kB and library has been tested with Mega 8kB ram. Add next lines before NMEA2000.Open();
  NMEA2000.EnableForward(false); /this disables message forwarding and save some memory.
  NMEA2000.SetN2kCANMsgBufSize(2);
  NMEA2000.SetN2kCANSendFrameBufSize(30);
This will reduce reseved memory for message buffers.

- To check free memory I used library on http://playground.arduino.cc/Code/AvailableMemory. Add e.g. after TempUpdated=millis(); lines
    Serial.print("freeMemory()=");
    Serial.println(freeMemory());
Remember to include #include <MemoryFree.h> at beginning of the code.

Timo

r2d290

Thank you for your fast reply :)

I don't quite understand the part with commenting out #define N2k_SPI_CS_PIN 10
I thought I did this to overwrite the CS_PIN 53 that is used by Mega, to instead use the CS_PIN10 for the UNO?

When I comment out this line, I can no longer see the light on TX or RX. I also tried to change the number from 10 to 9 (as you suggested in the issue you linked to), but also then, the light on TX and RX is gone. I used my multimeter on the CAN-BUS shield to confirm that Arduino UNO pin 10 (SS), 11(MOSI), 12(MISO) and 13(SCK) goes  to MCP2515 pins 16 (CS), 14(MOSI), 15(MISO) and 13(SCK).
I find it a bit strange, though, that both RX and TX is lit, even when nothing is connected to the DB9-connector on the CAN-BUS shield.

Is it necessary to have the interrupt-cabel to get the communication to work? According to your schema, the MCP2515 INT, pin 12, should be connected to Arduino pin SCL, but the CAN-BUS shield has this on digital pin 2 instead. So, since I have not yet connected it - do I need it? And if so - what changes should I do to change Arduino pin SCL to Arduino pin 2? And - what changes can I do to drop/skip using the interrupt?

Quote
Is there enough memory as default?
Code: [Select]
freeMemory()=483
freeMemory()=483

Also, thanks to the "NMEA2000.SetN2kCANMsgBufSize(2);", I no longer need to have those Serial.println(1,2,3,4) lines that I had in the beginning. So, that part seems a little better.
However, when I run in debug-mode now, I no longer see the "ISO Address claim", only the three other. Not sure how important that is, though.


So, to summarize - I'm still unable to get det arduino to display on the MFD. I have not connected the Interrupt-signal to the CAN-BUS shield. The TX and RX on the CAN-BUS shield is blinking verry fast (previously I think it was constantly lit). The NGT-1 is only blinking on that one led that is always blinking when connected to the gate (on the boat).

Any further troubleshooting suggestions?

This is my code now:

Code: [Select]

// Demo: NMEA2000 library. Send main cabin temperature to the bus.

#include <Arduino.h>
#include <MemoryFree.h>
#define N2k_SPI_CS_PIN 10
#include <NMEA2000_CAN.h>  // This will automatically choose right CAN library and create suitable NMEA2000 object
#include <N2kMessages.h>

// List here messages your device will transmit.
const unsigned long TransmitMessages[] PROGMEM={130310L,130311L,130312L,0};

void setup() {
  // Set Product information
  NMEA2000.SetProductInformation("00000001", // Manufacturer's Model serial code
                                 100, // Manufacturer's product code
                                 "Simple temp monitor",  // Manufacturer's Model ID
                                 "1.1.0.21 (2016-12-31)",  // Manufacturer's Software version code
                                 "1.1.0.0 (2016-12-31)" // Manufacturer's Model version
                                 );
  // Set device information
  NMEA2000.SetDeviceInformation(112233, // Unique number. Use e.g. Serial number.
                                130, // Device function=Temperature. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                75, // Device class=Sensor Communication Interface. See codes on  http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                2040 // Just choosen free from code list on http://www.nmea.org/Assets/20121020%20nmea%202000%20registration%20list.pdf                               
                               );
  // Uncomment 2 rows below to see, what device will send to bus. Use e.g. OpenSkipper or Actisense NMEA Reader                           
  Serial.begin(115200);
  NMEA2000.SetForwardStream(&Serial);
  // If you want to use simple ascii monitor like Arduino Serial Monitor, uncomment next line
  //NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text. Leave uncommented for default Actisense format.

  // If you also want to see all traffic on the bus use N2km_ListenAndNode instead of N2km_NodeOnly below
  NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly,3);
  //NMEA2000.SetDebugMode(tNMEA2000::dm_Actisense); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega
  NMEA2000.EnableForward(false); // Disable all msg forwarding to USB (=Serial)
  NMEA2000.SetN2kCANMsgBufSize(2);
  NMEA2000.SetN2kCANSendFrameBufSize(30);
  // Here we tell library, which PGNs we transmit
  NMEA2000.ExtendTransmitMessages(TransmitMessages);
  NMEA2000.Open();
}


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

double ReadCabinTemp() {
  return CToKelvin(22.5); // Read here the true temperature e.g. from analog input
}

double ReadWaterTemp() {
  return CToKelvin(15.5); // Read here the true temperature e.g. from analog input
}

#define TempUpdatePeriod 2000

void SendN2kTemperature() {
  static unsigned long TempUpdated=millis();
  tN2kMsg N2kMsg;

  if ( TempUpdated+TempUpdatePeriod<millis() ) {
    TempUpdated=millis();
    //Serial.print("freeMemory()=");
    //Serial.println(freeMemory());
    SetN2kTemperature(N2kMsg, 1, 1, N2kts_MainCabinTemperature, ReadCabinTemp());
    NMEA2000.SendMsg(N2kMsg);
    SetN2kEnvironmentalParameters(N2kMsg, 1, N2kts_MainCabinTemperature, ReadCabinTemp());
    NMEA2000.SendMsg(N2kMsg);
    SetN2kOutsideEnvironmentalParameters(N2kMsg, 1, ReadWaterTemp());
    NMEA2000.SendMsg(N2kMsg);
    // Serial.print(millis()); Serial.println(", Temperature send ready");
  }
}



Go Up