Arduino Due sending to Canbus (N2000) - help needed

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
Read this thread. Fascinating. Didnt understand a word of it but it sure is geeky.

:D that's probably what i'd think a couple of months back. Things are getting clearer but has to be said that NMEA2000 is 5-10 times harder than NMEA0183 which with minimal knowledge managed to successfully do.

I'm very impressed at the amount of progress being made - Have you tried contacting Timo to ask him questions?

I feel that we only need a bit more to get going and the good thing is once you have the setup right and working, you just v.easily thanks to Timo's efforts add PGNs (ok, from the supported list...)
I've tried contacting Timo before xmas didn't get a reply, but maybe I was using an email he doesn't monitor anymore (was from the arduino forum iirc)
Let's see what Skyflyer (or anyone else that has a working setup with a Mega or Due!) thinks about my rumblings and we go on from there...

cheers

V.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
sorry, not able to make it any easier/comprehensible but for whoever is interested a warning:

DONT assume that wiring suggestions for Arduino MEGA work on the DUE!
took me a few hours headscratching and reading to realise that when wiring the DUE to the 2515 you DONT use the pinout recommended by Timo as it refers to a MEGA.
Getting both pinout diagrams next to each other did help realise the error and helped me get an answer to the question "how the the s/w know which pins I've connected where?"
We are talking SPI interface so the 5 of the 6 pins in the middle of the Due are the ones to use instead of pins 50-53

Unfortunately still no bananas :(
but I feel I'm getting there :)

cheers

V.
 

adwuk

Active member
Joined
10 Jun 2015
Messages
788
Location
Tarbert
Visit site
Not really. raspberry pi is a cheap linux computer. arduino, designed in Italy, is a cheap electronics prototyping system. They work together pretty well.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
I know very little about the Arduino, only what I have picked up in converting code for a PIC microcontroller. However, I believe you still have to tell it what pins you are using for SPI, perhaps in the constructor?

you may be right, but I'm struggling figuing out what this bleeding Due does and it's config files.
Appears that on my sketch I include Arduino.h which in itself includes pins_arduino.h of which there are a dozen or so.
Strangely I cannot find one for the Due, seems that system picks the Mega one which indeed has 50-53 pins defined in pins_arduino.h

got to do a bit more studying and figuring out resources, how board is identified in the IDE and what resources are picked from where. I hope I can just copy the ones I want in the sketch project folder and the compiler uses them rather than looking around for other files. At least that's how other IDEs work (from what I remember...)
If that's the case, I have to source a few files before getting everything right.
OTOH, I might as well buy an Arduino Mega and try everything as is.

If you are using SPI to interface to the canbus chip then I guess any arduino will do? I've got a couple of pro minis lying around so may have a crack at this if so.

edit: just seen this board. looks like it might simplify some of the wiring and allow use of smaller arduinos: http://www.microchip.com/wwwproducts/Devices.aspx?product=MCP2562

Don't know, but tried using one of the Uno's I have to no avail. Wouldn't compile with out of memory, so check specs of the board (or simply get the NMEA2000 lib and follow Timo's steps to test compilation and messaging to simple Serial interface. If it works, you're fine, uno didn't compile fullstop.

cheers

V.
 
Joined
20 Jun 2007
Messages
16,234
Location
Live in Kent, boat in Canary Islands
www.bavariayacht.info
... I'm struggling figuing out what this bleeding Due does and it's config files...

This is what I perceive as the major problem of the Arduino. It masks the underlying structure of the microcontroller in an attempt to simplify the interface, but in doing so makes it hard to do anything out of the ordinary. Most people use Arduino devices by copying code they find online.

Personally I use PIC Microcontrollers programmed in C, either on a development board or on a home-built one. The initial learning curve is steeper, but once you get the idea then the possibilities are limitless.

[Edit]

Latest project, Water Tank Gauge
 
Last edited:

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,427
Location
Hopefully somewhere warm
Visit site
This is what I perceive as the major problem of the Arduino. It masks the underlying structure of the microcontroller in an attempt to simplify the interface, but in doing so makes it hard to do anything out of the ordinary.
Not really, all the info is online plus an incredible amount of discussion already of any weirdness and masses of help on the arduino forums. What does come up more often are run arounds getting shields to work which have their own eccentricities rather than the boards themselves.

Chances are anything you can imagine doing has been done before and more efficiently.
 

skyflyer

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

The Due board is not a standard one available in the IDE so it has to be added - go to 'Tools'>Board>Board manager

The advantage of the Due for N2K stuff is that it has can bus pins as standard so the config is supposedly easier (using MCP2562 chip) but I'm still working on it.

The disadvantage is that input voltages must be limited to 3.3v so essential to include a voltage divider to reduce any voltage greater than that OR use an opto-isolator which enables differing voltages either side.

I am hoping to get mine running this coming week. At the moment I have everything assembled on a test panel, at home, and am using an Arduino Nano to simulate wind transducer input, but will be using actual GPS, actual Depth transducer input, multiplexing all together and outputting to (hopefully) both N2000 and N183
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
This is what I perceive as the major problem of the Arduino. It masks the underlying structure of the microcontroller in an attempt to simplify the interface, but in doing so makes it hard to do anything out of the ordinary. Most people use Arduino devices by copying code they find online.

Personally I use PIC Microcontrollers programmed in C, either on a development board or on a home-built one. The initial learning curve is steeper, but once you get the idea then the possibilities are limitless.

[Edit]

Latest project, Water Tank Gauge

fully agree but since I'm simply a lousy project driven programmer, I get what's available around and try to accomplish the task.
I think the main issue is that I never ever learnt programming and I'm too old and busy to do so now!

[no time right now, but will surely check this project of yours, interested on having a watertank gauge myself, especially since I have no access/hole on the top of the tanks]

Vas

The Due board is not a standard one available in the IDE so it has to be added - go to 'Tools'>Board>Board manager

The advantage of the Due for N2K stuff is that it has can bus pins as standard so the config is supposedly easier (using MCP2562 chip) but I'm still working on it.

The disadvantage is that input voltages must be limited to 3.3v so essential to include a voltage divider to reduce any voltage greater than that OR use an opto-isolator which enables differing voltages either side.

I am hoping to get mine running this coming week. At the moment I have everything assembled on a test panel, at home, and am using an Arduino Nano to simulate wind transducer input, but will be using actual GPS, actual Depth transducer input, multiplexing all together and outputting to (hopefully) both N2000 and N183

Thanks SF, done the adding the board bit, hence I can now compile and use the board fine, my AutoAnchor and my old analogue rudder sensor to NMEA0183 work fine!
The 3.3V will bite me at some point though...
Still think that the MEGA would be an easier platform to work with a CANBUS shield as it seems that I've not ordered MCP2562 as I thought. Care to point the shop you ordered yours, may as well get one of them as well as well as a Mega to do some more testing on a working platform.
Once I figure out which pins_arduino.h I'm currently using and find a Due pins_arduino.h I'll be happy. BTW, which one are you using on your sketch?

cheers

V.
 

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,427
Location
Hopefully somewhere warm
Visit site
But, you are smart enough to own a boat with switches, fuses / breakers & "real" wires, that you can trace & repair underway

request: This thread is interesting to some and very specific, if people would like to discuss the merits of technology could they please not dilute this thread but maybe start another one?

ta :cool:
 

skyflyer

Active member
Joined
26 Jan 2011
Messages
1,433
Location
Worcester, UK
Visit site
bought my MCP2562 off eBay - £2.45 here

I'm still struggling getting everything lashed together. Having previously managed to get RS232/TTL working it seems to be playing up tonight!

Until i get everything going IN to the Due in correct voltage and logic, I can't check whether anything (sensible) is being sent to canbus pins. Once i check that I'll let you know what libraries worked. AT moment the sketch (untested fully) has
#include <TinyGPS.h>
#include <Arduino.h>
#include <N2kMsg.h>
#include <NMEA2000.h>
#include <N2kMessages.h>

I'm thinking of changing to TinyGPS++ as it seems better but that means changing sketch again!

If you delve into the above libraries you will see that they call other libraries too
eg

Tiny GPS library calls:-
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include <stdlib.h>

N2KMessages calls for #include <N2kMsg.h>
NMEA2000.h calls for #include <N2kCANMsg.h>
and so on.

I guess you know, do you, that when the sketch compiles it only uses the parts of libraries that it needs to run the sketch so there's no harm in including stuff you don't need, other than confusion!

Back to my original posted question. I still can't work out whether i will need the due_can.h library or whether this is bypassed by the other libraries!

I know that the Actisense NMEA readrer software will correctly read the Due output sent to it down the USB cable, but I haven't worked out whether separate coding is needed to send the same data to the can bus pins.

Need to spend some time looking at the examples I guess!
 

Beyondhelp

Member
Joined
1 May 2011
Messages
719
Location
Surrey
www.aboardmyboat.com
This is what I perceive as the major problem of the Arduino. It masks the underlying structure of the microcontroller in an attempt to simplify the interface, but in doing so makes it hard to do anything out of the ordinary. Most people use Arduino devices by copying code they find online.

Personally I use PIC Microcontrollers programmed in C, either on a development board or on a home-built one. The initial learning curve is steeper, but once you get the idea then the possibilities are limitless.

[Edit]

Latest project, Water Tank Gauge

I used to be like that. I did a ton of PIC projects in ASM. Some were used semi commercially, but the hardware abilities of the Atmel devices is really quite a lot better. No paging for one, better counters/timers etc. I've hardly used a pic since.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,077
Location
Volos-Athens
Visit site
Until i get everything going IN to the Due in correct voltage and logic, I can't check whether anything (sensible) is being sent to canbus pins. Once i check that I'll let you know what libraries worked. AT moment the sketch (untested fully) has
#include <TinyGPS.h>
#include <Arduino.h>
#include <N2kMsg.h>
#include <NMEA2000.h>
#include <N2kMessages.h>

I'm thinking of changing to TinyGPS++ as it seems better but that means changing sketch again!

If you delve into the above libraries you will see that they call other libraries too
eg

Tiny GPS library calls:-
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include <stdlib.h>

N2KMessages calls for #include <N2kMsg.h>
NMEA2000.h calls for #include <N2kCANMsg.h>
and so on.

I guess you know, do you, that when the sketch compiles it only uses the parts of libraries that it needs to run the sketch so there's no harm in including stuff you don't need, other than confusion!

Back to my original posted question. I still can't work out whether i will need the due_can.h library or whether this is bypassed by the other libraries!

I know that the Actisense NMEA readrer software will correctly read the Due output sent to it down the USB cable, but I haven't worked out whether separate coding is needed to send the same data to the can bus pins.

Need to spend some time looking at the examples I guess!

why the tinyGPS.h ???

I'm going by the book (what Timo includes in his NMEA2000-master) and trying the WindMonitor project with the dummy data he's using.
His libs are not that many it seems (assuming a due + the chip you have) but I got the MEGA set of libs and played around a bit with them.
Result is that I have the following in my sketch:

// Demo: NMEA2000 library. Send main wind data to the bus.

#define N2K_SOURCE 15

#include <Arduino.h>
#include <Time.h>
#include <N2kMsg.h>
#include <NMEA2000.h>
#include <N2kMessages.h>

//////////////
#include <SPI.h>
#include <mcp_can.h>
#include <NMEA2000_mcp.h>
#define N2k_SPI_CS_PIN 10 // Pin for SPI Can Select // SP.begin(10, HIGH);
tNMEA2000_mcp NMEA2000(N2k_SPI_CS_PIN);

pretty sure you need the due_can.h (or as you say not much to loose adding it!)

Still my problem is to figure out which of the various .h files are actually loaded when there is half a dozen of Different ones! in the installation directory structure.

And larger problem is finding a Due custom pins_arduino.h file, no luck no matter where I searched.

Have a look at the hardware/arduino/avr/variants/ folder structure you'll find pins_arduino.h files from 1KB (for the Uno and likes) to 13KB (for the MEGA). If you open the MEGA file, you'll see that pins are wrong for the due.
So my Q is HOW does the IDE know what pin does what on the Due which is different to all other hardware??? Where are the Due custom headers hidden and especially the pins_arduino.h which the Arduino.h calls?
I think you should also look into that unless you go the exact route Timo's done (presumably sucessfully)


cheers

V.

PS. Will be picking up a MEGA on Thursday so next w/e should be testing with that as wel (unless I get my Due working by Wednesday that is...)
 
Top