Arduino Due sending to Canbus (N2000) - help needed

skyflyer

Active member
Joined
26 Jan 2011
Messages
1,433
Location
Worcester, UK
Visit site
TinyGPS++ allows extraction of any data from any NMEA0183 sentence very easily
All you need to know is the title of the sentence, so suppose it is $ABCDE
The function TinyGPSCustom is then used to get what data you want, say the 5th field in the sentence (data after 5th comma)

eg TinyGPSCustom Dataname(gps, "ABCDE", 5);

tiny GPS is just receiving serial data it doesn't "know" its a GPS sentence or a Depth sentence or a Winsentence so anything can be easily extracted

I got a reply from Timo which I'm sure he won't mind me quoting
You do not need to look due-can.h. It is enough that you have installed due-can library.

Please download the latest NMEA2000 library and at least Arduino IDE 1.6.6. Then you can simply use:
#include <Arduino.h>
#include <NMEA2000_CAN.h>
#include <N2kMessages.h>

as in almost all my updated samples. NMEA2000_CAN.h automatically selects right library according to your board (Mega, Due or Teensy).

Currently NMEA2000 library uses only Can0, so connect MCP2562 to that as in my diagram. Library automatically uses that.

There are several sending samples like TemperatureMonitor, WindMonitor and MessageSender.

In short then, it's all automatic.

I'm confused by your need for Due-custompins or what it does. The Due has two dedicated Can pins so I assume all traffic is sent to/from them?

top left in this image (for those reading who don't have a Due)
ArduinoDue.JPG
 
Last edited:

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
TinyGPS++ allows extraction of any data from any NMEA0183 sentence very easily
All you need to know is the title of the sentence, so suppose it is $ABCDE
The function TinyGPSCustom is then used to get what data you want, say the 5th field in the sentence (data after 5th comma)

eg TinyGPSCustom Dataname(gps, "ABCDE", 5);

tiny GPS is just receiving serial data it doesn't "know" its a GPS sentence or a Depth sentence or a Winsentence so anything can be easily extracted

fair enough, didn't yet have any need for that, but will do with my yet to arrive NASA NMEA0183 wind sensor, thanks for reminding me ;)

I got a reply from Timo which I'm sure he won't mind me quoting


In short then, it's all automatic.

I'm confused by your need for Due-custompins or what it does. The Due has two dedicated Can pins so I assume all traffic is sent to/from them?

top left in this image (for those reading who don't have a Due)
ArduinoDue.JPG

aha,

yep that's what I'm afraid of SF!

you both assume that there is a clear pairing:
MEGA with a 2515
Due with the 2562
and the Teensy with whatever if fits...

HOWEVER, I stupidly am trying the:
DUE + 2515 combination, hence I'm afraid that the auto setup that Timo has done will assume I'm using the two pins CANTX CANRX you mention BUT I'm using the SPI interface (just under the infinity sign on the pic you posted) instead. To complicate things further this SPI on the Due is NOT in the same spot as on the MEGA where it's in pins 50-53...

Could you please ask Timo (since you're talking to him) if he's covered that up, as I doubt that the automated system works (hence me trying manually and looking for the right pins_arduino.h file unsuccessfully!)

will have another go at disecting his NMEA2000_CAN.h file and pick the MEGA bits and load them manually instead ;)

cheers

V.
 
Last edited:

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,427
Location
Hopefully somewhere warm
Visit site
fair enough, didn't yet have any need for that, but will do with my yet to arrive NASA NMEA0183 wind sensor, thanks for reminding me ;)
Little heads up which probably won't apply - my NASA NMEA wind sensor sends out the wrong checksum, when calculating it includes the "*" at the end, I've heard this is sorted now but if you can't get something to read the sentences it might be worth checking. Mine goes through an arduino so a few lines of code makes it right again.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
Little heads up which probably won't apply - my NASA NMEA wind sensor sends out the wrong checksum, when calculating it includes the "*" at the end, I've heard this is sorted now but if you can't get something to read the sentences it might be worth checking. Mine goes through an arduino so a few lines of code makes it right again.

thanks!

will keep in mind, although unless the N2K works, I'll just wire the NASA to the plotter directly which is not what I want :(

cheers

V.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
happy or rather overly happy! to report that Due+2515+Garmin GMI10 combination finally worked :D

only thing I had to do is check carefully the NMEA2000_CAN.h file and take all the useful bits out of it and add them into my sketch. Also added the other two recommended headers
So my sketch now looks like this:

#include <Arduino.h>

//bits from NMEA2000_CAN.h that suit my setup
#include <N2kMsg.h>
#include <NMEA2000.h>

// Use mcp_can library e.g. with Arduino Mega and external MCP2551 CAN bus chip
// CAN_BUS_shield libraries will be originally found on https://github.com/Seeed-Studio/CAN_BUS_Shield
// There is improved library, which branch can be found on https://github.com/peppeve/CAN_BUS_Shield
// That works also with Maple mini and 8 MHz clock. Hopefully these improvements will be applied to
// original library
#include <SPI.h>
#include <mcp_can.h> // https://github.com/peppeve/CAN_BUS_Shield
#include <NMEA2000_mcp.h>
#define N2k_SPI_CS_PIN 10 // Pin for SPI Can Select
#define MCP_CAN_CLOCK_SET MCP_8MHz
#define N2k_CAN_INT_PIN 0xff // No interrupt.
#define MCP_CAN_RX_BUFFER_SIZE 1 // Just small buffer to save memory
//tNMEA2000_mcp NMEA2000(N2k_SPI_CS_PIN,MCP_CAN_CLOCK_SET,N2k_CAN_INT_PIN); //right one with three parameters and new NMEA2000_mcp compilation errors!
tNMEA2000_mcp NMEA2000(N2k_SPI_CS_PIN,MCP_CAN_CLOCK_SET); //old ver that works with the old ver of the NMEA2000_mcp
//end of NMEA2000_CAN.h definitions

#include <N2kMessages.h>
#include <Time.h>

Only hiccup that needs sorting is that the tNMEA2000_mcp line which calls NMEA2000 with three parameters together with the latest NMEA2000_mcp library crashes oncompilation.
Reverted back to the old version of the NMEA2000_mcp and removed the CAN interrupt pin reference and all's fine :D

BTW, I also found the pins_arduino.h of the due hidden very well, in fact so well that I had to search my whole C drive to find it again!
Its in User files/AppData/Local/Arduino15/packages/arduino/hardware/sam/1.6.6/variants/arduino_due_x/ (under Win8.1)

Proof of the thing working showing 64.7kn of wind in my office :p

N2K_due_2515_success.jpg


I'm not going to try anything more right now as I've already spent half my w/e on that, will check some details re naming of devices, broadcasting. listing on other N2K devices, etc. For example, my Garmin GMI10 shows the above screen but doesn't list it as a NMEA2000 device in it's search menu.

cheers

V.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
spend £2.50 0n an MCP2562 - it came next day's post.

see above, as it worked I may skip spending any more arduino money ;)

let alone that it wont be down here in Greece in less than a week. I may get a Mega as now I can setup more than one N2K devices in the boat, no need to run massive lengths of cables from sensors (rudder fe)

cheers

V.
 
Last edited:

adwuk

Active member
Joined
10 Jun 2015
Messages
788
Location
Tarbert
Visit site
vas, what are you doing about opto isolation? I have a Teensy 3.2 and MCP2551 transceiver on the way and not sure if we put opto isolation between TX/RX of board and transceiver or between transceiver and N2k bus. I think the former.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
vas, what are you doing about opto isolation? I have a Teensy 3.2 and MCP2551 transceiver on the way and not sure if we put opto isolation between TX/RX of board and transceiver or between transceiver and N2k bus. I think the former.

had enough problems getting this to work for starters, wasn't worried with optoisolation but I guess the optoisolation has to be between your setup and the bus (so 2551 and N2K bus). Since it's a relatively controlled environment, you shouldn't worry about the internal connections, after all you'll probably put the two boards plus fuses or whatnot in a single box
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
me again...

spent last night trying to get the Due to not only sent data to the Garmin GMI10 through N2K but to also identify itself so that the GMI lists it as a N2K device.
Didn't have any luck, wind and temp data (the ones I've tried up to now) work fine, but device is not identified by the GMI.
Only as soon as I load a new sketch to the Due (whilst connected to the GMI and only for 5-6secs the GMI "sees" the Due but brings up an invalid serial message and then the device disappears...

I'm using the lines that Timo recommends and I've tried adding all sorts of values there just in case, no luck.
Anyone done it successfully, if so how?

// Set Product information
NMEA2000.SetProductInformation("00002121", // Manufacturer's Model serial code
123, // Manufacturer's product code
"VB N2K hub", // Manufacturer's Model ID
"1.0.0.11 (2016-03-10)", // Manufacturer's Software version code
"1.0.0.1 (2016-2-1)" // Manufacturer's Model version
);


cheers

V
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
This may or may not be relevant but i discovered that when you power up the Due or load a sketch it seems to need a reset to 'kick start' it again.

Theres a simple hardware fix which involves a resistor and capacitor between the reset pin and ground

see post #37 on this thread

https://forum.arduino.cc/index.php?topic=256771.30

thanks, not sure it's relevant though, as the thing works okay, I mean sends data to the N2K bus without any issues, it's obvious that there's some problem with my title/text in identifying the device on the bus.

I'll try adding more functions to the system for now and will come back to that later

cheers

V.
 

MortLuzar

New member
Joined
23 Feb 2016
Messages
1
Visit site
The libraries you need are NMEA2000 and TinyGPS there are variants depending on which board you use i think and then the due-can library for sending via can ports.
Dealing with 0183 is relatively simple as its all 'plain text' and viewable on a serial monitor. however be aware that you need to invert the signal which can be done using the SoftwareSerial library (which doesn't work on a Due!) of by using a hardware TTL<->RS232 converter chip.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
This may or may not be relevant but i discovered that when you power up the Due or load a sketch it seems to need a reset to 'kick start' it again.

Theres a simple hardware fix which involves a resistor and capacitor between the reset pin and ground

see post #37 on this thread

https://forum.arduino.cc/index.php?topic=256771.30

had some time to check this, yes, mine also needs a reset to work from a cold start, so a solution is welcomed. However I'm not at all happy soldering tiny bits in there, got to get the son to do it for me but he's clumsy and wants to finish everything in 4secs...

Have you thought of the #42 post in the same thread, talking about burning a firmware with different reset code? Seems easier than soldering!

cheers

V.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
The libraries you need are NMEA2000 and TinyGPS there are variants depending on which board you use i think and then the due-can library for sending via can ports.
Dealing with 0183 is relatively simple as its all 'plain text' and viewable on a serial monitor. however be aware that you need to invert the signal which can be done using the SoftwareSerial library (which doesn't work on a Due!) of by using a hardware TTL<->RS232 converter chip.

thanks and welcome to the forum,

yes I'm aware and have managed to sort all my problems and have now a functioning system with a DUE and a MCP2525 and a couple (well one working one fried) TTL<->RS232 chips. The one does the NMEA0183 in out to the GMI10 for the AutoAnchor sentences emulating the AA601, and the other is a listener for the NASA WIND NMEA0183 instrument.
Once my code is a bit more polished and commented I'll post it here or to whoever wants it.

only N2K bit that doesn't seem to work and I also have a conceptual problem with it, is the declaring/broadcasting or however you want to call it, of the device NAME and properties.
Timo's code has a standard format which I copied over but my test rig with a Garmin GMI10 doesn't list my DUE as a N2K device.

The conceptual issue has to do with the fact that I have ONE DUE that "pretends" to be wind, depth, temp, rudder, tank level and potentially a few more things (like EGT thermocouple) at once. All messages are fine, but can that be described as ONE device spanning across N2K sentence families I wonder?


cheers

V.

PS. mind being your first post, you may have to wait for a few hours (or even days...) for approval before your next few posts appear here, don't worry, it will happen eventually :D
 

Anthony

Active member
Joined
8 Sep 2003
Messages
1,041
Location
Western Australia
Visit site
happy or rather overly happy! to report that Due+2515+Garmin GMI10 combination finally worked :D

N2K_due_2515_success.jpg

Hi, it looks like you are using the MCP2515 CAN Bus board which also has the TJA1050 on it, however I see no reference to using the TJA1050 on any of the circuits. Does the TJA1050 act the same as the MCP2551, i.e. is that board a direct replacement for the circuit described for the Mega using the 2515 and 2551?

If the N2K display doesn't identify your unit as an N2K device (you mentioned problems with Device ID) how are you managing to select it as a source to get it to display?

Great news that you got it working, cant wait to try this out with my Garmin plotter to get battery bank voltage and water tank levels (external capacitive sensing, yet another project) displayed. Although I'd like to know who in marketing came up with the bright idea of calling the devices 2551 and 2515, for two devices are used together...

Please keep us updated with your progress.

Ants
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
Hi, it looks like you are using the MCP2515 CAN Bus board which also has the TJA1050 on it, however I see no reference to using the TJA1050 on any of the circuits. Does the TJA1050 act the same as the MCP2551, i.e. is that board a direct replacement for the circuit described for the Mega using the 2515 and 2551?

If the N2K display doesn't identify your unit as an N2K device (you mentioned problems with Device ID) how are you managing to select it as a source to get it to display?

Great news that you got it working, cant wait to try this out with my Garmin plotter to get battery bank voltage and water tank levels (external capacitive sensing, yet another project) displayed. Although I'd like to know who in marketing came up with the bright idea of calling the devices 2551 and 2515, for two devices are used together...

Please keep us updated with your progress.

Ants

Anthony,

you're far more technical than me I'm afraid....
Let's go basic here. I originally checked Timo's docs and suggestions, found a few cheap boards on some CN ebay site that looked close to his suggestions, bought them, hooked this one up, edited the headers that Timo had produced, and voila it works. Never bothered to check if the TJA1050 is the same as the MCP2551 tbh, obviously it's compatible... I have another 2 tiny boards and a bigger CANBUS shield to try. Will probably need a second N2K transmitting board to tidy up cabling and avoid massive runs of signals about the engine bay.

Well the fact that the Due doesn't identify itself is not affecting GMI10's ability to display practically anything that I'm throwing at it.
I did try a GPSMAP751 and only got temps out of it, but I didn't spend much time trying to figure out how to configure it to display various things. tbh I don't care much as next to it is a GMI10 :)
Will try on my other plotter, a GPSMAP4008 and report.

I'll investigate this issue further once I have time, but not a high priority. Need Timo's opinion on that I think, or a few more here having working setups and help eachother debug such issues. If you do go ahead, drop me a line to help you save a few evenings sorting out cabling and sketches ;)
PM me your email and I can sent the sketch I'm using.

cheers

V.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
If the N2K display doesn't identify your unit as an N2K device (you mentioned problems with Device ID) how are you managing to select it as a source to get it to display?

Ants

Hm,

just back home, wired up the GPSMAP4008 with the GMI10 and the Due+2515 board.

GMI is obviously dumber than the 4008 as it wont show diesel tank level for example (ready configured page with this info) whereas GMI happily shows 40% full tanks...
So we need to sortout the serial # error.
If it helps what I get on the 4008 on the tank Labels is:

FUEL:
Tank 2
Unknown NMEA2k Device
Serial #: Unknown
NMEA 2000 Instance: 1

FRESH WATER:
Tank 2
Unknown NMEA2k Device
Serial #: Unknown
NMEA 2000 Instance: 1

BLACK WATER:
Tank 2
Unknown NMEA2k Device
Serial #: Unknown
NMEA 2000 Instance: 1


you see any similarities between the three :rolleyes: ?

Relates to this:

// Set Product information
NMEA2000.SetProductInformation("800000021", // Manufacturer's Model serial code
107, // Manufacturer's product code
"GVD N2K hub1", // Manufacturer's Model ID
"1.0.0.1 (2016-03-10)", // Manufacturer's Software version code
"1.0.0.1 (2016-02-11)" // Manufacturer's Model version
);

NMEA2000.SetDeviceInformation(5, // Unique number. Use e.g. Serial number.
150, // Device function=Fluid Level. 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
2122 // Just choosen free from code list on http://www.nmea.org/Assets/20121020 nmea 2000 registration list.pdf
);

Probably a combination or errors in Manufacturer's Model serial code and the SetDeviceInformation definition that follows


Skyflyer??? should we ask Timo?

cheers

V.
 

adwuk

Active member
Joined
10 Jun 2015
Messages
788
Location
Tarbert
Visit site
I've got exactly the same problem. It would appear that the SetProductInformation() data is being scrambled somehow. This is what I get on the network after these two calls. The device information is correct, but the product information clearly hasn't been transmitted correctly:

// Set product information
NMEA2000.SetProductInformation("123456", // Manufacturer's Model serial code
100, // Manufacturer's product code
"Temp monitor", // Manufacturer's Model ID
"1.0", // Manufacturer's Software version code
"1.0" // Manufacturer's Model version
);
// Set device information
NMEA2000.SetDeviceInformation(1, // Unique number. Use e.g. Serial number.
130, // Device function=Temperature.
75, // Device class=Sensor Communication Interface.
2046 // Just choose free from code list on http://www.nmea.org/Assets/20121020 nmea 2000 registration list.pdf
);

attachment.php
 
Last edited:

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
Interesting!

looks like it's quite a few of us working on arduino N2K after all :D
I've posted a couple of times on the Arduino forum on a thread that Timo is also posting but haven't got a reply from him.
IIRC Skyflyer is in contact with him, maybe he'd pass on the question?

Since the Model ID seems to be truncated on the second character, I also tried with very short (1 character long...) strings in these, and also tried with empty strings and all sorts of lengths of serial # to no avail :(
Went through the NMEA2000 master folders and files, couldn't figure out anything, so I'll wait for an update from Timo.

cheers

V.
 
Top