Arduino Due sending to Canbus (N2000) - help needed

skyflyer

Active member
Joined
26 Jan 2011
Messages
1,433
Location
Worcester, UK
Visit site
Almost there! I'm using an Arduino Due to multiplex NMEA0183 sentences from different transducers which it then re-transmits to my chart plotter.

It also converts the data to NMEA2000 format (packets). I am able to send these to the serial ports and they are correctly read by a PC running the Actisense NMEA Reader software.

In order to actually send the data to the NMEA2000 network on the boat the next step is to get the Arduino to send the packets to its Canbus pins on the board.

and that's where I've got stuck!

I'm aware (i think!) that I need the due_can.h library, but any help with what needs to be added to the sketch to actually send the data to the can bus pins would be handy!

No doubt someone has invented this wheel already!
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
Almost there! I'm using an Arduino Due to multiplex NMEA0183 sentences from different transducers which it then re-transmits to my chart plotter.

It also converts the data to NMEA2000 format (packets). I am able to send these to the serial ports and they are correctly read by a PC running the Actisense NMEA Reader software.

In order to actually send the data to the NMEA2000 network on the boat the next step is to get the Arduino to send the packets to its Canbus pins on the board.

and that's where I've got stuck!

I'm aware (i think!) that I need the due_can.h library, but any help with what needs to be added to the sketch to actually send the data to the can bus pins would be handy!

No doubt someone has invented this wheel already!

good to see your're doing what I'm planning to do in March :D
still waiting for my Due.
Are you using the built in can interface? (Just in case I also bought a couple of extra boards to test...)

are you aware of the work carried out by a Fin? He seems to know his stuff and done a few sentences already, plus libs and some instructions:

https://github.com/ttlappalainen/NMEA2000_due

I think the main problem is formatting the sentences as I haven't found any clear documentation/examples.
What sentences are you pumping through?

cheers

V.
 

skyflyer

Active member
Joined
26 Jan 2011
Messages
1,433
Location
Worcester, UK
Visit site
Vas

The Fin is a guy called Timo, I think, and yes he has been very helpful.

Basically I am not the expert, most of this has been done by a friend of mine who knows twice what I do, but half what he needs to finish it!

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 (about £3)

The due-can library will enable you to send data to the can pins on the board but you still need a transceiver chip downstream of that. Not quite sure what it does but do i need to know - no!

The NMEA library takes data from the 0183 input and packs it up in a suitable packet to send to the N2K network. Again, I have no real idea how it works but it does!

Sorry not to be much help. It's a dark art as far as I am concerned. Largely done via trial and error

One thing that is really useful is to download the free Actisense NMEA reader software. Anything you 'create' with the arduino can be fed to this which decodes it so you can see if you are sending what you think or if there are errors.
 

vas

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

The Fin is a guy called Timo, I think, and yes he has been very helpful.

Basically I am not the expert, most of this has been done by a friend of mine who knows twice what I do, but half what he needs to finish it!

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 (about £3)

The due-can library will enable you to send data to the can pins on the board but you still need a transceiver chip downstream of that. Not quite sure what it does but do i need to know - no!

The NMEA library takes data from the 0183 input and packs it up in a suitable packet to send to the N2K network. Again, I have no real idea how it works but it does!

Sorry not to be much help. It's a dark art as far as I am concerned. Largely done via trial and error

One thing that is really useful is to download the free Actisense NMEA reader software. Anything you 'create' with the arduino can be fed to this which decodes it so you can see if you are sending what you think or if there are errors.

First of all i have to say that I probably wont be of any help, as it seems you're ahead of me in this task.
However I've ordered 3 or 4 different canbus chips/boards of sorts "just in case" so I'll gladly test something if you wish (once they arrive that is!)

I'm at a stage I can send and interpret NMEA0183 messages either via software serial or h/w serial (only sending on h/w atm) and I'm not finding things too hard once you get your h/w wirings right.
Any reason why software serial doesn't work on Due? I may have to use both my TTL-RS232 converters for 0183 I/O.

Any idea what this transceiver chip is, and what is the point of it considering the diagrams that Timo has included in the nmea2000 master lib?

thanks for the Actisense reader sw pointer, been to their site various times, never bothered checking the download section!
Checked it, shows my AutoAnchor, depth and wind sentences just fine (but then I knew it as they work on the GMI as well)




After delving into much Arduino code over the last couple of weeks, I think you have summed it up nicely.

so it seems that ppl around YBW forums left right and centre are coding various things in arduino...

Maybe we should have a show us your code thread rather than the show us your wake shot, or best pic of your boat.
OK, maybe best pic of your MFD/plotter/smartphone/touchscreen would be more appropriate :D

cheers

V.
 

SiteSurfer

Active member
Joined
18 Jun 2015
Messages
1,262
Visit site
Software serial runs fine - allthogh given the Due has 3 sets of serial in/out pins anyway - its not used much.

So you just use Serial1/2/3. I used the TTL converters into 2 of the hardware serials for my sentences.
 

rogerthebodger

Well-known member
Joined
3 Nov 2001
Messages
13,453
Visit site
image: http://www.ybw.com/forums/images/ybw/misc/quote_icon.png
Quote Originally Posted by skyflyer
image: http://www.ybw.com/forums/images/ybw/buttons/viewpost-right.png
View Post
..I have no real idea how it works but it does! ...

After delving into much Arduino code over the last couple of weeks, I think you have summed it up nicely.

That's why any code that needs to be shared should be well documented. I would document code if written for someone else but never bothered for any code written for myself.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
In order to actually send the data to the NMEA2000 network on the boat the next step is to get the Arduino to send the packets to its Canbus pins on the board.

and that's where I've got stuck!

I'm aware (i think!) that I need the due_can.h library, but any help with what needs to be added to the sketch to actually send the data to the can bus pins would be handy!

No doubt someone has invented this wheel already!

was just checking again Timo's files,

what h/w do you use on your due to get the signals out towards the CANBUS?
Unless I'm missing something, it seems you can use
MCP2562, SN65HVD234 or MCP2515. (they are a couple of quid each and I've ordered one of each just in case)
From the drawings seems fairly straightforward and in theory should work straight away (say testing the WindMonitor.ino example), no mention of other layers of s/w from my reading...

V.
 

skyflyer

Active member
Joined
26 Jan 2011
Messages
1,433
Location
Worcester, UK
Visit site
Vas

When i tried to upload a sketch to the Due that had "include SoftwareSerial.h" it failed to compile (but it would do so on my nano) so i assumed that it won't use/run any soft serial ports as it doesn't need them, given that is has more than one Tx/Rx pair of ports anyway.

I have been told that soft serial ports use a lot of processing power, too.

The downside is that you can't invert the signal automatically as you can with SoftSerial ports

I followed Timo's circuit diagram here so bought the MCP2562. As I said - not sure why its needed, but intend to wire it as shown!

My knowledge-gap at the moment concerns how to configure and use the Due-can library to send the data to the can ports. I need some sample code to hack about with! I can send the data to the normal Tx/RX serial ports and read it on the ACtisense NMEA reader, but have yet to work out how to write the sketch to send it to the Can pins.
 
Last edited:

vas

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

When i tried to upload a sketch to the Due that had "include SoftwareSerial.h" it failed to compile (but it would do so on my nano) so i assumed that it won't use/run any soft serial ports as it doesn't need them, given that is has more than one Tx/Rx pair of ports anyway.

I have been told that soft serial ports use a lot of processing power, too.

The downside is that you can't invert the signal automatically as you can with SoftSerial ports

I followed Timo's circuit diagram here so bought the MCP2562. As I said - not sure why its needed, but intend to wire it as shown!

My knowledge-gap at the moment concerns how to configure and use the Due-can library to send the data to the can ports. I need some sample code to hack about with! I can send the data to the normal Tx/RX serial ports and read it on the ACtisense NMEA reader, but have yet to work out how to write the sketch to send it to the Can pins.

any progress?

received my due a couple of days ago and today I got my MCP2515 CAN board
Also noticed that I couldn't compile with SoftwareSerial.h but since I've got 2 TTL-232 converters I'll skip that for now.

Planning to spend a few hours during the w/e trying to pump some readymade sentences out
Even hacked a garmin terminator I had spare to get to the resistor in order to cut it and wire the CAN signal there (once I figure out how...)

cheers

V.
 

skyflyer

Active member
Joined
26 Jan 2011
Messages
1,433
Location
Worcester, UK
Visit site
Afraid not - I think i fried the MCP2562 so have ordered another! I did finally work out how the whole arrangement connects to the N2000 network. Basically the power lines (2 cores, +12v and ground) in the cable are used to power the arduino and the two signal lines (Can-H and Can-L) come from the MCP chip.

I think - but can't try it out yet - that the library NMEA2000 that Timo specifies, calls on other libraries so that the signal is sent to the can pins without any need to add specific configuration in the sketch.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
hm :(

I manage to revert to hardware serial, checked and run my sketch on the autoanchor on the due using Serial1.
Everything works fine (after a bit of head scratching on multiple serial naming...), struggling a bit with reading NMEA0183 messages from the garmin, but I think I've got it.

Currently not bothering driving the arduino from the N2K bus as I've not received my 12->3.3V dropper yet.
however I do have the MCP2515 and will try it tomorrow.
Any hints to avoid burning mine, or you did something v.silly that is best not posted? :p
Seems straight forward with V+ grnd

cheers

V.
 

rgarside

Active member
Joined
24 May 2009
Messages
502
Location
East Coast
Visit site
hm :(

I manage to revert to hardware serial, checked and run my sketch on the autoanchor on the due using Serial1.
Everything works fine (after a bit of head scratching on multiple serial naming...), struggling a bit with reading NMEA0183 messages from the garmin, but I think I've got it.

Currently not bothering driving the arduino from the N2K bus as I've not received my 12->3.3V dropper yet.
however I do have the MCP2515 and will try it tomorrow.
Any hints to avoid burning mine, or you did something v.silly that is best not posted? :p
Seems straight forward with V+ grnd

cheers

V.
If your Due has arrived, doesn't it have 4 hardware UARTs? In which case you can use 3 of those without the complications of software serial or using the one needed for programming.

There is code that reads two incoming NMEA streams, identifies required sentences and logs and multiplexes the two streams in the file I sent.
 

vas

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

having sorted my h/w serial reading/writing to the SD and few other things, I started with the arduino -> N2K project.

I also have collected (and read to an extent!) various bits of info focusing on the latest Github offerings found https://github.com/ttlappalainen

I managed to wire my MCP2515 CAN bus board to the Due (in a way described in a PDF file https://github.com/ttlappalainen/NM...ents/ArduinoMega_CAN_with_MCP2515_MCP2551.pdf)
Got son to help wire temp 40cm cables on the hacked N2K socket (started life as a terminator but now has red black blue and white wires ;) )
Wired everything up (not bothering getting 12V from the N2K bus to run the due, that can wait) and connected to the bus that I have my test device (Garmin GMI10).
Loaded a test WindMonitor sketch, uploaded it nada. Doesn't crash, does compile, upload but nothing happens, just a red led on the CAN board.

Reading again it seems that you really don't need anything else to run as the included NMEA2000_CAN.h does all the if then and loads the right libraries.
Even went a bit on specifically loading the bits I wanted, no luck as in nothing shows on the GMI10 on the wind direction/speed page.

What now ?


I'm slightly puzzled on two issues:

A. why do we really need a bleeding CAN Bus board when the Arduino Due has one embedded? Can we just run the code with the inbuilt stuff? Rhetorical question will check myself later on...

B. Wiring the MCP board to the Due involved 5 pins of the Due (leaving aside the V+ and GND) I followed the PDF and connected them to pins 50-53 and I wired the INTerrupt which apparently is not used on N2K. However I didn't find any place in the code where the 50-53 pins are declared somehow. Should they? is it hardwired on the lib, or what?

Any ideas or simple tested sketches much appreciated!

cheers

V.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
I'm slightly puzzled on two issues:

A. why do we really need a bleeding CAN Bus board when the Arduino Due has one embedded? Can we just run the code with the inbuilt stuff? Rhetorical question will check myself later on...

B. Wiring the MCP board to the Due involved 5 pins of the Due (leaving aside the V+ and GND) I followed the PDF and connected them to pins 50-53 and I wired the INTerrupt which apparently is not used on N2K. However I didn't find any place in the code where the 50-53 pins are declared somehow. Should they? is it hardwired on the lib, or what?

Any ideas or simple tested sketches much appreciated!

cheers

V.

OK, after more studying seems that:

A. yes it has a set of CAN BUS pins but need a little chip to change them to what is N2K. Fair enough I'm still waiting for this to arrive from China

B. downloaded the new version of NMEA2000 library I linked in the previous message, read carefully the instructions, tested everything works by sending the NMEA2000 messages to the Actisense NMEAReader, (via the Serial port of the Due), all fine.

Tested on the WindMonitor sketch, and realised that you do actually define at least one pin (53 for CS)
I also played around the various conf options, changed the various libraries and headers so that it explicitly loads the MCP2515 shield ones.

Still not much luck, GMI is totally unimpressed with all my efforts and doesn't even list it in its N2K device list. power led on the canbus shield is on (and is very bright, suspiciously bright...), board doesn't feel hot, all seems fine.

One odd thing that Timo is not explaining much is the NMEA2000.SetMode() function which was reading:
NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly,23);

thought I should edit it for mcp so changed it to:
NMEA2000.SetMode(tNMEA2000_mcp::N2km_NodeOnly,23);

Project compiles, so should be okay, but still no luck.

Further he's mentioning device address (in my example it's 23)

Note that with this function you can also set default address for your device. It is preferable that once your device has been connected to the bus, it tries always use last used address. Due to address claiming, your device may change its address, when you add new devices to the bus. So it would be good to save last used address to the EEPROM and on startup read it there and use it as parameter for SetMode. You can check has your address you set originally by SetMode changed by using function 4.3.4.14 ReadResetAddressChanged and you can read current address by function 4.3.4.13 GetN2kSource.

which I cannot say I fully understand, nor can figure out if it's causing problems.

Any ideas?

cheers

V.
 
Top