Arduino Due sending to Canbus (N2000) - help needed

Keith-i

Well-known member
Joined
4 Jul 2012
Messages
1,439
Location
Jersey
Visit site
Another beginner here. I have recently bought a teensy and (still to arrive) a 2551 CAN transceiver chip for some experimenting. I am using Timo's libraries and documentation and have successfully got dummy temperature data being sent to Actisense NMEA reader on my PC. I really don't yet understand what the lines of code do, nor which ones need to be commented or why but hopefully I will fathom it over time.

However, I seem to be suffering a similar problem to vas in that the device and product info is not being transmitted. It does not appear in NMEA reader. The bug that adwuk refers to seems to have been corrected in the libraries I've downloaded, but that aside I'm not even getting garbled info. Any thoughts?
 

adwuk

Active member
Joined
10 Jun 2015
Messages
788
Location
Tarbert
Visit site
Keith, product information is only sent out when it is requested by another device on the network. When each device starts up, it claims a network address and negotiates with other devices in the event of address conflicts. Your display (chart plotter or instrument display) tracks all the devices on the network and will request product information from them as and when needed. The point is that Timo's library handles all the NMEA 2000 "under the hood" stuff automatically for you.

That said, you can force the transmission of product info if you want to by calling NMEA2000.SendProductInformation();
 

Keith-i

Well-known member
Joined
4 Jul 2012
Messages
1,439
Location
Jersey
Visit site
Thanks for the explanation, much appreciated. Once my 2551 turns up I will give it a go connected to a real N2K network.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
Keith, product information is only sent out when it is requested by another device on the network. When each device starts up, it claims a network address and negotiates with other devices in the event of address conflicts. Your display (chart plotter or instrument display) tracks all the devices on the network and will request product information from them as and when needed. The point is that Timo's library handles all the NMEA 2000 "under the hood" stuff automatically for you.

That said, you can force the transmission of product info if you want to by calling NMEA2000.SendProductInformation();

do you mean that if you fire up the arduino first and the plotter/gmi/whatever afterwards, there may be a chance of it working? I'm pretty sure I've tried both ways and didn't so yes, my problem is slightly deeper. Hope the 2551s arrive soon so that I can try it. Teensy arrived yesterday so may have a go at the w/e.

adwuk: care to give us a simple description of the discussions you're having with Timo on his github page? I'm getting all the emails but I cannot say I can follow what's going on there :rolleyes:
Anything useful?

cheers

V.
 

adwuk

Active member
Joined
10 Jun 2015
Messages
788
Location
Tarbert
Visit site
So product information is only sent out by Timo's library when it is requested (i.e. remote device sends PGN126996). This is, for my Triton, when it sees data from the Teensy for the first time. It sends a request to the Teensy to basically ask "what are you?". This is then displayed in the depths of the Triton's screens.

Some discussions with Timo re improving/adding to the NMEA2000 library. Just support for additional PGNs which I have been adding to get my Teensy device into a functional state. The discussion has been solely around the implementation of these additions. So useful, yes - it has taken me hours of comparing bits and bytes, reading other people's decoding of NMEA 2000, discovering that some it this was incorrect, and then implementing a solution that works - that means that others can just have the software that works!
 

Keith-i

Well-known member
Joined
4 Jul 2012
Messages
1,439
Location
Jersey
Visit site
Sterling work adwuk, thanks for your help and also furthering the cause by collaborating with Timo to help the rest of us.

Would someone mind briefly explaining in English what these lines of code mean/do and why you might use them. I have read Timo's guide a few times but struggle to get the gist of his phrasing.

NMEA2000.SetForwardType(tNMEA2000::fwdt_Text);

NMEA2000.SetForwardOwnMessages();

NMEA2000.EnableForward(false);
 

adwuk

Active member
Joined
10 Jun 2015
Messages
788
Location
Tarbert
Visit site
NMEA2000.SetForwardType(tNMEA2000::fwdt_Text);

Any messages that are forwarded from the CAN network to the Serial (read USB) port are done so in an ASCII text format

NMEA2000.SetForwardOwnMessages();

Does the NMEA 2000 library forward any locally generated messages (normally destined for the CAN bus) to the Serial/USB port

NMEA2000.EnableForward(false);

Are any messages (including those received from others) from the CAN bus forwarded to the USB/Serial port.

In short, all useful for debugging, but once live, turn them all off as it is a waste of precious CPU cycles, unless you have a desire to forward raw NMEA 2000 messages via USB to something else.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
Sterling work adwuk, thanks for your help and also furthering the cause by collaborating with Timo to help the rest of us.

Would someone mind briefly explaining in English what these lines of code mean/do and why you might use them. I have read Timo's guide a few times but struggle to get the gist of his phrasing.

NMEA2000.SetForwardType(tNMEA2000::fwdt_Text);

NMEA2000.SetForwardOwnMessages();

NMEA2000.EnableForward(false);

cannot comment on the first two sentences, but quoting from post #75 above:


NEVER FCKING EVER comment out the line:

NMEA2000.EnableForward(false);


it does create various messages, all garbled up with the real things you want to see (or your debugging print().
Spend a whole night trying to sort that mess out...

cheers

V.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
Some discussions with Timo re improving/adding to the NMEA2000 library. Just support for additional PGNs which I have been adding to get my Teensy device into a functional state. The discussion has been solely around the implementation of these additions. So useful, yes - it has taken me hours of comparing bits and bytes, reading other people's decoding of NMEA 2000, discovering that some it this was incorrect, and then implementing a solution that works - that means that others can just have the software that works!

ADWUK, I notice on github that Timo is asking if anyone would be interested on N2K AIS sentences, I'm definitely in as I have an old NASA NMEA0183 and I have to convert it to N2K sentences so that I can get it on both plotters without messing with lots of Cabling from lower helm to f/b.
So please count me in!

cheers

V.
 

Keith-i

Well-known member
Joined
4 Jul 2012
Messages
1,439
Location
Jersey
Visit site
vas, are you suggesting that that particular line of code should always be commented out, even when just communicating with a PC and Actisense, or is it only a problem when you are connected to an N2K network?
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
vas, are you suggesting that that particular line of code should always be commented out, even when just communicating with a PC and Actisense, or is it only a problem when you are connected to an N2K network?

the exact opposite in fact :D
shouldn't be commented!
no matter if you're running it for Actisense or on a N2K network, if you comment this line serial monitor goes berserk!
Couldn't follow the debug messages I was sending on the serial monitor and I guess it will be slowing down slightly the whole thing.


cheers

V.
 

adwuk

Active member
Joined
10 Jun 2015
Messages
788
Location
Tarbert
Visit site
Vas - all that function does is determine if NMEA 2000 messages seen on your network are forwarded to your serial port. This can be very useful for debugging, but for live use (unless this is functionality you need) you should turn it off. What turn it off means is to change the value in brackets from true to false. True, forwarding happens - false, forwarding doesn't happen. Commenting out the line is the same as setting the value to true, but it is always best to understand the code you are writing/modifying rather than treating it as some kind of magical voodoo ;)
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
Vas - all that function does is determine if NMEA 2000 messages seen on your network are forwarded to your serial port. This can be very useful for debugging, but for live use (unless this is functionality you need) you should turn it off. What turn it off means is to change the value in brackets from true to false. True, forwarding happens - false, forwarding doesn't happen. Commenting out the line is the same as setting the value to true, but it is always best to understand the code you are writing/modifying rather than treating it as some kind of magical voodoo ;)

:D

got a few more lifes to live, so voodoo it is :p
Was never trained as a programmer and therefore arduino with the help of code like Timo's and contributions like yours means I can enjoy fooling around bits of code I copy paste from wherever and having the great satisfaction that something (that I don't really comprehend 100%) works!

On a serious note, all these messages it was pumping was way too much to decipher, especially as I had a system with quite a few things going around the bus. I guess if you dissect your code and try to debug small constrained bits, it would be helfpul.
For a newbie like Keith (and myself!) it is just hell!

still hadn't have the time to check the IDing of arduinos in the N2K bus. Got a teensy and a couple of Mega's so I can try getting them alltogther in the bus and see what GMI makes out of them, but weather is way too good to do programming and I'm working on the boat atm

cheers

V.
 

Keith-i

Well-known member
Joined
4 Jul 2012
Messages
1,439
Location
Jersey
Visit site
NMEA2000.SetForwardOwnMessages();
So just to clarify, this outputs any N2K messages that the arduino is producing to serial/usb

NMEA2000.EnableForward(false);
And this outputs all messages to serial/usb i.e. any it reads from the N2K bus and any that the arduino is producing.

Or am I missing something?

Regardless of the above, I can at least report success on using the example TemperatureMonitor code and getting both 'cabin' and 'water' temperature onto my Garmin 5008 including having the device show up on the N2K device list. Woohoo!
 
Last edited:

adwuk

Active member
Joined
10 Jun 2015
Messages
788
Location
Tarbert
Visit site
Correct on the first part (you can optionally put true or false as arguments depending on what you want). The second part, if you want messages forwarded you need to change the false to true. As it is written, it will disable all forwarding - and well done on getting it working!
 

vas

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

reviving this thread as I've got some more things to report and of course ask...

First, managed to burn the USB chip thingy of my MEGA clone (stupidly gave 12V on a pin, don't ask...) MEGA works but I cannot program it now, needs some convoluted process that I'll leave for now.
Thankfully I bought two of them, so the other is running all the bits of code that the DUE was running fine now.
The main reason I burnt the MEGA was that I was trying to get a CAN BUS Shield v1.0 working with it (unsucessfully...)

So now got everything (almost!) in a box and trying to get it ready for installation on the lower helm.

One first question is, what do you do with all these wires and pins routing cables about?
Surely one cannot expect a couple of dozen con wires to stay in place in the sea?

If I was using a teensy, I'd do what adwuk did with his (hope you don't mind relinking to the pic) and use breadboard and solder everything down:
attachment.php


On a MEGA or a DUE, what am I supposed to do?
I have an Arduino MEGA prototype shield v3 so in theory I could patch that on top and solder bits about and do my routing to mainly the sockets on the box that the various wires from devices around the boat will hook.
Any other ideas, as I'm about to place an order with Farnell with various bits I'm missing?

Second issue was I tried to hook the Due with a SN65HVD230D (note NOT SN65HVD234D that Timo recommends) simply because I had one...
Checked the specs, looks like the recommended one is just a development on the one I got. Wired it, tried it, nada.
Any idea of what could be possibly wrong?
I tried Timo's demos without my alternations as this setup combo is addressed by his code, but had no luck.

Finally it seems that I made a bit of a progress on the Garmin identification issue I was facing.
Reading about I added a few lines of code and commented out the various NMEA2000.SetDeviceInformation setups (one for each type of output) and now with the help of NMEA2000.SendIsoAddressClaim(); on the mail loop I get regular updates of my device being:

Uncalibrated
Actisense Unknown Device
Serial#: invalid

Now this is my working setup with a MEGA and a board featuring MCP2515 and a TJA1040. Doubt the 1050 recommended will make any difference tbh. That is with the latest NMEA2000-master from Timo

Nice to know but not very helpful. Bits of code I'm using right now for commenting:


#define N2K_SOURCE 15 //what is it for??? does it relate to other IDs mentioned later?

void setup() {

tN2kMsg N2kMsg;
// Set Product information
NMEA2000.SetProductInformation("07", // Manufacturer's Model serial code
21202, // Manufacturer's product code
"MiToS-H", // Manufacturer's Model ID
"1.33", // Manufacturer's Software version code
"1.3.3.0" // Manufacturer's Model version
);

NMEA2000.SetDeviceInformation(7, // Unique number. Use e.g. Serial number.
130, // Device function=Atmospheric. See codes on http://www.nmea.org/Assets/20120726 nmea 2000 class & function codes v 2.00.pdf
25, // Device class=External Environment. See codes on http://www.nmea.org/Assets/20120726 nmea 2000 class & function codes v 2.00.pdf
273 // Just choosen free from code list on http://www.nmea.org/Assets/20121020 nmea 2000 registration list.pdf
);
Serial.begin(115200);
//NMEA2000.SetForwardSystemMessages(true);
NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly,23);
NMEA2000.EnableForward(false);
NMEA2000.Open();

////test code:
NMEA2000.SendMsg(N2kMsg);

}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////MAIN LOOP/////////////////////////////////////////
void loop() {
SendN2kWind(); //convert NMEA0183 from NASA wind instrument to N2K
SendN2kTemperature();
SendN2kDieselFluidLevel();
SendN2kFreshWaterFluidLevel();
SendN2kBlackWaterFluidLevel();
SendN2kRudderAngle();
NMEA2000.ParseMessages();

AutoAnchor(); // NMEA0183 comms for AutoAnchor

// NMEA2000.SendProductInformation(); //doesn't work fails on compilation with
NMEA2000.SendIsoAddressClaim();
}



Evening's task is to grab a breadboard and solder the Teensy (that everyone seems to have great success with!) and the recommended MCP2551 and test it. Plan is to use the teensy on the e/r for pyrometers, temp sensing for raw water, pressure gauges and other such messy things

Sorry for the long and maybe confusing post...

cheers

V.
 

timolappalainen

New member
Joined
25 Oct 2016
Messages
1
Visit site
Hi all,

Just googling around and found my library referred. Some quick comments:

- I hope you use always the latest version of library. In present 2 months there are some big improvements.

- For technical questions about library I prefere to use Arduino forum "NMEA 2000 Shield" topic (http://forum.arduino.cc/index.php?topic=50893.105)

- For the errors or issues with libray use library github page to add issue.

- I have personally tested all my examples and drawings. I also had to do some upgrades for drawings after finding some issues like important diode for due board power connection. I still have not managed to burn any chip, even I once made a new Teensy with MCP2562 and powered the chip opposite.

- I have moved to use only MCP2562 or MCP2551, since I have not had any problems with them. I read somewhere problems with 3.3V only chips that there would be not enough "power" for boat long N2k busses. May be wrong infromation and maybe just bad hw. So please inform, if you have success or have any issues with other CAN bus driver chips.

- Someone commented: "NEVER FCKING EVER comment out the line: NMEA2000.EnableForward(false);" I am sorry if my document is clear enough. Hopefully you understand how difficult it is write public document for system you know extremely well. Sometimes would be better that some other would write the document and ask the questions what and why. Also I am Fin, so the language is not the best. But anyway, if you like to print you own data to serial/usb, you need to set NMEA2000.EnableForward(false); Otherwise your data will be messed with N2k messages.

- "#define N2K_SOURCE 15" This is not needed, if you do not use it. You could have e.g. NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly,N2K_SOURCE); Then it has some effect.

- "// NMEA2000.SendProductInformation(); //doesn't work fails on compilation with" Should work, but should no be necessary. There are some fixes for latest version due to sending problem. Library automatically respond this, when other device queries it.

- "NMEA2000.SendIsoAddressClaim();" Also this should not be necessary. Library also does automatic address claiming and informing to the bus. I have heard some "badly behaving" MFD, which does not automatically query others and instead requires that every device does "SendIsoAddressClaim" at least withing 2 sec. This is not requirement of NMEA2000 standard. Also that was before latest update. At least you should not send it on loop every time. You need timer to limit sending to 1-2 sec. But before that please try without with latest library version.

- Check also https://hackaday.io/project/11055-kbox based on my library.

- Check also NMEA simulator and OpenSkipper on http://www.kave.fi/Apps/

Nice to see that you have found my library. Hopefully it helps others to develop devices to closed N2b bus. It is "closed" bus but not rocket science. I am also willing to develop library, since I use it on my own yacht.

Timo
 

adwuk

Active member
Joined
10 Jun 2015
Messages
788
Location
Tarbert
Visit site
Timo, good to have you on YBW!

This is the thread where practical boat owners are hands on with electronics and software rather than wrenches and grease. Nevertheless great strides are being made.

After the initial inspiration from vas, I now have a fully functioning N2K pressure sensor, OpenCPN route upload/navigation and N2K to wifi gateway all contained in 1 small box and using 0.1amp. All this is working in a large part thanks to your efforts and the small contributions I have made.

attachment.php


This community stuff is first rate!
 
Last edited:
Top