Arduino Forum

Development => Other Hardware Development => Topic started by: svDeepPlaya on Feb 03, 2011, 12:05 am

Title: NMEA 2000 Shield
Post by: svDeepPlaya on Feb 03, 2011, 12:05 am
NMEA 2000 is a closed CAN-BUS standard for marine electronics. It would be awesome to have a shield that can accept the standard NMEA 2000 or that has a screw down terminal to accept bare wires.

NMEA 2000 supplies both power and data in it's cable. Not sure if it's adequate to power the ardunio.
http://en.wikipedia.org/wiki/NMEA_2000

If someone out there can handle the hardware and board side of things, I could help do the research.

Thanks,
-p
Title: Re: NMEA 2000 Shield
Post by: estratos on Feb 03, 2011, 11:17 am
Hi,

Building a CAN shield for the Arduino is quite simple. You just need a SPI-based CAN controller (ex: MCP2515) and a CAN interface (ex: MCP2551). The N2K bus typically provides 12VDC so you will need a regulator in order to power the arduino and the shield, and some kind of optical isolation between CAN interface and CAN controller if you want to stay clean. This is just for the physical side of the engine. Then you'll need to implement all the N2K protocol into the Arduino, but remember the following:

1. NMEA 2000 is a proprietary protocol. You'll surely need to purchase the specification from the NMEA association (several $1000's if I remember well).
2. If you want to certify the product, you'll need to pay for a N2K ID to the NMEA association and later you'll need to pay for the certification process.

I've worked with NMEA 2000 in the past so feel free to drop more questions if you need.

Daniel.
Title: Re: NMEA 2000 Shield
Post by: svDeepPlaya on Feb 07, 2011, 08:01 am
Thanks for the tips!

I hear you on the NMEA 2000 proprietary thing, but many are reverse engineering it... so I'm guessing it's not too difficult.

-p
Title: Re: NMEA 2000 Shield
Post by: estratos on Feb 17, 2011, 04:34 pm
Depending on the amount of N2K nodes available on the bus and their outgoing traffic load (some N2K devices are programmed to drop CAN messages every 100 ms), you could find that your Arduino-based node is not capable to accept all the traffic load without loosing packets so If you're thinking in using the Arduino as a kind of PC gateway this could be an issue. For end-device applications the AVR should be fine.
Title: Re: NMEA 2000 Shield
Post by: rjason on Oct 04, 2011, 04:13 pm
Hello,

Did you ever get anywhere with NMEA 2k -> Arduino? I'm considering the CAN shield to start playing with it.. don't want to recreate the wheel if you've made progress.

Thanks,
Jason
Title: Re: NMEA 2000 Shield
Post by: svDeepPlaya on Oct 04, 2011, 07:54 pm
I've not heard anything more about anyone working on this...
Title: Re: NMEA 2000 Shield
Post by: terryking228 on Oct 07, 2011, 03:24 pm
I just saw several NMEA2000 installations yesterday at the Genoa, Italy Boat Show. Immense. Many 100 foot yachts.  All NMEA2000 setups were on carpeted booths and high-end graphics.

The only DIY that crowd seemed to do was mixing drinks  :smiley-mr-green:

If anyone gets into NMEA-Anything start a thread on the forum... I've done a little.
Title: Re: NMEA 2000 Shield
Post by: androrossi on Jul 23, 2012, 02:03 pm
Hi all,

I want to send data over NMEA 2000 bus using Arduino UNO + Sparkfun Can-Bus (http://www.sparkfun.com/products/10039).

I have some questions on NMEA 2000:

1) Is correct to use that Can-Bus board to send data??? The structure of can bus message is the same of NMEA2000 message???
2) Is there any library that I can use???

Any suggestion on NMEA 2000 would be appreciated.

Thanks a lot!

:D
Title: Re: NMEA 2000 Shield
Post by: estratos on Jul 23, 2012, 04:23 pm

1) Is correct to use that Can-Bus board to send data??? The structure of can bus message is the same of NMEA2000 message???


Yes, you should be able to connect an Arduino to a CAN bus through this board. However, bear in mind the actual traffic load in the bus and the limited computing power of an Arduino. If you just want to develop a "sender" application it's should be OK.

Quote

2) Is there any library that I can use???


No free or open source library if I remember well. Working with NMEA2000 typically requires you to buy their specs.

Hope this helps,

Daniel.
Title: Re: NMEA 2000 Shield
Post by: androrossi on Jul 23, 2012, 08:50 pm
Thanks a lot Daniel.

I just want to develop a Sender application on Arduino.

I have another question:
is the structure of CanBus messages (2.0b) the same of Nmea2000 messages???

:D
Title: Re: NMEA 2000 Shield
Post by: estratos on Jul 23, 2012, 11:43 pm
Yes, NMEA2000 sits on top of CAN (extended address schema).
Title: Re: NMEA 2000 Shield
Post by: androrossi on Jul 25, 2012, 02:09 pm
Thanks a lot Daniel.

Is the message format for NMEA2000 this http://www.can-cia.org/index.php?id=496 ???
But it is bit different from CAN (2.0B) message format http://it.wikipedia.org/wiki/Controller_Area_Network#Formato_dell.27Extended_frame .

I'm wrong???

:D
Title: Re: NMEA 2000 Shield
Post by: estratos on Jul 25, 2012, 03:36 pm
ID A + ID B makes 29 bits. Yes, NMEA2000 is somehow a subclass of J1939 and inherits some PGN's from it in fact.
Title: Re: NMEA 2000 Shield
Post by: androrossi on Jul 29, 2012, 07:01 pm
Hi Daniel,

I found this forum http://www.mikrocontroller.net/topic/143234 and on this forum I found this library http://www.mikrocontroller.net/attachment/53861/NMEA2000ToNMEA183.rar .

I think it is what I need...

Can you help me with it?


Thanks a lot.

:)
Title: Re: NMEA 2000 Shield
Post by: dpharris on Jul 29, 2012, 07:15 pm
What do you need help with exactly?  My boat has a Volvo engine that sends their variant of this -- would be nice to interface to it. 

David
Title: Re: NMEA 2000 Shield
Post by: androrossi on Jul 30, 2012, 02:10 pm
Hello David,

Did you already use that library ( http://www.mikrocontroller.net/attachment/53861/NMEA2000ToNMEA183.rar )?
If yes, what hardware are you using? I have an Arduino UNO + Sparkfun Can-Bus ( http://www.sparkfun.com/products/10039 ).
I want to send some data over NMEA2000 bus to all node (broadcast).
I'd like to have a code example to send data using that library (if possible) or a brief guide to using the library.

Thanks a lot

:)
Title: Re: NMEA 2000 Shield
Post by: skyjumper on Aug 07, 2012, 07:54 am
I also have an N2K project I need to work on, but the expense of the protocol and certification is holding me up. Have you had any luck so far?
Title: Re: NMEA 2000 Shield
Post by: southern_cross on Oct 08, 2012, 08:45 pm
I have just started with embedded programming but been writing enterprise software for many years.

I have just pulled together a base NMEA 2000 / J1939 protocol stack. Currently I have support for a limited number of PGNs but I do have  support for single and fast frame NMEA2000 messages. The current project is to create NMEA 2000 transducer that will read analog engine data and broadcast PGNs 127488 (engine Rapid), 127489 (engine dynamic), 127505 (fuel level). The protocol stack is built to quick add additional PGNs with minimal amount of code.

Also I'm finishing up support for address claim and other NMEA 2000 group functions. If you are interested in working with me on adding additional capabilities and functions let me know. The current implementation runs on Arduino Uno with Sparkfun CAN-bus that uses MCP2515 CAN controller.

Title: Re: NMEA 2000 Shield
Post by: JayEmell on Oct 15, 2012, 12:19 pm
Hi, @southern_cross: I'm most interested in your work. Myself looking at the possibilities to use Arduino + shield to prototype a marine monitoring interface. Basically I would want to monitor and convert to NMEA2000 the engine data you mention plus some additional ones, like PGN 127508 - Battery Status. Possibly also some environmental data and in future also read and parse the AIS PGNs. I've previously only been working in the NMEA0183 domain though now believe that the transition to 2000 is inevitable. If you are willing to share your progress and also specify how you would want to co-operate I'd be very happy to join.
Title: Re: NMEA 2000 Shield
Post by: scruzin on Dec 04, 2012, 08:33 am
Hi, I'm new to this forum.  Just wondering if there has been anything more on the subject of interfacing Arduino and NMEA2000?
Title: Re: NMEA 2000 Shield
Post by: scruzin on Dec 04, 2012, 08:50 am
BTW, there is an open-source NMEA 2000 decoder project over at https://github.com/canboat that looks useful.
Title: Re: NMEA 2000 Shield
Post by: coryjfowler on Jan 29, 2014, 02:15 am
I've just spent the weekend decoding a NMEA 2000 GPS sensor.  Garmin's manual specified the PGNs the unit transmits and accepts but no detail on any of the payload.  I've managed to come across documents which have been helpful, but whats been most helpful is Maretron's product manual.  They get into detail, at least with their GPS sensor, almost as heavily as most NMEA0183 devices I've had the pleasure to use.  Only problem is, I need to figure out how to configure my Garmin sensor since differential corrections are disabled be default...  I've been talking with a Garmin representative about the lack of technical documentation and am waiting for a follow-up.

When it comes to standards, the manufacture might be the entity who purchases the standard, but we, the customer, are actually paying for it. 

http://www.nmea.org/Assets/july%202010%20nmea2000_v1-301_app_b_pgn_field_list.pdf

I've been active over at Seeed studio's forums.  I've been actively developing and ironing out the MCP2515 library.  I would recommend checking out my github if you end up using the MCP2515 with an Arduino.
Title: Re: NMEA 2000 Shield
Post by: allen652 on Feb 10, 2014, 11:22 pm
Cory would you be able to provide an example of writing a broadcast of engine data PGN 127489 using your library?

I am working on receiving these values from my boat's computer (delphi ecm MEFI3) and I would now like to have them appear on my NMEA 2000 network.

I'll be releasing my full project's source code and hardware when completed (for now: by request).
Title: Re: NMEA 2000 Shield
Post by: allen652 on Mar 05, 2014, 04:21 am
Nevermind Cory.

I have successfully broadcasted engine data (PGN 127488 + PGN 127489) to my raymarine MFD.
Title: Re: NMEA 2000 Shield
Post by: Fishstretcher on Mar 21, 2014, 02:22 am
I am very interested in doing just this. If you are willing to share what you have done, I would very much appreciate it. Not sure if if want PGN 127489 or 130311 for my task. There doesn't seem to be an appropriate PGN for engine vacuum (not boost).

Thanks!


Nevermind Cory.

I have successfully broadcasted engine data (PGN 127488 + PGN 127489) to my raymarine MFD.
Title: Re: NMEA 2000 Shield
Post by: allen652 on Mar 22, 2014, 01:13 pm
I'd be happy to help. PM sent.
Title: Re: NMEA 2000 Shield
Post by: Fishstretcher on Mar 22, 2014, 03:40 pm
I replied. Thanks very much! I don't have much to offer in kind, other than a parts list and schematic for what I plan to do with it.
Title: Re: NMEA 2000 Shield
Post by: FPeter on May 11, 2014, 04:44 am

Nevermind Cory.

I have successfully broadcasted engine data (PGN 127488 + PGN 127489) to my raymarine MFD.

Hello Allen!

How did You manage to broadcast PGN 127489? It isnt covered by standard or extended CAN formats due to more than 8 databyte (=26) in it - I found that its only supported by CAN FD devices - MCP2515, AT90CAN128 family and all PICs are supports only the 8 databyte mode... Im really interested in it, can You please share Your findings?

Best regards,
Peter
Title: Re: NMEA 2000 Shield
Post by: coryjfowler on Jun 03, 2014, 06:52 am
The way more than 8 data bytes is sent is a little confusing.  They send it 7 bytes at a time with the first byte of every message incrementing by 1, which is called the sequence identifier.  So to send more than 8 data bytes, you would essentially be sending multiple messages, each having the sequence identifier one greater than the previous.  Three such messages would give you 21 bytes and four would give you 28.  I think the simplest way to do this would be with a 'for' loop, putting the data bytes in an array, using the the loop count variable as the sequence ID, and multiplying the loop variable by seven for the offset needed by the array.

Sorry, its been a while since I've been around and active.  I've been busy with life things and not had any time for my toys.
Title: Re: NMEA 2000 Shield
Post by: JayEmell on Jul 09, 2014, 12:53 pm
@allen652:
I'm very impressed you managed to generate engine data on NMEA 2000 so the Raytheon MFD could display it. Is there a way you could share your results or can I approach you via a PM? /Jay
Title: Re: NMEA 2000 Shield
Post by: hobi on Aug 29, 2014, 06:46 pm
@allen652: I also look to broadcast information to a Triton T41 MFD.

I have been crawling on the web to find out some raw binary file, that I could use to check my code but no luck.
Therefore, what I have is the NMEA decoder ( Good that this was made open, really a huge piece of work)  that will help me to understand what the Triton sends out initially when powered up, but I will have to reverse the decoder, and assemble some PGNs ( like boat COG , wind direction) and send that to the Triton.

It would be of great help if you could accept to share the piece of SW you did to boradcast PGNs... Please.

What I am concerned about is the address claim, and also device capabilities / ISO aCK stuff.

Thanks in advance.

Title: Re: NMEA 2000 Shield
Post by: jpjcb66 on Oct 09, 2014, 12:36 pm
Hello everyone,
I have trouble with PGN 127489 + MFDe7 Raymarine and I have not response from "allen652" .
Can not display engine temperature water.
Can someone please help me?
thank you
jp
(http://jp-jacobee.fr/BATEAU/MFDe7_1014.png)
Title: Re: NMEA 2000 Shield
Post by: allen652 on Oct 09, 2014, 04:32 pm
I am using an arduino MEGA and the MCP2515 library as mentioned and worked on by coryjfowler https://github.com/coryjfowler/MCP2515_lib (https://github.com/coryjfowler/MCP2515_lib).

I built my own shield for a few dollars by purchasing the components from digikey.com (http://digikey.com). The design is based on seeedstudio's canbus http://www.seeedstudio.com/wiki/images/7/78/CAN-BUS_Shield_v0.9b.pdf (http://www.seeedstudio.com/wiki/images/7/78/CAN-BUS_Shield_v0.9b.pdf).

IC CAN Transceiver: MCP2551-I/P-ND
IC CAN Controller: MCP2515-I/P-ND
16 MHZ Crystal: XC1748-ND
Resistors: 10kohm & 4.7kohm
Capacitors: (2) 22pf & (2) 100nf

I am using non-certified NMEA2000 cabling products that I had manufactured for my current project. I have several available for sale below if interested. See images.
2 meter cable (Male to Female) - $7.5 each
T adapter - $7 each
Male rear panel mount connector - $5 each

I'll put some sample code in my next post.
Title: Re: NMEA 2000 Shield
Post by: allen652 on Oct 09, 2014, 04:53 pm
Code: [Select]

#include <mcp_can.h>
#include <SPI.h>

MCP_CAN CAN0(53);                                      // Set CS to pin 53
//MCP_CAN CAN0(2); //for my new prototype shield
unsigned char stmp[8] = {0, 0xA0, 0x41, 0, 0, 0, 0, 0};
unsigned char extpgn[26] = {0, 0xA0, 0x41, 0, 0, 0, 0, 0};
void setup(){
  Serial.begin(115200);
  // init can bus, baudrate: 250k
  if(CAN0.begin(CAN_250KBPS) == CAN_OK) Serial.print("can init ok!!\r\n");
  else Serial.print("Can init fail!!\r\n");
  //testPGN127489();
  //transmitPGN127489(0,55.5,164,171,13.54,15.8,221,11.2,32.1,38,44,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  testRPM();
}

void loop(){ 
  //PGN 127488 binary 011111001000000000
  //for id try 110 + above + 00000000 = 11001111100100000000000000000 = hex 19F20000
  //highest priority = 000 try 00001111100100000000000000000 = hex 1F20000 = dec 32636928
 
  //PGN 127489 binary 011111001000000001
  //for id try 00001111100100000000100000000 = hex 1F20100 = dec 32637184
 
  // send data:  id = 0x00, extended frame, data len = 8, stmp: data buf
  CAN0.sendMsgBuf(32636928L, 1, 8, stmp); 
 
  //testPGN127489();
  //transmitPGN127489(0,55.5,164,171,13.54,15.8,221,11.2,32.1,38,44,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);  //with checkEngine flag set to true
  transmitPGN127489(0,55.5,164,171,13.54,15.8,221,11.2,32.1,38,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);  //with checkEngine flag set to false
 
  delay(1000);                       
}
void testPGN127489(){
  //if an engine parameter is not available, set it to 255
  unsigned char extpgn[26] = {0, 208, 14, 170, 13, 151, 136, 236, 4, 37, 2, 112, 207, 11, 0, 255, 255, 255, 255, 1, 0, 0, 0, 0, 255, 255};  //decimal values
  unsigned char temp[8] = {0,0,0,0,0,0,0,0};
  //
 
  int cur=0;
  for(int i = 0; i<=3; i++){
      temp[0] = i; //frame counter
      if (i==0){
          temp[1] = 26; //total bytes in fast packet
          //send the first 6 bytes
          for(int j = 2; j<8; j++){ 
               temp[j]=extpgn[cur];
               cur++;   
           }
      } else{
           for(int j = 1; j<8; j++){ 
               temp[j]=255;
           }
           //send the next 7 data bytes
           for(int j = 1; j<8; j++){ 
               temp[j]=extpgn[cur];
               cur++;   
           }
      }
      CAN0.sendMsgBuf(32637184L, 1, 8, temp); 
      delay(1);
  }
}
void testRPM(){
  unsigned char stmp[8] = {0, 0xA0, 0x41, 0, 0, 0, 0, 0};
  int rpm;
  for(int i = 0; i<=4200; i=i+100){
      rpm=(i*4);
      stmp[2]=rpm/256;
      stmp[1]=rpm-(stmp[2]*256);
      CAN0.sendMsgBuf(32636928L, 1, 8, stmp); 
      delay(100);
  }
}
void transmitPGN127489(int engineInstance, float engineOilPress, float engineOilTemp, float engineCoolantTemp, float battery,
  float fuelRate, float engineHours, float engineCoolantPress, float engineFuelPress, float engineLoad, float engineTorque, bool flagCheckEngine,
  bool flagOverTemp, bool flagLowOilPress, bool flagLowOilLevel, bool flagLowFuelPress, bool flagLowSystemVoltage, bool flagLowCoolantLevel,
  bool flagWaterFlow, bool flagWaterInFuel, bool flagChargeIndicator, bool flagPreheatIndicator, bool flagHighBoostPress, bool flagRevLimitExceeded,
  bool flagEgrSystem, bool flagTPS, bool flagEmergencyStopMode, bool flagWarning1, bool flagWarning2, bool flagPowerReduction,
  bool flagMaintenanceNeeded, bool flagEngineCommError, bool flagSubThrottle, bool flagNeutralStartProtect, bool flagEngineShuttingDown){
  //if an engine parameter is not available, set it to 255
  unsigned int extpgn[26]; // {0, 208, 14, 170, 13, 151, 136, 236, 4, 37, 2, 112, 207, 11, 0, 255, 255, 255, 255, 1, 0, 0, 0, 0, 255, 255};  //decimal values
  unsigned char temp[8]; // {0,0,0,0,0,0,0,0};
  float v;
  extpgn[0]=engineInstance;
 
  v=engineOilPress;
  v=v*68.94757;
  //extpgn[2]=v/256;
  //extpgn[1]=v-(extpgn[2]*256);
  extpgn[2]=highByte((int) v);
  extpgn[1]=lowByte((int) v);  //this works well. I should change the code below to use this format.
 
  v=engineOilTemp;
  v=(((v-32)*5/9)+273)*100;
  extpgn[4]=v/256;
  extpgn[3]=v-(extpgn[4]*256);
 
  v=engineCoolantTemp;
  v=(((v-32)*5/9)+273)*100;
  extpgn[6]=v/256;
  extpgn[5]=v-(extpgn[6]*256);
 
  v=battery;
  v=v*100;
  extpgn[8]=v/256;
  extpgn[7]=v-(extpgn[8]*256);
 
  v=fuelRate;
  v=v*37.8541;
  extpgn[10]=v/256;
  extpgn[9]=v-(extpgn[10]*256);
 
  v=engineHours;
  v=v*3600;
  //extpgn[14]=v/16777216;
  //extpgn[13]=(v-(extpgn[14]*16777216))/65536;
  //extpgn[12]=(v-((extpgn[14]*16777216)+(extpgn[13]*65536)))/256;
  //extpgn[11]=v-((extpgn[14]*16777216)+(extpgn[13]*65536)+(extpgn[12]*256));
  int tempVar = (long) v >> 16;
  extpgn[14]=highByte(tempVar);
  extpgn[13]=lowByte(tempVar);
  tempVar = (long) v & 0xFFFF;
  extpgn[12]=highByte(tempVar);
  extpgn[11]=lowByte(tempVar);
 
  v=engineCoolantPress;
  v=v*68.94757;
  extpgn[16]=v/256;
  extpgn[15]=v-(extpgn[16]*256);
 
  v=engineFuelPress;
  v=v*689.4757;
  extpgn[18]=v/256;
  extpgn[17]=v-(extpgn[18]*256);
 
  extpgn[19] = 255; //nmea2000 reserved byte
 
  int engineStatus1P1 = B00000000;
  int engineStatus1P2 = B00000000;
  int engineStatus2 = B00000000;
  if (flagCheckEngine) engineStatus1P1 |= B00000001;
  if (flagOverTemp) engineStatus1P1 |= B00000010;
  if (flagLowOilPress) engineStatus1P1 |= B00000100;
  if (flagLowOilLevel) engineStatus1P1 |= B00001000;
  if (flagLowFuelPress) engineStatus1P1 |= B00010000;
  if (flagLowSystemVoltage) engineStatus1P1 |= B00100000;
  if (flagLowCoolantLevel) engineStatus1P1 |= B01000000;
  if (flagWaterFlow) engineStatus1P1 |= B10000000;
 
  if (flagWaterInFuel) engineStatus1P2 |= B00000001;
  if (flagChargeIndicator) engineStatus1P2 |= B00000010;
  if (flagPreheatIndicator) engineStatus1P2 |= B00000100;
  if (flagHighBoostPress) engineStatus1P2 |= B00001000;
  if (flagRevLimitExceeded) engineStatus1P2 |= B00010000;
  if (flagEgrSystem) engineStatus1P2 |= B00100000;
  if (flagTPS) engineStatus1P2 |= B01000000;
  if (flagEmergencyStopMode) engineStatus1P2 |= B10000000;
 
  if (flagWarning1) engineStatus2 |= B00000001;
  if (flagWarning2) engineStatus2 |= B00000010;
  if (flagPowerReduction) engineStatus2 |= B00000100;
  if (flagMaintenanceNeeded) engineStatus2 |= B00001000;
  if (flagEngineCommError) engineStatus2 |= B00010000;
  if (flagSubThrottle) engineStatus2 |= B00100000;
  if (flagNeutralStartProtect) engineStatus2 |= B01000000;
  if (flagEngineShuttingDown) engineStatus2 |= B10000000;
 
  extpgn[20]=engineStatus1P1;
  extpgn[21]=engineStatus1P2;
  extpgn[22]=engineStatus2;
  extpgn[23]=0;
 
  extpgn[24]=engineLoad;
 
  extpgn[25]=engineTorque;
 
  int cur=0;
  for(int i = 0; i<=3; i++){
      temp[0] = i; //frame counter
      if (i==0){
          temp[1] = 26; //total bytes in fast packet
          //send the first 6 bytes
          for(int j = 2; j<8; j++){ 
               temp[j]=extpgn[cur];
               cur++;   
           }
      } else{
           for(int j = 1; j<8; j++){ 
               temp[j]=255;
           }
           //send the next 7 data bytes
           for(int j = 1; j<8; j++){ 
               temp[j]=extpgn[cur];
               cur++;   
           }
      }
      CAN0.sendMsgBuf(32637184L, 1, 8, temp); 
      delay(1);
  }
  //for debugging
  /*
  Serial.println();
  Serial.print("Data = ");
  for(int j = 0; j<26; j++){ 
    if (j<25){
      Serial.print(extpgn[j]);
      Serial.print(", ");
    } else {
      Serial.println(extpgn[j]);
    }
  }
  Serial.print("HexData = ");
  for(int j = 0; j<26; j++){ 
    if (j<25){
      Serial.print(extpgn[j],HEX);
      Serial.print(", ");
    } else {
      Serial.println(extpgn[j],HEX);
    }
  }
  */
}
Title: Re: NMEA 2000 Shield
Post by: jpjcb66 on Oct 09, 2014, 04:55 pm
Thank you for your reply.
Here is my current code for this part :

Code: [Select]
// ++++++++++++++++++++++++++++++++++++ Engine Parameters, Dynamic ++++++++++++++++++++++++++++++++++++
  updateRate = 500; // 2 * / s
  priorite = 5;
  PGN = 127489;  // Paramètres environnementaux bus NMEA 2000 (N2K)
  source = 35;   // Airmar = 35
  adresse = priorite * 67108864 + PGN * 256 + source;
  float tempwc =  95; //TWEng;  // Celsius  Engine Water Temp
  long tempwk =  100 * ( tempwc + 273.15 );
  long tempw1 = ( tempwk & 0b1111111100000000 ) >> 8;  // mise en forme format CAN 16bits
  long tempw2 =   tempwk & 0b0000000011111111;

  float PressEng = 200;  // Lecture capteur pression resolution = 8 bits pour essai.
  long PressEng_ = 20 * PressEng;
  long PressEng1 = ( PressEng_ & 0b1111111100000000 ) >> 8;  // mise en forme format CAN 16bits
  long PressEng2 =   PressEng_ & 0b0000000011111111;

  message.id = adresse;
  message.ide = 1;
  message.rtr = 0;
  message.dlc = 8;
  message.data[0] = 0;   //  SID
  message.data[1] = 0;   //  Engine instance  8bits    0=Single Engine
  message.data[2] = 0;   //  doit etre  à 0 pour lecture 2 octets plus bas. Oil press = 0 si 255
  message.data[3] = PressEng2; //PressEng2;   
  message.data[4] = PressEng1; //PressEng1;   //  Oil   Press huile 1=0,3  2=0,5  3=0,8  4=1b  28=7,2b
  message.data[5] = 255;   //  ????
  message.data[6] = tempw2;   //  Temperature eau moteur - 16 bits (sonde DS18B20)
  message.data[7] = tempw1;   //  Temperature eau
/* Serial.print("TEMPERATURE EAU MOTEUR : ");
Serial.print(tempw2);  Serial.print(" - ");
Serial.println(tempw1);
*/
  SendPaquet();

  message.data[1] = 1;  // 1 paquet supplémentaire
  message.data[2] = 0;  // Alternateur
  message.data[3] = 0;  // Alt
  message.data[4] = 0;  // Fuel rate
  message.data[5] = 0;  // Fuel rate
  message.data[6] = 1;  // Hour
  message.data[7] = 0;  // Hour
  message.data[8] = 0;  // Hour

  SendPaquet();

  message.data[1] = 2;  // 1 paquet supplémentaire
  message.data[2] = 4;  // Hour
  message.data[3] = 0;  // Coolant press
  message.data[4] = 0;  // Coolant press
  message.data[5] = 0;  // Fuel press
  message.data[6] = 0;  // Fuel press
  message.data[7] = 0;  // reserved
  message.data[8] = 0;  // Discrete Status 1

  SendPaquet();

  message.data[1] = 3;  // 1 paquet supplémentaire
  message.data[2] = 0;  // Discrete Status 1
  message.data[3] = 0;  // Discrete Status 2
  message.data[4] = 0;  // Discrete Status 2
  message.data[5] = 0;  // Percent Engine Load
  message.data[6] = 0;  // Percent Engine Torque

  SendPaquet();

  delay(updateRate);
Title: Re: NMEA 2000 Shield
Post by: spicetraders on Oct 09, 2014, 05:13 pm


I am using non-certified NMEA2000 cabling products that I had manufactured for my current project. I have several available for sale below if interested. See images.
2 meter cable (Male to Female) - $7.5 each
T adapter - $7 each
Male rear panel mount connector - $5 each


I have found that NEMA2000 is hardware wise follows the older DEVICENET so many parts interchange with out issues. 
Title: Re: NMEA 2000 Shield
Post by: jpjcb66 on Oct 09, 2014, 05:14 pm
Compliments, Beautiful Code.
But I have to try to translate Arduino uno.

I did not see how you code:
address = priority * 67108864 * 256 + PGN + source;
Title: Re: NMEA 2000 Shield
Post by: allen652 on Oct 09, 2014, 06:04 pm
I should probably comment my code better (and more often).

jpjcb66: The first 3 bits of the id is the priority, the next 18 bits are the PGN, and the last 8 bits are the source address.
See the comments in my code above in void loop().

priority = 000
PGN = 011111001000000000
source = 00000000

00001111100100000000000000000 binary = 32636928 decimal

Code: [Select]
// send data:  id , extended frame, data length = 8, data buffer
  CAN0.sendMsgBuf(32636928L, 1, 8, stmp);
Title: Re: NMEA 2000 Shield
Post by: jpjcb66 on Oct 09, 2014, 06:45 pm
@allen652

I understand !
You put "source" = 0x0
Code Airmar = 0x25 (35dec).
There exists an array of manufacturer codes ?
For example what is the Volvo Penta code ?


Your code is perfect, thank you infinitely.
jp
Title: Re: NMEA 2000 Shield
Post by: farabin on Jan 21, 2015, 07:36 pm
Hi friends
I want to read 2 periodic data from maretron WSO100 module. PGN #130306 for wind data & #130310 for environmental parameters. As I read this PGNs send periodically every 100 ms &  500 ms...
I use LPC1768 controller and do this steps to read wind data:
1) set CAN Controller baud rate to 250 kbit/sec
2) set ID to 130306(0x01FD02) in extended format
3) read can receive buff...
But I don't receive any data on bus!!!
what should I do??? what's wrong???
please help me...
Thanks a lot
Title: Re: NMEA 2000 Shield
Post by: Prof67 on Feb 20, 2015, 01:41 am
Hi,

Want to read NEMA2000 stream from a Garmin Depth founder with a Arduino Due.

Just this device on NEMA network.

Did someone have code reference ?

  :D
Title: Re: NMEA 2000 Shield
Post by: elgui on Mar 30, 2015, 08:57 pm
Hi,

I'm about to buy a "triducer", the Airmar DST800. It's going to send depth/temp/speed via NMEA2000.
As a java programmer with zero experience with Arduinos (but lot of time to spend on it), do you think I have a chance, using existing resources, to decode these informations and display it on a e-ink display shield ?
I don't absolutely need a ready-to-use solution, and a simple "yes you can" would be much appreciated to preserve my motivation ^^
Of course, I'll be back later with more accurate questions ;)
Title: Re: NMEA 2000 Shield
Post by: CrossRoads on Mar 30, 2015, 09:04 pm
Yes you can.
Only challenge is parsing the NMEA data stream to pick out the pertinent info.
And then sorting out the e-ink interface. Probably just another serial data stream?
Title: Re: NMEA 2000 Shield
Post by: elgui on Apr 01, 2015, 01:21 am
Thank you CrossRoads,
I have an idea about the parsing challenge, and I guess I can use some existing code that parse GPS datas and adapt it. The e-ink display does not scares me that much, because if I don't succeed, I still have other display options.
I'll put my code somewhere on this forum if I reach my goal =)
See you !
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 31, 2015, 10:08 am
Hi All,

I have been trying to find NMEA2000 shield without success, so I wrote my own. It can act as listener only and forward data to PC in Actisense or clear text format. Or it can act as Termperature sensor node with automatic address claiming. Or as I am making it as a NMEA0183 combiner/ NMEA200 converter and sensor node.

Library works with Mega board with MCP2551 chip or with Due board with its internal CAN controller.

Anybody interested?
Title: Re: NMEA 2000 Shield
Post by: rickbase1 on Aug 13, 2015, 09:41 pm
Great timing, I just signed up to this forum and started looking for a library today ! 

Please count me in. 

I am building a LiFePo4 alternator regulator and an active charge/monitor BMS and would love to have a full NMEA2k interface to connect my Maretron/Raymarine network.

Thanks,

Rick

Title: Re: NMEA 2000 Shield
Post by: FXVT on Aug 16, 2015, 11:24 pm
Bonjour

Here is the sketch I have written to display the battery voltage on my boat.
It sends the PGN 127508 thru the NMEA 2000 network.
The voltage (Only one battery, Battery number 1= instance 0) can be read on:
- Raymarine A78 MFD
- B&G Triton


The Arduino+Shield (Seeedunio) pack is directly powered by the 12v supply

The voltage is read by the A0 pin through a voltage divider made with 2 resistors

It works well and seems to be reliable, but sometime the INT red led turns on solid. However it keeps on running, the network does'nt hang up.

Amicalement.
François-Xavier
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 17, 2015, 08:00 am
Hi,

You can find NMEA2000 library and samples on https://github.com/ttlappalainen. The best would be to use Arduino Due, since it needs only MCP2562 tranceiver for connecting to the bus. It also has 8 byte double for better calculations.

My own setup is running and it has also 3 NMEA0183 inputs for combiner and tranfer data to N2kBus. So with Arduino Due and 4 extra chips this replaces 4 devices: NMEA0183 combiner (e.g. Brookhouse), NME0183->N2k (Actisense), N2k->PC  (Actisense), MOB device.
Title: Re: NMEA 2000 Shield
Post by: FXVT on Aug 17, 2015, 08:47 pm
Bonjour,

Good job Timo.

I have not understood everything but it is very interesting.

Amicalement.
François
Title: Re: NMEA 2000 Shield
Post by: pogcarr on Sep 09, 2015, 05:13 pm
Timo,

Can you provide any pictures or other details of your hardware setup?  How you hooked everything together.  VERY interested!

Paul
Title: Re: NMEA 2000 Shield
Post by: thomasow on Sep 11, 2015, 06:17 pm
Hi All,

I have been trying to find NMEA2000 shield without success, so I wrote my own. It can act as listener only and forward data to PC in Actisense or clear text format. Or it can act as Termperature sensor node with automatic address claiming. Or as I am making it as a NMEA0183 combiner/ NMEA200 converter and sensor node.

Library works with Mega board with MCP2551 chip or with Due board with its internal CAN controller.

Anybody interested?
Timo,

Hello.  Wanted to let you know I have just posted up a very rough cut of a NMEA-2000 / Alternator regulator bridge based on your lib.  I made some extensions to include some additional PGNs - and once proofed out a bit will submit a pull back to your get-hub lib.

This bridge is intended to run on a Due, and takes the ASCII status strings from my Arduino based Alternator Regulator and send them out to the NMEA-2000 bus.  At this point is is rather unproven as I lack some additional hardware (specifically, the NEMA-2000 display side), am not settled on which PGNs should be broadcasted, and I am not totally sure I have extended your libs correctly  :o

Source, extended libs (draft form), as well as a bit more details here:
http://arduinoalternatorregulator.blogspot.com/2015/09/very-rough-nmea-2000-bridge-source.html (http://arduinoalternatorregulator.blogspot.com/2015/09/very-rough-nmea-2000-bridge-source.html)

Looking forward to perhaps getting this a bit more settled.


Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 25, 2015, 08:28 am
Hi PogCarr and thomasow,

I'll try to upgrade GitHub with pictures and extension as soon as possible. I have been a bit busy with othe project.

Timo
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 27, 2015, 08:41 am
Hi all,

Now there is upgraded version of NMEA2000 library and some drawings under Documents in https://github.com/ttlappalainen/NMEA2000
Title: Re: NMEA 2000 Shield
Post by: skyflyer on Nov 09, 2015, 03:23 pm
I have to laugh when I see some of your posts describing yourselves as 'beginners'. To me a lot of this is like a foreign language and you are experts compared to me!

Perhaps someone can help me if I describe where I am at and where I am trying to go

I have managed to set up an Arduino to create NMEA0183 sentences from analogue data, combine with NMEA0183 sentences from other instruments and transmit in NMEA0183 format.

I need to now translate that to NMEA2000 to feed a different network

From this thread I have managed to understand that I will need to buy or make a Canbus shield, to attach to the Arduino.  Also that I will need to download and include various Libraries.

What i do not understand, nor can I find any obvious reference, is what I then have to do to convert the data obtained via N0183 to N2000?

Where is this step? Is it proprietary? Is everyone having to do their own reverse engineering, or is this staring me in the face somewhere that I have missed?

Unfortunately my knowledge of electronics is zero. I can connect one terminal to another, I can solder, I can construct but I have no understanding at all of what is happening inside the device! I struggle with simple concepts like transmission speed, capacitors, diodes, transistors etc.

I' just want an idiots guide to try and get this working. It sounds like many of you have managed but I cannot make the jump from the sample sketches to the real thing.

For example if I have a simple wind sentence from NMEA0183

$WIMWV,059,R,5.04,N,A*0

How do I get that data or part of that data, broadcast to N2000?

Thanks if anyone can help
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Nov 09, 2015, 04:15 pm
Hi,

Well I am beginner with Arduino, but did my first digital telecope control system on 1980 with 2 A4 sized boards full of logic chips.

I prefer you buy a Arduino Due and MCP2562 chip for NMEA2000 tranceiver. Due is better for your task, since it has more power.

If you like to convert data from NMEA0183 to NMEA2000 you also need e.g. MAX3483 for NMEA0183 bus tranceiver. On Arduino Due you can have max. 3 MAX3483 and so 3 channels for NMEA0183.

I can then send you ready drawing for converter. If you get data to Arduino as in analog format, then you do not need MAX3483 tranceivers.

So now actually there are almost everything ready. I have to update NMEA2000 library, which now also have functions fo sending wind data. I have not done that yet, since other guy has developed wind data handling and I have not yet proved it ok.

On my library there is sample TemperatureMonitor, which does your task but with temperature. Post your contact to me, so I can guide you how to  continue.
Title: Re: NMEA 2000 Shield
Post by: skyflyer on Nov 09, 2015, 04:57 pm
thanks for that, its a good start; I am contactable at gc9876 (at) hotmail dot com

I should explain that I need some data in NMEA0183 format also (to feed to chart plotter) so it needs to be done in two steps, even if actually it would be possible to go straight from analogue to N2000.

My set up will require the combining (multiplexing) of N183 GPS, Wind and Depth sentences which is then both transmitted to N183 chart plotter and also converted to N2000 for autopilot.


Thanks again
GC
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Nov 09, 2015, 05:13 pm
You setup is rather same I have. So I'll contact directly to you.
Title: Re: NMEA 2000 Shield
Post by: mcnobby on Nov 13, 2015, 02:35 pm
I used to work for Simrad/Navico and worked on some of the earliest versions of NMEA2000, I even had a bit of a hand in some of the original PGNs !! Simrad/Navico adopted CAN@250kbps on thier Corus instrument system well before NMEA2k was published. We mainly used Philips devices (one of the earliest companies to embed CAN into their microcontrollers), then moved to Renesas devices.

Its come a long way

A tiny bit off-topic, but this is a very interesting venture :
https://www.kickstarter.com/projects/1689846268/ikommunicate-gateway-enabling-the-internet-of-thin (https://www.kickstarter.com/projects/1689846268/ikommunicate-gateway-enabling-the-internet-of-thin)
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Nov 14, 2015, 05:17 am
Hi,

I also know signal-K, but there is no MFD with support for that - at least I have not heard any. And with MFD I mean waterproof and sunlight readable display, which can be installed on steering pole. So the point for NMEA library is the way to provide tools to add e.g. temperature or tank sensors to existing bus. It also provides way to read data to PC.

Check also NMEA-Simulator (http://www.kave.fi/Apps/), which next version (coming withing few days) also offers way to simulate devices on N2k bus.
Title: Re: NMEA 2000 Shield
Post by: zyabba on Nov 23, 2015, 11:06 am
hi, Timolappalainen.
it is a great project ! I am trying to make my own wind sensor . the hardware is working fine. It send nmea 0183 mwv message to com port. now I am trying to connect it to pc-to n2k converter. I use arduino due with internal can and max 232cpe. I have sucsess to read depth data from n2k . and I see some data in actisense listener but cannot read it . I also see pcton2k in list of devises on my lowrance and garmin , but when I try to send some data from comport or nmea 0183 out of garmin Isee nothing ! I tyied different baud rate of ports , connected to native and programming ports of arduino ,used max 232cpe  and arduino serial port but fail ! I see led blinking when data comes from n2k and from nmea simulator but nohing in n2k . what is wrong in my setup ? is it possible to read actissence format ? thanks !
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Nov 23, 2015, 11:50 am
Hi,

I did not understood you setup.
- What is your pc-to-n2k converter
- Where do you have MAX232CPE? For CAN you should use CAN tranceivers
- What do you mean  "...see some data in actisense listener"? Are you using my Arduino example ActisenseListener with Actisense "NMEA Reader" PC sw?

There is new Arduino example ActisenseListenerSender, which can read and send data. With that you:
- Connect Arduino CAN to N2k bus.
- Open Actisense "NMEA Reader" to the programming port.
- Open "NMEA Simulator" to native port.

Now if you enable PGN:s for sending on "NMEA Simulator", you should see them on "NMEA Reader" and also simulated devices on your Garmin or Lowrance. Note that on "NMEA Simulator" you must set device source addresses different than devices you have on N2k bus. "NMEA Simulator" can not yet do Address Claiming.

If you want to send wind data to the N2k bus, take first the example WindMonitor. There you need only to write your code for functions double ReadWindAngle() and ReadWindSpeed() and it will send wind data to the bus. Not that to write N2k, you do not write any NMEA0183 messages to com port. You have to create N2k message and send it as in example void SendN2kWind().

Download newest version of NMEA2000 library and "NMEA Simulator". I have done several fixes within few days.
Title: Re: NMEA 2000 Shield
Post by: zyabba on Nov 24, 2015, 08:17 am
my hardware is arduino due internal can and can tranceiver tja1050 .
max232cpe is used to connect arduinos serial with rs232 on laptop or garmin in some cases.
yes I am  using your Arduino example ActisenseListener with Actisense "NMEA Reader" .my last attempt was sucsessful.
I could read data from can bus ,see list of nmea2000 devises , but I did not see ActisenseListener in this list. but
your another example FromPCToN2k is shown .I have downloaded your new ActisenseListenerSender example and I will try it today.
I think I need to smoke a lot of manuals before I could create N2k message and send it to bus :)  . thank you for your answer .









Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Nov 24, 2015, 08:57 am
Hi,

Example ActisenseListener and ActisenseListenerSender are blind to N2k bus. If you instead take as I mentined example WindMonitor, it will be shown on the bus. If on WindMonitor you uncomment line
  // Serial.begin(115200);
and change line:
NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly,23);
to
NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode,23);

Your wind monitor will act as N2k node, but also lintens and forwards all traffic to the Serial.

I have spent too much time with N2k, so I hope you do not need to. For that there are several ready N2k messages to create for sending with library. You will find these on file N2kMessages.h. If you need some new message (PGN) to be send, contact me so I'll add it to the library for available to everyone. I take few minutes for me to add new PGN, while you may need to dig internet for hours.

Note that WindMonitor uses those predefined functions from N2kMessages.h within its function "void SendN2kWind() {...}

And if you like to visualize N2k data on PC or have webserver for them, check also OpenSkipper. The lates beta is on http://www.kave.fi/Apps The other way for visualizing is to use SignalK (http://signalk.org/)
Title: Re: NMEA 2000 Shield
Post by: zyabba on Nov 24, 2015, 05:51 pm
hello ,
windmonitor is working great ! I see speed and direction of the wind and WindMonitor is shown in device list (exept raymarine i70 but data is shown)
I also try it as ListenAndNode - the bus data is shown in Openskipper .the example "fromPCToN2k" is also seen in the bus .if I turn ListenAndNode I see bus trafic but I cannot send message to n2k even in NodeOnly .I try to send some n2k pgn using nmea simulator but no data is shown on mfd
(lowrance and raymarine) may be I am doing something wrong .I dont anderstand what . but it is a progress . next I wil try to connect wind sensors
to windmonitor . first I will connect potentiometer to analog if sucsess- digital out of sensors .It would be great to connect rudder sensor, so adding
rudder pgn would be great ! I hope this topic would progress !
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Nov 24, 2015, 08:30 pm
Hi,

Note that sending data from PC to N2k bus is not build in the library. It is an other module ActisenseReader. That has been used on both examples fromPCToN2k and ActisenseListenerSender. Note that on ActisenseListenerSender I have used Arduino programming port for data to PC and native port for data from PC to N2k bus. This is because I did not found the reason why stream get jammed, if I used same port for both directions. It worked for some time but on long period it always stopped and nothing went to any direction any more. Maybe there is explanation somewhere, but it was not critical for me at that time.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Nov 25, 2015, 08:49 am
Hi,

I updated NMEA Simulator with rudder PGN (see Tools-Options...-NMEA2000-"Engine, other") and function void SetN2kRudder(...) to N2kMessages module on NMEA2000 library.

Timo
Title: Re: NMEA 2000 Shield
Post by: zyabba on Nov 25, 2015, 10:55 am
thank you Timo ! I'll try. So I anderstand that if I have a compass in n2k bus , it is possible to calculate true wind direction (listenAndNode) Am I wright ? openskipper dont want to work when I plug n2k compass to the bus.I think it doesn't like high data refresh.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Nov 25, 2015, 11:34 am
Yes. Then you need tom make similar message handler as in example DataDisplay. I need to add heading parser function to N2kMessages module. Which PGN your compass is sending - PGN 127250? Which GPS compass you have?

I have 10Hz compass and lot of other data coming to OpenSkipper, so I do not think this is the problem with it. Other possibility is that some definition is wrong.
Title: Re: NMEA 2000 Shield
Post by: zyabba on Dec 02, 2015, 07:58 am
WoW ! It's working !
I connected magnetic encoder as5040 as wind direction sensor , IR couple from old mouse as wind speed sensor , potentiometer as rudder sensor. I have edded rudder to simple wind monitor .
Everything working great . now I am trying to edd tft lcd with beautifull graphics. Need some more time and alcohol to solve bugs , but already it is a greate step. thank you Timo!































































i
Title: Re: NMEA 2000 Shield
Post by: skyflyer on Dec 20, 2015, 09:24 pm
Another newbie question has arisen as my own project develops. The Due I am using to output the data, transmits the 0183 sentences down the serial port, but I guess this is RS232 protocol.

I believe NMEA0183 is TTL or at least different; at the moment my instrumentation will not read what the due is outputting.  How do I convert it, invert it, change it?

Thanks
Title: Re: NMEA 2000 Shield
Post by: virtuvas on Jan 14, 2016, 08:24 pm
Hi,

You can find NMEA2000 library and samples on https://github.com/ttlappalainen. The best would be to use Arduino Due, since it needs only MCP2562 tranceiver for connecting to the bus. It also has 8 byte double for better calculations.

My own setup is running and it has also 3 NMEA0183 inputs for combiner and tranfer data to N2kBus. So with Arduino Due and 4 extra chips this replaces 4 devices: NMEA0183 combiner (e.g. Brookhouse), NME0183->N2k (Actisense), N2k->PC  (Actisense), MOB device.
hello,

my first post here, but have being working on arduino Uno -> NMEA0183 and have a few sketches working for specific things already posted in the YBW forum. One is for rudder angle (IIRSA) which I now have to convert to NMEA2000 (should be 127245) as my Garmin GMI10 doesn't support this sentence.

Have a few bits of kit, 3 Uno's relay/wifi/ethernet/Serial->TTL, etc shields but NOT a Due, nor a CAN BUS gate/shield.

Could you please recommend a setup that will work with minimum effort and debugging?
I'm ok with a soldering gun, but not particularly good in reading graphs (talking about building the CAN BUS interface in hardware using the MCP2562 tranceiver you mention).
Are there any readymade shields that would plug on the Due that will work with your code? Planning to order tonight so that I can get the N2K project moving using your notes and code.
I can see the CAN BUS Seeed  and the SparkFun one, are they any good?

thank you very much!

cheers

Vassilis
Title: Re: NMEA 2000 Shield
Post by: virtuvas on Jan 14, 2016, 08:29 pm
Another newbie question has arisen as my own project develops. The Due I am using to output the data, transmits the 0183 sentences down the serial port, but I guess this is RS232 protocol.

I believe NMEA0183 is TTL or at least different; at the moment my instrumentation will not read what the due is outputting.  How do I convert it, invert it, change it?

Thanks
hi there,
I know it's a month old question, just in case you haven't figured it out you need an RS232 - > TTL converter, a few on ebay for 1-2euro each.
In theory (haven't tried it) the new IDE supports software serial and it should work without h/w will try (maybe later on tonight and can report back)

cheers

V.
Title: Re: NMEA 2000 Shield
Post by: R_P_Ryan on Jan 19, 2016, 08:37 pm
I have built and published an Arduino-based marine engine monitoring system at https://bitbucket.org/R_P_Ryan/enginemonitor/wiki/Home.

It reads nine sensors and displays the data on 16 X 2 LCD, with a "next" button to display the next sensor:
1. Raw water in temp
2. Raw water out temp
3. Coolant entering the heat exchanger temp
4. Coolant exiting the heat exchanger temp
5. Cylinder head temp
6. Engine room temp
7. Oil temp
8. Exhaust gas temp
9. RPM


There is demand to publish the data to NMEA 2000 displays.

What is the best way to approach this?

Thanks,
Robert
Title: Re: NMEA 2000 Shield
Post by: Heatz on Feb 10, 2016, 04:21 pm
HI ttlappalainen,
your work on this project is very much appreciated and impressively done. I have a Mega and a CANbus shield but am having problems with sending data on my n2k network to a Raymarine a98. The arduino code (your tempmonitor) initializes the canbus shield correctly (though I had to change the CSpin to 10), but i get Write Failed messages when it runs. Does the code need to get a response form the n2k network or should it just be writing out the data? My TX and RX LEDs on the CANbus shield remain constantly lit. I am able to see the correct data when using the Actisense reader s/w and uncommenting the appropriate lines of code. I see nothing on the Raymarine MFD.
Thanks for any help you can provide.
Title: Re: NMEA 2000 Shield
Post by: Heatz on Feb 15, 2016, 10:50 pm
Timo,
Your code is fantastic and all working great as you documented. Thanks for the tremendous effort. I am using a Mega with CANBus shield. I had to connect Pin 53 of mega to pin 9 of Canbus shield to make it work. I am displaying RPM, OIl Pressure, Coolant Temp and Battery V on a Raymarine a98 MFD. I am curious about the SetN2kPGN127489 function as it appears not to make use of the boolean alarm flags. Your N2kMESSAGES.CPP code seems to not assign the enginesStatus1 and 2 messages into PGN messages.

I would have expected to see:

  N2kMsg.AddByte(engineStatus1P2);  // Discrete Status1
  N2kMsg.AddByte(engineStatus1P2);  // Discrete Status1
  N2kMsg.AddByte(engineStatus2);    // Discrete Status 2
  N2kMsg.AddByte(0);

right after the building of the engineStatus1x bytes. Is this correct?
Thanks, Heatz
Title: Re: NMEA 2000 Shield
Post by: Dick3 on Feb 22, 2016, 02:08 pm
Hi,

I'm looking for the NMEA PGN 127245 Rudder field format for SW programming.
Can anyone help me, please?

Thanks!

Jan Richard
Title: Re: NMEA 2000 Shield
Post by: Enzycal on Mar 04, 2016, 05:05 pm
Hi, is it possible to use this module http://www.14core.com/wiring-the-mcp2515-controller-area-network-can-bus-diagnostics/ (http://www.14core.com/wiring-the-mcp2515-controller-area-network-can-bus-diagnostics/) with NMEA2000 library?
Title: Re: NMEA 2000 Shield
Post by: maxik on Mar 13, 2016, 12:56 pm
Do I understand correctly that for use of the library to Maple Minnie I need additional Shield?
Title: Re: NMEA 2000 Shield
Post by: Hobbe1979 on Mar 15, 2016, 05:06 pm
Hi,
Great work you have done. I have managd to setup an Arduino due with a mcp2562 as described in the documentation from timolappalainen. I'm trying to communicate with a Garmin 721xs but I experience several problems.

It works if I use ActisenseListenerSender and run it with the nmea simulator by timolappalainen from openskipper. I do not receive all info sent. The wind data, tank and RPM does not show on the garmin unit. However fuel rate, engine temp, oil temp works among others. All simulated devices  appears in the list of devices on the garmin unit.

So now to the real trouble
If I use some of the other exampels as message sender or temp monitor. It shows up in the list and I receive data. Not complete but some of the data works. Then after 30-60 seconds it stops and the unit disappears from the list of devices. If I look on the traffic on the serial bus (usb), I still receive data from the garmin unit and the arduino seams to still send data. So I guess that its been kicked out by the garmin unit of some reason.
If I just initiate the Arduino and disable it from sending messages, then its stays in the list on the garmin unit.

I guess that I probably missed something important….   I have been reading through most of the documentation and libraries. I have to say that I'm impressed even if I do not understand even half.

I'm happy for all kind of support to get this to work.
Title: Re: NMEA 2000 Shield
Post by: The4thzeke on Mar 16, 2016, 12:06 am
Hello everyone, I am a complete Noob to Arduino and forums in general so I hope I do not insult anyone with my first post.  I would like to use the Arduino to receive depth data from my Raymarine NMEA 2000 depth sounder to control a fishing downrigger.  The Arduino would adjust the depth of my fishing gear based on the information sent from my depth sounder.  I'm okay with the mechanical aspects but have really no idea about the programming end of things.  I would appeciate any oppinion on the "do-ability" of this project as well as the level of programming complexity (ie. Likelihood of existing libraries for the programming).  I have spent some time searching the forum and the web for similar projects and I think others have done similar things but have not found anyone who has taken depth information from a NMEA 2000 system.  Thank you in advance and forgive me if I posted this in the wrong place.
Title: Re: NMEA 2000 Shield
Post by: Hobbe1979 on Mar 16, 2016, 06:15 pm
Hello,
I´ve been keeping on trying to find out why I get kicked out from the Garmin unit. I have made some interesting observations.  When I watch the traffic sent from the Arduino with the temature monitor program.

If I  comment: " // SendN2kTemperature();"  so it doesn't send any messages. it will stay in the list in the Garmin unit.

The traffic looks as follows:
--------------------------------------
CAN device ready
Start address claim
Pri:6 PGN:60928 Source:22 Dest:255 Len:8 Data:FB,FF,5F,2E,0,A0,64,40
Pri:6 PGN:126996 Source:22 Dest:255 Len:134 Data:FF,FF,9A,2,45,78,63,61,6C,69,62,75,72,20,58,2D,31,31,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,31,30,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,2E,30,2E,30,2E,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,30,39,37,31,34,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,FF,FF
Pri:6 PGN:60928 Source:22 Dest:0 Len:8 Data:FB,FF,5F,2E,0,A0,64,40
Pri:6 PGN:60928 Source:22 Dest:0 Len:8 Data:FB,FF,5F,2E,0,A0,64,40
-------------------------------------

And there after keep on sending PGN:60928 with a few seconds interval.
However when uncomment: " // SendN2kTemperature();" and I send a message, the traffic looks as follows. I Have noticed that it stops sending PGN:60928. Instead it send only PGN:13031.  See under.
I guess that this could be the reason? Are there any way of getting it to send PGN:60928 frequently?

------------------------------------------
CAN device ready
Start address claim
Pri:6 PGN:60928 Source:22 Dest:255 Len:8 Data:FB,FF,5F,2E,0,A0,64,40
Pri:6 PGN:126996 Source:22 Dest:255 Len:134 Data:FF,FF,9A,2,45,78,63,61,6C,69,62,75,72,20,58,2D,31,31,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,31,30,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,2E,30,2E,30,2E,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,30,39,37,31,34,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,FF,FF
Pri:6 PGN:130310 Source:22 Dest:255 Len:8 Data:16,C1,70,FF,FF,FF,FF,FF
Pri:6 PGN:130310 Source:22 Dest:255 Len:8 Data:16,C1,70,FF,FF,FF,FF,FF
------------------------------
Title: Re: NMEA 2000 Shield
Post by: Hobbe1979 on Mar 17, 2016, 01:14 pm
I have figured out that, if I do send an address claim by using "NMEA2000.SendIsoAddressClaim();" every 2000 milliseconds,  It works well with the Garmin 721xs.  Then everything seems stable. The RPM data works now. It seems to be just a setting in the garmin that was the issue.

Is this the correct way of solving my issue?
Title: Re: NMEA 2000 Shield
Post by: heryoon on Mar 19, 2016, 01:48 am
Hello, I'm trying to use the Mega and the Can-Bus shield in order to get readings from my NMEA 2000 "Intelliducer" from Garmin.
When I was attempting to use the temperature monitor sample code,
"CAN device failed to open"
from the
NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); part of the code.
Even though on my Can-Bus shield, the RX led is flashing.

Any idea why it's failing to "open" to the device which I'm assuming it's not communicating with it???
Title: Re: NMEA 2000 Shield
Post by: Hobbe1979 on Mar 21, 2016, 09:49 am
Hello, I'm trying to use the Mega and the Can-Bus shield in order to get readings from my NMEA 2000 "Intelliducer" from Garmin.
When I was attempting to use the temperature monitor sample code,
"CAN device failed to open"
from the
NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); part of the code.
Even though on my Can-Bus shield, the RX led is flashing.

Any idea why it's failing to "open" to the device which I'm assuming it's not communicating with it???
I got the same issue with my mega when the MCP2515 where not hooked up correctly. So I think that its caused when there are no working communication to the can controller.
Title: Re: NMEA 2000 Shield
Post by: Heatz on May 06, 2016, 02:11 am
Hello, I'm trying to use the Mega and the Can-Bus shield in order to get readings from my NMEA 2000 "Intelliducer" from Garmin.
When I was attempting to use the temperature monitor sample code,
"CAN device failed to open"
from the
NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); part of the code.
Even though on my Can-Bus shield, the RX led is flashing.

Any idea why it's failing to "open" to the device which I'm assuming it's not communicating with it???
I had issues getting my mega to work with the Canbus shield. Turned out I had the wrong MISO pin selected (or something like that). I posted about this somewhere, but can't seem to remember at this time.
Title: Re: NMEA 2000 Shield
Post by: Adrculda on May 11, 2016, 04:07 am
Hey guys...
My plan is to use a Garmin GFS10 for fuel consumption and level alongside an Arduino DUE faced with Engine Data Acquisition ( It's and older boat, not fuel injected ) and everything is analog. With that being said I would like to use this as an performance tracking tool and as backup if one of those gauges start to "lie".

Would like to add the following items into the NMEA2000 Stream with the DUE.
- Engine RPM ( I will have to devise a simple circuit as the only signal I have is from the coil )
- Engine Water Temp
- Port Exhaust Temp
- Starboard Exhaust Temp
- Water Temp / Speed ( Using Mercruiser 859223 Unit )
- Heading / Compass
- Trim / Tilt


 I'm going to be using an Lowrance Elite 7Ti as an display unit.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 11, 2016, 05:03 am
Hi Guys,

I have not followed this forum for a while, since I should get messages by email and I have not got any until now. So I have thought this has been dead. Here are some late answers.

Please check arduino library on https://github.com/ttlappalainen/NMEA2000 . It has been developed more and used by several projects. Under documents there are drawings to make own devices and how to start with library. Under examples there are ready code e.g. for sending some temperatures.

Adrculda:
So for sending engine RPM you just use:
    SetN2kEngineParamRapid(N2kMsg, EngineInstance, RPM);
    NMEA2000.SendMsg(N2kMsg);

For engine water temp you need to use
    SetN2kEngineDynamicParam(N2kMsg, 1,N2kDoubleNA,N2kDoubleNA,EngineWaterTemp,N2kDoubleNA,N2kDoubleNA,N2kDoubleNA);
    NMEA2000.SendMsg(N2kMsg);

And for temperatures as in example TemperatureMonitor.ino
    SetN2kTemperature(N2kMsg, 1, 1, N2kts_ExhaustGasTemperature, ExhaustTempPort);
    NMEA2000.SendMsg(N2kMsg);
    SetN2kTemperature(N2kMsg, 1, 2, N2kts_ExhaustGasTemperature, ExhaustTempStarboard);
    NMEA2000.SendMsg(N2kMsg);

Hobbe1979:
PGN 60928 is only for address claiming and it will be done only when requested. So that should ne be sent frequently. Unfortunately some units expects it. E.g. my Garmin GMI 20 does not.

Dick3:
In NMEA2000 library there is ready function SetN2kRudder. If you need to know how data is build, read code on N2kMessages.cpp.

Enzycal:
Yes you can. It is almost the same as my sample schematic: https://github.com/ttlappalainen/NMEA2000/blob/master/Documents/ArduinoMega_CAN_with_MCP2515_MCP2551.pdf
Title: Re: NMEA 2000 Shield
Post by: jukkap on May 11, 2016, 07:26 pm
Hello,

My goal is to get speed information from Raymarine a67 and display it in another display/meter.

Problem is that when Raymarine contacts satellites, NMEA messages ends from Raymarine and Raymarine don´t receve any messages from AT90CAN128.
 
When Raymarine is tested indoors and it can´t get satellites, system shows work  just fine.
For example it ansewers ISO reguest speed IDE: 59904 Data: 128259 (speed), even without address claim.

What would be the solution?

1. Should i pay attension something in address claim?
            (Field informations, Device instance, Manufacturercode etc.)

2. Should Product Information(126996) be send, even Raymarine or ohter nodes don´t request it?
             (Tryed to send, but Raymarine not seems to understand message)

3. Or should i give up and by Actisense NGT-1 ISO? Could it be the solution of this project. Any experiences  from Actisence?


Harware setup:
-AT90CAN128
-MCP2551
-Raymarine a67


Thanks,

Jukka Penttinen

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 11, 2016, 09:17 pm
Hi jukkap,

First do you use my NMEA2000 library with NMEA2000_avr?
Have you tested just listen traffic on bus by using example ActisenseListener and do you get it right?
What is your other display?

1. I have tested a lot with Garmin GMI 20 and it seem to be rather flexible. With my current address claiming code it works fine. But some other system required that address claiming should be sent every 2 sec. So who can say about Raymarine does it accept only registered manufacturer instead my default 2046, which is the highest possible value.

2. In principle there is no need to send product information without request. Devices should register devices on the bus by address claiming and if they are interested about sender, then they should request product information.

3. I have NGT-1 ISO and it is good. After writing NMEA2000 library I have done everything with with it and NGT is just as a spare on boat.

If you are located in near Turku I would be interested to test your MFD with Arduinos.
Title: Re: NMEA 2000 Shield
Post by: Adrculda on May 12, 2016, 03:42 pm
So...

Went Ahead and Ordered a waterproof enclosure (http://www.ebay.com/itm/252101965244?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT) and will be using an AMP seal connector for the sensor inputs from the engine.

Does anyone know what the part number for the NMEA2000 connectors are ??
I'm almost sure TE / AMP would be the one to supply them...
Title: Re: NMEA 2000 Shield
Post by: Rfritz on May 12, 2016, 09:14 pm
Look at these from digikey:

APC1760-ND $4.24

waterproof O-ring and mounting nut included.
Title: Re: NMEA 2000 Shield
Post by: Adrculda on May 13, 2016, 04:04 am
Look at these from digikey:

APC1760-ND $4.24

waterproof O-ring and mounting nut included.
Thank you :)
Title: Re: NMEA 2000 Shield
Post by: nilsal on May 14, 2016, 10:38 pm
I've tried to build the TemperatureMonitor program for mega it gives the error message:

C:\Users\Nils\Documents\Arduino\libraries\NMEA2000_mcp-master/NMEA2000_mcp.h:62:84: error: 'MCP_16MHz' was not declared in this scope ...


If I build it with due settings it works. Unfortunately I don't have a duo board.
If I try to define MCP_16MHz

#ifndef MCP_16MHz
#define MCP_16MHz 1
#endif


 I get:
C:\Users\Nils\Documents\Arduino\libraries\NMEA2000_mcp-master\NMEA2000_mcp.cpp:60:148: error: no matching function for call to 'MCP_CAN::MCP_CAN()'...

I think I have followed the instruction in Arduino NMEA2000 library
02.02.2016 pdf file
Does anybody know what can be wrong?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 15, 2016, 06:08 am
I tested with latest libraries and seem to work.

Note that you should not use original Seed studio can bus shield library. MCP_16MHz has been defined in developed version of CAN_BUS_Shield library in file mcp_can_dfs.h on line 250. If you do not have that, delete your Arduino\libraries\CAN_BUS_Shield-master and download it from https://github.com/peppeve/CAN_BUS_Shield and install it.
Title: Re: NMEA 2000 Shield
Post by: jukkap on May 15, 2016, 08:19 am
Hi Timo,

Here is some deteails what I forgot mention.

First do you use my NMEA2000 library with NMEA2000_avr?
No. When I start this project I found some C CAN example from AvrFreaks harwared with AT90CAN128.
For me Adruino isn´t so familar yet, but maybe I should exlore it.

Have you tested just listen traffic on bus by using example ActisenseListener and do you get it right?
I have´n test bus any other device but follow bus traffic from Raymerine. Raymarine stops sending messages when it reachs satellites.
Now I´m gonna order Actisence so I can listen bus traffic and maybe get proceed this project by that.

What is your other display?
My plan is to get old Sumlog knotmeter to display speed from Raymarine == Retrometer ;)


Here is some tests what  I´m done whit my devices.

Raymerine gets           AddClaim        SpeedReguest         Traffic on bus
Satellites                      done               Tx + Rx              (checked from Raymarine)

   F                                F                     F                         T
   F                                T                     T                         T
   T                                T                     F                         F
And correction my previous message: I have to AddressClaim before can get or send any messages on bus.
So, thats seems to be OK.


Summary: I get that Actisense and see how does it works then.
Tanks for all so far. I raport results when I get that Actisense.

PS: Timo, I live in Vaasa and sail under WSF. Let me know if you are sailing here Kvarken.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 15, 2016, 08:41 am
You could try with my library before ordering NGT-1. If you just load my library, stuff for avr and try with example ActisenseListener, you should be able to see all traffic on bus with Actisense NMEA Reader.
Title: Re: NMEA 2000 Shield
Post by: jukkap on May 15, 2016, 08:50 am
Ok.

Maybe i should test it. Do I have to do some modifications to code when i use AT90CAN128 prosessor?
Title: Re: NMEA 2000 Shield
Post by: nilsal on May 15, 2016, 11:12 am
I tested with latest libraries and seem to work.

Note that you should not use original Seed studio can bus shield library. MCP_16MHz has been defined in developed version of CAN_BUS_Shield library in file mcp_can_dfs.h on line 250. If you do not have that, delete your Arduino\libraries\CAN_BUS_Shield-master and download it from https://github.com/peppeve/CAN_BUS_Shield and install it.
Thanks, change of library did the trick!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 15, 2016, 08:20 pm
JukkaP. I have not tested avr chips, but thomasonw used them and made the code. On library readme it says: "To use avr processors internal CAN you need also NMEA2000_avr library and avr_can library, which you can download from https://github.com/thomasonw/avr_can". So if you have selected avr board, the #include <NMEA2000_CAN.h> in example ActisenseListener should automatically select right libraries for you - you must have installed them ofcoarse.

Example ActisenseListener does not show itself on bus at all - it simply listens. To send some data e.g. temperatures, there is example TemperatureMonitor, which should work as well. I have tested all examples with DUe and Mega boards by using both Garmin GMI20 and NMEAReader. Some examples has been also tested with Teensy boards. I do not have avr boards, but thomasonw developed something by using my library.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 16, 2016, 08:33 am
Hi all,

For building NMEA2000 devices, check this link: https://hackaday.io/project/11055-kbox
It has build in several hw components for boating solutions. Available code has been build by using my NMEA2000 library.
Title: Re: NMEA 2000 Shield
Post by: gibas on May 16, 2016, 01:53 pm
Hi,

I'm new to these foruns. First of all thanks to everyone for sharing the information. I'm trying to send data from Arduino battery monitor example sketch to my N2k bus consisting of Garmin 720, 2 GMI10, one VHF 300i and 1 Airmar Intelliducer. I have one MCP2515 controller with TJA1050 transceiver working at 8 Mhz. From what I've realized the library is set for 16 Mhz as default. How can I change it to 8Mhz?

Thanks for your answers,

Gibas
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 16, 2016, 02:10 pm
Hi,

You should edit beginning of you BatteryMonitor sample with #define USE_MCP_CAN_CLOCK_SET 8:
...
#include <Arduino.h>
//#define N2k_CAN_INT_PIN 21
#define USE_MCP_CAN_CLOCK_SET 8
#include <NMEA2000_CAN.h>       // This will automatically choose right CAN library and create suitable NMEA2000 object
#include <N2kMessages.h>
...
Title: Re: NMEA 2000 Shield
Post by: gibas on May 16, 2016, 02:25 pm
Hi,

As described in the begining of NMEA200_Can.h file.... I don't know how I've missed it. Thanks for your fast reply.

Regards,

Pedro
Title: Re: NMEA 2000 Shield
Post by: Tlam on Jun 21, 2016, 08:21 am
Hi!


I have trouble with 127506 PGN DC Detailed status.

I write any value of field 3 and display - "0%" !!!

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 21, 2016, 09:11 am
Hi,

Which display you use? Do you have right type for value?

There is example MessageSender, which also sends that message as sample. I just tested that with NMEA Reader and it shows values as they have been set on sample code. One can test MessageSender code with single board by setting NMEA2000.EnableForward(true); on setup and then opening NMEA Reader to board port. You can test your code in this way too.
Title: Re: NMEA 2000 Shield
Post by: Tlam on Jun 23, 2016, 09:51 am
Thank you for you answer, problem is out)


I need another little help.

I try coding PGN 127505 and problem with field of capacity in liters.

Field is 8 byte , I don't know how to translate simple value (ex. 100) into 8 byte field ....
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 23, 2016, 10:28 am
Are you using NMEA2000 library and N2kMessages.h/.cpp? In N2kMessages.h there is simple definition for call: SetN2kPGN127505 or
SetN2kFluidLevel(tN2kMsg &N2kMsg, unsigned char Instance, tN2kFluidType FluidType, double Level, double Capacity);
, where you simply set Capacity as 100 e.g.

SetN2kFluidLevel(N2kMsg,1,N2kft_Fuel,51.2,100);
NMEA2000.SendMsg(N2kMsg);

This will set current fuel level to 51.5% of 100 l capacity.
Title: Re: NMEA 2000 Shield
Post by: Tlam on Jun 23, 2016, 09:38 pm
another question. I try to use your library with arduino nano and can bus shield 8MHz.

"
Arduino: 1.6.7 (Windows XP), Плата:"Arduino Nano, ATmega328"

In file included from C:\Documents and Settings\Admin\Мои документы\Arduino\libraries\NMEA2000-master/NMEA2000_CAN.h:85:0,

                 from C:\Documents and Settings\Admin\РњРѕРё документы\Arduino\Nmeatest\Nmeatest.ino:19:

C:\Documents and Settings\Admin\Мои документы\Arduino\libraries\NMEA2000_mcp-master/NMEA2000_mcp.h:58:84: error: 'MCP_16MHz' was not declared in this scope

     tNMEA2000_mcp(unsigned char _N2k_CAN_CS_pin, unsigned char _N2k_CAN_clockset = MCP_16MHz, unsigned char _N2k_CAN_int_pin = 0xff);

                                                                                    ^

In file included from C:\Documents and Settings\Admin\Мои документы\Arduino\Nmeatest\Nmeatest.ino:19:0:

C:\Documents and Settings\Admin\Мои документы\Arduino\libraries\NMEA2000-master/NMEA2000_CAN.h:95:27: error: 'MCP_8MHz' was not declared in this scope

 #define MCP_CAN_CLOCK_SET MCP_8MHz

                           ^

C:\Documents and Settings\Admin\Мои документы\Arduino\libraries\NMEA2000-master/NMEA2000_CAN.h:105:39: note: in expansion of macro 'MCP_CAN_CLOCK_SET'

 tNMEA2000_mcp NMEA2000(N2k_SPI_CS_PIN,MCP_CAN_CLOCK_SET,N2k_CAN_INT_PIN);

                                       ^

exit status 1

?
 
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 24, 2016, 09:22 am
Hi,

You have the same problem as nilsal on this forum message #92. I responded on #93 that you should not use original seed studio library. Instead use https://github.com/peppeve/CAN_BUS_Shield. That has been also mentioned on my library documents.

Timo
Title: Re: NMEA 2000 Shield
Post by: fred3 on Jun 29, 2016, 07:38 pm
Hi Timo and all !

This is my first post but I have been reading everything you did with N2k and all about boats !
Thank you very much for sharing all your work. I appreciate it very much !

I am retired in electronics but have been living the computer age since the day of the 80 series (and even the 40 !) did some assembler with the 6502 but I am new in Arduino and programming. I have been interested in the N2k CAN since my friend has a boat using this network. So I need to help him with electronics.

However I have 2 due's working with CAN in a closed N2k network. All is working FB including a short program I  put together from bits and pieces of programs including your work that sends waterspeed to N2kbus from a paddle speed sensor. It works OK including the Product and Device information but I am shy to share it as it probably would not survive experts opinion,hi.

Anyway I am able now to inspect my friends N2k network and perhaps do some work in the future.
I would like to look at the Address Claiming in the near future. I hope to be able to learn more about this N2k with the Arduino due and have some NMEA0183 devices connected too.
Please continue your work !

Thank you

Fred




 
Title: Re: NMEA 2000 Shield
Post by: syntaxio on Aug 30, 2016, 04:42 pm
Just found this as I am starting a project on a new wake sport boat. I have been long time electronics guy but mostly in the analog realm until the last few years. That said I have been coding for a very long time and do it for a living. It is all just syntax and IO so I figure with enough time I will be able to figure out N2K.

My intent is to automate a few things that I normally could have done without the need for N2K. The issue is that the newer wake sport and day boats are moving to custom built in MFD with joystick control knob and button devices for the human interface that all communicate of N2K. Boats in this class are getting far more complex as they are including features from the factory that use to be add ons. The custom MFD in my boat handles the task of communicating over the engine can bus, the radio can bus, NMEA 0183, and NMEA 2000. The MFD also communicates with a gateway over N2K in order control things such as lights, bilge, horn, etc. The only things I need to decipher for my current project are GPS and all of the joystick/button commands. Obviously there will be a few undocumented PGNs but I hope to be able to figure them out. I am first going to attempt to use the actisense listener sketch to see what is being broadcasted but from there I may need a hand as I am new to N2K. The upside is I may discover and help document a few PGN on the HID side of things which are becoming more common.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 30, 2016, 07:22 pm
Hi syntaxio,

You have interesting job to discover undocumented PGN:s. Note that there are pgn.h under SignalK project and PGNDefs.N2kdfn.xml (latest version under www.kave.fi/Apps) under OpenSkipper, which already has a lot PGN information. Also it is easiest for reverse engineering to minimize bus data by switching devices off.

Anyway do not hesitate to ask help.
Title: Re: NMEA 2000 Shield
Post by: syntaxio on Sep 14, 2016, 10:13 pm
I have tried sending a private message a few days ago but not sure if it worked. Long story short is I have isolated the proprietary PGN and values that I need to be able to read and write. Just need to get them added to the library and having just a bit of brain fart trying to do that. Could certainly use a hand at this point.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 15, 2016, 05:57 am
Hi,

I do not know, why I did not receive notify for private message.

Since these are proprietary, it is best to create own message files for these. So if you have device manufacturer B&G, you could create message files N2kBandGProprietaryMessages.cpp and .h. Then you create message creation and parsing messages similar as they are on N2kMessages.cpp and .h. Note also that since different manufacturers can use same PGN:s for proprietary messages, it may be that there is no sense name functions as they are on N2kMessages e.g. SetN2kPGN127489. Instead just use informative name e.g.
// Sonic hub proprietary PGN 130816
void ParseN2kSonicHubInfo(...)

So you do not need to add your PGNs at this point to library. When you have tested handling functions for then, it would be greate to get them published for possible other users.

Without information about you PGN structure I can not say more for now.
Title: Re: NMEA 2000 Shield
Post by: coryjfowler on Oct 06, 2016, 09:20 pm
Does anyone have a Garmin chart plotter that uses a NMEA 2k GPS?  I can decode all the GPS PGNs, but I can't turn on WAAS and GLONASS.  Garmin is no help at all, and I do not suggest using their NMEA 2k products as a result since they wont support them outside of their own products which violates the whole point of NMEA 2k.

By the way, Maretron manuals are a good source for NMEA 2k PGN information.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 07, 2016, 06:17 pm
I prefer also to look CanBoat project pgn.h (https://github.com/canboat/canboat/blob/master/analyzer/pgn.h) and derived OpenSkipper PGNDefns.N2kDfn.xml (see http://openskipper.org/). Both has better description of data than Maretron Manuals. I have some fixes for OpenSkipper PGN definitions, which has not yet been published, but I'll do it within some weeks.
Title: Re: NMEA 2000 Shield
Post by: mespelosin on Nov 08, 2016, 01:25 pm
I am working with Maretron products (FFM100 and FPM100 sensors), reading data in NMEA2k and sending in RS232 port. I have decoded FPM100 sentences, but i faced difficulties in FFM100 65286 / 65287 propietary sentences.
I would need information about those fields, to decode info and later send it.
I would appreaciate if you could provide any kind of information.
Title: Re: NMEA 2000 Shield
Post by: Heatz on Nov 29, 2016, 07:31 pm
I am using a Arduino Mega and CANbus shield for sending data through to a NMEA 2k network. I am successfully sending the following PGNs and displaying on an a98 Raymarine MFD

SetN2kEngineDynamicParam
SetN2kEngineParamRapid
SetN2kDCBatStatus
SetN2kEnvironmentalParameters

However, I am trying to construct my own AIS messages and send SetN2kAISClassAPosition but it is not being displayed on a98 Raymarine MFD even though it does appear to be 'read' on the actisense nmea reader.

  SetN2kAISClassAPosition(N2kMsg, 1, Repeat, 123456789, 26.396, -80.075, 1, 1, 1, 20, 20, 30, 0, NavStatus);


has anyone successfully sent AIS messages?

Eric
Title: Re: NMEA 2000 Shield
Post by: mechand on Dec 08, 2016, 08:29 am
Dear colleagues, we are producing fuel flow meters. And now making Nmea2k version of differential type fuel flow meter (can be easy installed for supply-return flow engine).

Would be fine to have some cooperation with other NMEA2k investigators.

We now can send messages to Lowrance display:

http://imgur.com/a/PWNBU
http://imgur.com/a/PWNBU

but I understand it is point-point communication, in real big NMEa2k network it will create problems

We are lacking address claiming support.
And PGN list report.

SO if any can share this docs with us we can send our products for example as X-mas gift :)
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 08, 2016, 08:37 am
Hi,


Are you using my NMEA2000 library (https://github.com/ttlappalainen/NMEA2000). It has automatic address claiming support etc.

There is also progress with "Remove Arduino dependencies" under issue with that name.

Funny that I am also building fuel flow/engine monitor just for my own.
Title: Re: NMEA 2000 Shield
Post by: lundpetersen on Dec 13, 2016, 06:38 pm
Hi All,

I have used timolappalainen's great project and have it working on my Arduino Due. I have created a simple circuit that measures the voltage of my batteri and outputs it on NMEA2000 to my Lawrence HDS 9 Gen3 MFD. It works like a charm.

My plan is to transfer my analogue gauges to my MFD - the first was the voltage. I also need to transfer Fuel Level, Tachometer (RPM's), and Speedometer. Ultimately I also want to use the DUE as NMEA0183 to NMEA2000 for my Furuno 4800 Radio with AIS so I don't need to have any NMEA0183 connected to my MFD's.

My question is, do anyone have a good link to a circuit I can studdy to figure out how to make my DUE read the input from the Tachometer from my engine? Its an old Mercury engine - and it is definitely analogue. Any good ideas/links to articles about others that has done this on Arduino?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 14, 2016, 07:07 am
Hi,

Have you checked e.g. http://cr4.globalspec.com/thread/53842/Getting-a-RPM-Signal-From-the-Alternator ?

Alternative way is to use e.g. reflective sensor e.g. http://fi.farnell.com/omron-electronic-components/eesy313/photomicrosensor-reflect-4-4mm/dp/2301884?ost=eesy313&selectedCategoryId=&categoryNameResp=Kaikki%2Bluokat&searchView=table&iscrfnonsku=false

That of coarse requires that you need to build support forsensor to engine. But with it you will allways get true RPM, which does not need calibration like using W.

I am building fuel flow meter, where I would include reflective sensor for RPM and other engine information.

I have also ready NMEA0183->NMEA2000 converter for GPS. By modifying selected messages, you could easily modify that for your own purposes.

I also prefere to have several boxes instead of trying to put all functionalities to same. I have started to use Teensy 3.2 or up in most my devices. Teensy 3.2 is smaller and requires less power that DUE. You can find some documents on example https://github.com/ttlappalainen/NMEA2000/tree/master/Examples/TeensyActisenseListenerSender
Title: Re: NMEA 2000 Shield
Post by: Tlam on Dec 16, 2016, 02:25 pm
Hi,

I have develope FUSION LINK server

Please help me construct CAN message for CAN.sendMsgBuf() function.

PGN 130820

The first two data bytes of any message will contain Proprietary Parameter Group Structure with the
following format

11 bit - value of 419
2 bit - value of 3
3 bit - value of 4

These fields combine to give the value 0x99A3
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 16, 2016, 06:05 pm
Are you using NMEA2000 library or do you really want to use directly mcp_can library?
Title: Re: NMEA 2000 Shield
Post by: Tlam on Dec 16, 2016, 06:53 pm
I successfully use your library, thank you very much.


But it useless for FUSION LINK PGNs. I want use directly mcp_can.

But I can't construct right message.
Title: Re: NMEA 2000 Shield
Post by: Tlam on Dec 16, 2016, 07:28 pm
And , are you have any information about PGN 130820 ? )
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 16, 2016, 08:19 pm
Why it is useless? You can send or parse any message with library. You just need to write message build or parser program to your own file. N2kMessages contains most used messages, but nothing prevents you write you own messages.

130830 is proprietary message and its contents depends of manufacturer and I do not have any other information of it execpt that first two bytes contains manufacturer code and and industry code (4=maritime).

But for library you can have message builder function like others in N2kMessages:
void SetN2kPGN130830FusionLink(tN2kMsg &N2kMsg, ???) {
    N2kMsg.SetPGN(130830L);
    N2kMsg.Priority=3;
    N2kMsg.Add2ByteUInt(0x99A3); // Fusion link
    N2kMsg.Add???
}

But there is no way to write more, if you do not know the content os Fusion Link message.

Note that 0x99A3 can be also constructed  4 << 13 || 3 << 11 || 419
Title: Re: NMEA 2000 Shield
Post by: Tlam on Dec 16, 2016, 08:36 pm
Thank you for help and idea ! ))

But very difficult for me...
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 17, 2016, 05:31 am
With library you can make much more easily any N2k system, since it takes care of several things required on communication on N2k bus. In N2kMessages you will find common PGN build and parser routines, which you can use as sample to build your own. In examples MessageSender, WindMonitor or Temperature monitor you find how to send data to the bus. And e.g. example DataDisplay2 shows how to read PGNs.

If you do not have description for PGN 130830 data content, you have to spy it by recording data on bus and mark changes made on sender side. You can not do that "reverse engineering" if you do not have devices from original manufacturer.
Title: Re: NMEA 2000 Shield
Post by: Tlam on Dec 17, 2016, 09:42 am
I successfully use library for many selfmaid devices. Engine monitor, fuel level and battery monitor.

Now I have idea to make audio server on arduino that controlled from raymarine mfd.

I don't have device for reverse engineering and fully information about proprietary PGNs(

But some pieces of information looks are possible for some experiments.

Title: Re: NMEA 2000 Shield
Post by: Tlam on Dec 17, 2016, 01:13 pm
May be somebody have information about proprietary entertainment PGNs ?
Title: Re: NMEA 2000 Shield
Post by: Tlam on Dec 18, 2016, 12:28 pm
Hi Timo,


I have a question about NMEA2000.SetN2kCANMsgBufSize();

When I provide argument value more than 2 , device hold. What happened ?


1 or 2 work correctly
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 18, 2016, 05:39 pm
What device you use and how much memory used it says after compilation?

I tested example ActisenseListener on Arduino Mega with 20 and it works. 30 does not. Note that this allocates memory dynamically and one tN2kCANMsg eats about 243 bytes memory. So 5 will eat 1.2 kB. For Mega my test says 7.8 kB free after compilation. So 30 takes 7.3 kB and remaining 0.5 kB is not enough for other local variables and also Mega hangs. So I would expect that you have device where even 3 is too much.
Title: Re: NMEA 2000 Shield
Post by: Dazzler on Dec 30, 2016, 08:07 pm
I'm struggling with the basics.  I have a Due connected to the W7 PC running Arduino IDE 1.6.12, as per Timo's instructions for the NMEA 2000 library. I have edited the temperature sketch, uploaded it to the Due and started Actisense NMEAReader and selected the com port, all as per instructions.
But I see nothing in NMEA reader.  The only output I can see is if I uncomment the serial.print line in SendN2kTemperature and start the Serial monitor.
I've followed Timo's instructions to the letter but have failed at the first hurdle.  Is there any other config  I should have done?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 30, 2016, 08:45 pm
Hi,

Due to library portability changes we had to remove Serial as default output stream. This is documented on Readme Changes section. So it should start to work, if you add line
  NMEA2000.SetForwardStream(&Serial);
after
Serial.begin(115200);

I'll add this to example for next release.
Title: Re: NMEA 2000 Shield
Post by: Dazzler on Dec 31, 2016, 05:03 pm
Thanks Timo. Laziness on my part - RTFM, as they say.
And thanks for all the work you've put into this. I'm sure there are many more people who have benefited from all your effort.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 04, 2017, 09:41 am
As my opinion RTFM is not good attitude, since things may be written unclear or specially when you start to work with new things, it may be difficult to understand or find. Also even for simple things manuals may be so long, that who has time to read them from word to word. So if I know the answer, I'll never respond with RTFM. Instead as this case I'll answer to the question and point to the place, where it has been explained. This may help user next time to find answers for similar questions first from manual.

So please at least about my NMEA 2000 library do not hesitate to ask, if you do not find solution easily from manual. Asking may save you several hours instead of trying to understand my manual.
Title: Re: NMEA 2000 Shield
Post by: jrmdive on Jan 24, 2017, 07:47 pm
Hi all,

A million thanks for Timo and the others who have contributed code.  Life is good.

I'm working on building out an array of marine electronics for my boat.  I have an existing N2K network that I installed previously, and wanted to push my data onto it to make it available to my consumer electronics.

Just a quick note for those who are contemplating this path:

DO NOT USE THE ARDUINO TOOLCHAIN PRE-PACKAGED WITH YOUR LINUX DISTRO.

I wasted (although I've learned tons, so it's probably not wasted) about a week working on getting the NMEA stuff to compile.  I could not figure out why I was having cascading dependency problems.  I even deleted my entire IDE and started again.  Then I snagged a Due and transceiver to try and follow as closely to the original project as possible, which is when I discovered that the version of the Arduino IDE that I had installed was a mess (no option for additional boards.)  I dumped it, downloaded the one from arduino.cc, and installed the library chain.  And it compiles first time.  Aaarrrrggghhhhh!

You'd think as someone who's been using Linux since 1994, and various UNIX flavors for much longer, I would have known not to trust a pre-compiled package.  But since that issue didn't pop up in a lot of searching, I thought I'd memorialize my issue and solution here for the next person.

At any rate, many thanks again to all those contributors.  I'm sure there'll be questions in the future, as I'm planning on putting together a network of low-cost low-power sensors based on the Nano and tying them in to my existing N2K network.

Josh
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 24, 2017, 08:49 pm
Just want to remind about KBox project, which has nice package for N2k bus with WiFi output etc. Check it at https://hackaday.io/project/11055-kbox
Title: Re: NMEA 2000 Shield
Post by: jrmdive on Jan 25, 2017, 01:30 am
Also, there's a typo on line 58 of NMEA2000_mcp.h

   tNMEA2000_mcp(unsigned char _N2k_CAN_CS_pin, unsigned char _N2k_CAN_clockset = MCP_16MHz
                                                                                                                                                                         

should be:

   tNMEA2000_mcp(unsigned char _N2k_CAN_CS_pin, unsigned char _N2k_CAN_clockset = MCP_16MHZ



Josh
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 25, 2017, 07:56 am
Why? See mcp_can_dfs.h ... line 255: #define MCP_16MHz   1
Title: Re: NMEA 2000 Shield
Post by: jrmdive on Jan 25, 2017, 07:55 pm
This is why the boss at my first sysadmin job insisted that we compile everything from source ourselves.  Because package managers only complicate things.  Turns out that even though I stripped out the packages and reinstalled the new IDE in my home directory (may the aforementioned BOFH forgive me for ever installing in my home directory) I hadn't actually checked to make sure that ALL the files were deleted.  Turns out that there was a copy of the seed version installed in /usr/share/arduino/libraries/.  Which wouldn't be a problem, except that even though I installed in my home directory (a thousand pardons sir), the IDE decided to default to the shared library location and was using that library, which has it capitalized.  Which is why nothing would compile without the change.

So I deleted them, quit all IDE sessions, reloaded, and tried again.  I still required the "MHZ" in my trial program.  Rebooting didn't help.  Somewhere the IDE was hiding that define with the capital Z, and I couldn't find it.

So I got medieval on it.  Removed everything, from everywhere.  Downloads, folders, everything.  "sudo find /* | grep mcp" found a bunch of stuff hiding in /tmp.  Stripped it all.  Started over from scratch, redownloading and reinstalling.  Deleted all my CAN test sketches (OK, that may have been a bit much, but I was frustrated).  Which was a bummer as I had a working three node setup (two nanos and a due) all talking even with all this namespace clashing.

So, after the complete nuke drop and reinstall, I've got the three nodes talking again, without the capital "Z" but this is crazy.  I have no idea which of my other projects I've broken by doing this.

I once worked in a shop where the suits decided that Silicon Graphics was the next Sun, and dropped a bunch of IRIX machines on us and told us to use them.  We had to port everything.  This feels a lot like that, except that was the early 1990's and I was getting paid...

Josh

-- I think the moral of this story is "If you've ever done anything with CAN in the arduino environment before attempting the NMEA2000 stuff, delete it ALL and start from scratch."
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 26, 2017, 06:54 am
I am sorry, but I do not understand. On original SeedStudio CAN bus code I could not find that definition at all. See. https://github.com/Seeed-Studio/CAN_BUS_Shield . As far as I know peppeve (https://github.com/peppeve/CAN_BUS_Shield) implemented that, when he added support for Maple Mini 8MHz.
Title: Re: NMEA 2000 Shield
Post by: jrmdive on Jan 26, 2017, 04:53 pm
Not that it overly matters now, I've got it all working.  But in the interest of my own curiosity, here's what I've found.

In the version of the library that was initially installed, this was the header:
Code: [Select]
mcp_can_dfs.h
  2012 Copyright (c) Seeed Technology Inc.  All right reserved.
  2014 Copyright (c) Cory J. Fowler  All Rights Reserved.

  Author:Loovee
  Contributor: Cory J. Fowler
  2014-1-16

When you peruse the file, starting in line 439 you get:
Code: [Select]
#define MCP_20MHZ    0
#define MCP_16MHZ    1
#define MCP_8MHZ     2

Which obviously translates over to the .cpp file, yet those are the only instances.  All the rest of the times the "Z" appears lower case, as in lines 241-:
Code: [Select]
/*
 *  Speed 8M
 */
#define MCP_8MHz_1000kBPS_CFG1 (0x00)
#define MCP_8MHz_1000kBPS_CFG2 (0x80)
#define MCP_8MHz_1000kBPS_CFG3 (0x80)

#define MCP_8MHz_500kBPS_CFG1 (0x00)

In fact, in the entire library folder, there are only these instances:
Code: [Select]
     ./grep MHZ *
keywords.txt:MCP_16MHZ           LITERAL1
keywords.txt:MCP_20MHZ           LITERAL1
mcp_can.cpp:        case (MCP_8MHZ):
mcp_can.cpp:        case (MCP_16MHZ):
mcp_can.cpp:        case (MCP_20MHZ):
mcp_can_dfs.h:#define MCP_20MHZ    0
mcp_can_dfs.h:#define MCP_16MHZ    1
mcp_can_dfs.h:#define MCP_8MHZ     2

I think the only reason I even ran into it, beyond the "broken not broken" nature of the library caching system in the arduino IDE, is that the cheap Aliexpress breakout boards I got came with 8MHz crystals instead of 16MHz.  So in using the #define to allow for the different speeds, I got caught out with conflicting libraries.

At any rate, a million thanks again for the N2k code.  I've got my sensors up and talking and it's great. 

Josh
Title: Re: NMEA 2000 Shield
Post by: Pelle8879 on Jan 28, 2017, 01:40 pm
Hi Timo!
I would like to send compass direction in degrees to NMEA2000 and would like to know how to do that.
I do not like the way GPS is determining compass direction when standing still.
A have a compass solution using two GPS-es. I am reading NMEA0183 from each and then I calculate Compass direction (0-360) with an arduino DUE.

The problem I have is to send degrees to NMEA2000 (If there are any message type for that).
How do external compasses send compass direction on NMEA2000?

I can send NMEA0183 message but would like to send similar to NMEA2000 bus.
This is the spec. for xxHDT in NMEA0183.
$--HDT,x.x,T*hh
1) Heading Degrees, true
2) T = True
3) Checksum
Could you please help me?
/Pelle
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 28, 2017, 03:11 pm
Heading will be provided with NMEA 2000 PGN 127250.

Have you looked in e.g. WindMonitor example in my NMEA2000 library? So instead of call SetN2kWindSpeed(...) in WindMonitor use call SetN2kTrueHeading(N2kMsg,0,DegToRad(HeadingInDegrees));

Remember also change SetProductInformation(...) and SetDeviceInformation(...) in setup() to match your device.

You can find message creating functions in N2kMessages.h.

How accurate heading you can get with two GPS? I have Vector GPS compass, which is accurate, but expensive.
Title: Re: NMEA 2000 Shield
Post by: Pelle8879 on Jan 28, 2017, 04:42 pm
Thank you Timo!
I plan to use two RTK-recievers fetching Base station data over TCP and therefore I will get position within dm accuracy (at clear sky), that means... very good GPS-accuracy. I have not calculated the accuracy but it depends of course of the distance from front to rear antennas.
I will immediatly try to setup your suggested solution.
Thanks a lot for your info!
If I have further questions regarding connections for CAN-Bus I hope you will be helpful also.
Thanks again!
/Pelle
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 28, 2017, 05:36 pm
Please check the documents folder, there are sample schemas. With due I prefer to use MCP2562, which has ability to use 3.3 V IO as required with DUE.
Title: Re: NMEA 2000 Shield
Post by: Pelle8879 on Jan 29, 2017, 08:31 am
Thanks Timo, I really appreciate your help! :)
/Pelle
Title: Re: NMEA 2000 Shield
Post by: seamaster on Feb 03, 2017, 07:53 am
I read that most people are using arduino duo or mega. I'm not quite clear if it is possible to create low cost engine monitoring system and output to n2k with arduino uno and some kind of can driver?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 03, 2017, 10:45 am
I would prefer Teensy. Check example https://github.com/ttlappalainen/NMEA2000/tree/master/Examples/TeensyActisenseListenerSender on my NMEA2000 library and leave additional USB (small Pololu board) away. Then you have NMEA2000 bus ready board to add your own interfaces.

I have not tested library with Uno. But with it you would anyway need CAN controller, bus driver, chrystal and some capacitors or ready CAN-BUS shield.
Title: Re: NMEA 2000 Shield
Post by: seamaster on Feb 04, 2017, 09:31 am
Timo,
thanks for the quick reply
Today I managed to buy Mega and Can Shield. I'm up and running with the CAN shield example sketch, but when i load your temperature sketch, and it compiled OK. I don't have the shield connected to NMEA2000 network yet, but I'm flying to the boat on Sunday and Monday I can test that. Will update with the next post... I'm sure I will have more questions...
Thanks again!

Title: Re: NMEA 2000 Shield
Post by: bgnad on Feb 07, 2017, 11:19 pm
Is anyone working on converting automotive CAN bus data to NMEA2000, so one could use the engine interments on a marine multifunction display while using it as an offroad chart reader?
Title: Re: NMEA 2000 Shield
Post by: seamaster on Feb 09, 2017, 12:03 am
I'm having success outputting to my boats n2k bus after following Timo's documention.
I think it will be relatively easy to adopt the sample code to output different analog values, e.i. temperature, rpm, angle (from pot signal) etc.
One question I have is can I, or how do I combine sensors that I can use one CAN shield and one Mega board to output different class devices. For example, can I output battery monitoring/status PGNs, combined with refrigerator and freezer temperatures and engine and generator rpm, temp, etc. I hope I explained what my goal is... instead of using 3 arduino boards and 3 CAN shields, I would like to combine the functionality in one. Is that possible, or will each class device require separate hardware?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 09, 2017, 02:59 pm
First answer for your last question: as far as I know, each class does not need to be published. So I mean that you can just choose e.g. class 25 (Inter/Intranetwork Device) and 132 (Analog to NMEA 2000 Gateway). I have not yet heard MFD device, which would not show information from wrong class device. They are more interested just about data nodes will send. I have not either saw MFD device, which would show Device/Class information. Normally they just show manufacturer, ModelSerialCode and ProductCode etc. (information from SetProductInformation).

I had plans about functionality to have device separation on library. You are the first one who is asking this. You can see e.g. SetMode has DeviceIndex parameter. That was planned for handling multiple device/class on same code. But then we would also need DeviceIndex for SetProductInformation and SetDeviceInformation. You would send message with SendMsg(N2kMsg, DevIndexBatteryMonitor); So if that would be important, I could continue to develop that, but it is not mandatory by bus.

As more problematic I would see wireing all sensors from engine, refridgerator etc. to one mega board. I have added several Teeansy boards, which is rather small package (see my example https://github.com/ttlappalainen/NMEA2000/blob/master/Examples/TeensyActisenseListenerSender/Documents/Teensy_Actisense_listener_sender.pdf) and then just wired N2kBus.
Title: Re: NMEA 2000 Shield
Post by: flemmingdjensen on Feb 15, 2017, 09:04 pm
Hi timolappalainen!

First of all - thank you very much for these libraries for Arduino.

I have a project currently where I use an ESP8266 connected with the MCP2515 shield.

I am using the ActisenceSenderListener example and the NMEA Simulator to try and output NMEA2000 packets on can-bus.

I have not connected any bus to the H / L pins of the MCP2515 shield yet.

When I start the firmware I can see the first sentences goes fine but then all following messages fails...

See my console log...

Any idea what is going wrong? Is the library compatible with ESP8266? I'm not using interrupt for the MCP2515 as I am only sending data. CS is software controlled on GPIO15 on the ESP8266 CLK, MISO, MOSI is connected to the recommended perip pins.


0x2d
csum 0x2d
v09f0c112
~ld

CAN device ready
Pri:6 PGN:126996 Source:13 Dest:255 Len:134 Data:14,5,9A,2,4E,4D,45,41,32,30,30,30,20,73,69,6D,75,6C,61,74,6F,72,20,47,50,53,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,31,30,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,30,39,37,31,35,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
Pri:6 PGN:130312 Source:17 Dest:255 Len:8 Data:0,0,0,8F,70,FF,FF,FF
Pri:6 PGN:130316 Source:17 Dest:255 Len:8 Data:0,1,D,52,81,4,8C,B
Pri:6 PGN:126996 Source:13 Dest:255 Len:134 Data:14,5,9A,2,4E,4D,45,41,32,30,30,30,20,73,69,6D,75,6C,61,74,6F,72,20,47,50,53,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,31,30,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,30,39,37,31,35,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
PGN 126996, frame:17/20 send failed
Pri:6 PGN:130312 Source:17 Dest:255 Len:8 Data:0,0,0,8F,70,FF,FF,FF
PGN 130312 send failed
Pri:6 PGN:130316 Source:17 Dest:255 Len:8 Data:0,1,D,52,81,4,8C,B
PGN 130316 send failed
Pri:6 PGN:126996 Source:13 Dest:255 Len:134 Data:14,5,9A,2,4E,4D,45,41,32,30,30,30,20,73,69,6D,75,6C,61,74,6F,72,20,47,50,53,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,31,30,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,30,39,37,31,35,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
PGN 126996, frame:0/20 send failed
Pri:6 PGN:126996 Source:14 Dest:255 Len:134 Data:14,5,9A,2,4E,4D,45,41,32,30,30,30,20,73,69,6D,75,6C,61,74,6F,72,20,4C,6F,67,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,31,30,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,30,39,37,31,35,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
PGN 126996, frame:0/20 send failed
Pri:6 PGN:126996 Source:16 Dest:255 Len:134 Data:14,5,9A,2,4E,4D,45,41,32,30,30,30,20,73,69,6D,75,6C,61,74,6F,72,20,57,69,6E,64,20,6D,65,74,65,72,0,0,0,31,2E,32,2E,30,2E,31,30,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,30,39,37,31,34,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
PGN 126996, frame:0/20 send failed
Pri:6 PGN:126996 Source:17 Dest:255 Len:134 Data:14,5,9A,2,4E,4D,45,41,32,30,30,30,20,73,69,6D,75,6C,61,74,6F,72,20,6F,75,74,73,69,64,65,20,65,6E,76,69,72,31,2E,32,2E,30,2E,31,30,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,30,39,37,31,34,38,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
PGN 126996, frame:0/20 send failed
Pri:6 PGN:126996 Source:18 Dest:255 Len:134 Data:14,5,9A,2,4E,4D,45,41,32,30,30,30,20,73,69,6D,75,6C,61,74,6F,72,20,65,6E,67,69,6E,65,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,31,30,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,30,39,37,31,34,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
PGN 126996, frame:0/20 send failed
Pri:6 PGN:126996 Source:19 Dest:255 Len:134 Data:14,5,9A,2,4E,4D,45,41,32,30,30,30,20,73,69,6D,75,6C,61,74,6F,72,20,66,6C,75,69,64,20,6C,65,76,65,6C,0,0,31,2E,32,2E,30,2E,31,30,39,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,2E,32,2E,30,2E,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,30,39,37,31,34,36,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
PGN 126996, frame:0/20 send failed
Pri:6 PGN:130306 Source:16 Dest:255 Len:6 Data:0,F4,1,59,C4,0
PGN 130306 send failed
Pri:6 PGN:130311 Source:16 Dest:255 Len:8 Data:0,41,97,72,78,37,F5,3
PGN 130311 send failed
Pri:6 PGN:130312 Source:17 Dest:255 Len:8 Data:0,1,4,55,73,55,73,FF
PGN 130312 send failed
Pri:6 PGN:130312 Source:17 Dest:255 Len:8 Data:0,1,4,55,73,55,73,FF
PGN 130312 send failed

BR Flemming Dahlhof Jensen
Title: Re: NMEA 2000 Shield
Post by: flemmingdjensen on Feb 15, 2017, 09:33 pm
I just attached a logic analyser and can see endless loop retransmitting the following....

Pri:6 PGN:126996 Source:13 Dest:255 Len:134 Data:14,5,9A,2,4E,4D

So this retransmitting seems to prevent sending the next sentences...
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 16, 2017, 06:19 am
Do you mean example ActisenseListenerSender? That has been tested to work only on Due, since it uses two USB:s - one for sending and other for listening. I had problems with single USB that it stops responding, when you are sending and reaceiwing binary data throug it. But this should not be your case.

Are you writing with NMEA Simulator? It may be that sending buffers will overflow and it can not send all messages. You coud try add NMEA2000.SetN2kCANSendFrameBufSize(500); on beginning of setup(). Note that value 500 is frames, so this is taking 4k of memory. So you have to adjust value according to your memory. Default is 40 as documentead.

But also I am not sure that does MCP2515 chip fail to send anything, if it is not connected to the bus. Then everything will be just bufferd, until it fills out and start to give error.

Also if you using NMEA Simulator, you can disable sending product information for each device. I prefer to first test with one device and one PGN and then add PGNs.
Title: Re: NMEA 2000 Shield
Post by: flemmingdjensen on Feb 16, 2017, 08:53 am
I had to modify your sketch slightly in order for it to work on my setup.

So I am using a NodeMCU ESP8266 with 4MByte flash.
Using the std com port as programming interface and normal Serial output for debugging
I then attach one more USB serial and drive this throught the software Serial driver.
This software serial is now receiving the messages from the NMEA Simulator
Im not using interrupts

I have to modify NMEA2000_mcp.cpp because there is no SREG on the ESP8266

So I use noInterrupts() & interrupts() instead for the ESP8266.

In my logic analyser it seems like the 2515 is repeating the last frame (8 bytes) over and over again.

I have read an errata on the chip mentioning that CS should go hi within 78us after the last transmission or the chip could begin repeating.

I will try upping my transmit buffer as you suggested later today.

My sketch is looking like this:

=============================

// Demo: NMEA2000 library. Bus listener and sender.
//   Sends all bus data to serial in Actisense format.
//   Send all data received from serial in Actisense format to the N2kBus.
//   Use this e.g. with NMEA Simulator (see. http://www.kave.fi/Apps/index.html) to send simulated data to the bus.

#define USE_N2K_CAN 1
#define N2k_SPI_CS_PIN 15
#define USE_MCP_CAN_CLOCK_SET 16
//#define N2k_CAN_INT_PIN 4

#include <Arduino.h>
#include <N2kMsg.h>
#include <NMEA2000_CAN.h>
#include <ActisenseReader.h>
#include <SoftwareSerial.h>

tActisenseReader ActisenseReader;

SoftwareSerial swSer(2, 0, false, 256);

void setup() {
  Serial.begin(115200);
  swSer.begin(115200);
 
  NMEA2000.SetForwardStream(&Serial);  // PC output on due programming port
  NMEA2000.SetMode(tNMEA2000::N2km_SendOnly);
  NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text
  NMEA2000.Open();

  // I had problem to use same Serial stream for reading and sending.
  // It worked for a while, but then stopped.
  ActisenseReader.SetReadStream(&swSer);
  ActisenseReader.SetMsgHandler(HandleStreamN2kMsg);
}

void HandleStreamN2kMsg(const tN2kMsg &N2kMsg) {
  N2kMsg.Print(&Serial);
  NMEA2000.SendMsg(N2kMsg,-1);
}

void loop() {
  NMEA2000.ParseMessages();
  ActisenseReader.ParseMessages();
}
Title: Re: NMEA 2000 Shield
Post by: flemmingdjensen on Feb 16, 2017, 09:22 pm
SUCCESS!!!!

Now I build a complete setup!
NMEA2000 Simulator -> ESP8266 -> MCP2515 -> CAN-BUS -> MCP2515 -> ESP8266

And guess what.... It works :)

So I guess the reason for the errors in transmission was because I didn't have a complete CAN-BUS setup...

Title: Re: NMEA 2000 Shield
Post by: WheelSea on Feb 17, 2017, 11:32 pm
Kudo's to you timolappalainen,
That was a lot of work on your part.

I have my arduino (Mega + 2515) up and running and I am very impressed so far with all the coding on your part. My 2515 was 8mhz and that took a little trouble shooting.   Being able to output to the terminal and NMEA 2000 simultaneously solved a lot of problems.  I had a lot of trouble with my other NMEA devices not being able to read 130316, Temperature for EGT.  This being the Actisense NGT-1 USB and the iKommunicate and Raymarine I70.  All my work is being done at home prior to any installation on the boat.
So far I have output voltages for 3 batteries voltages  and 3 environment temperatures and 1 EGT.  Adding 3 more EGT's should be easy.  I need 4 EGT's total.  Twin engine and a turbo on each side of each engine.

It should be straight forward to apply all the other sensors to the engines now.  I will probable use a few arduino's to do so, one for temp the other pressure, resisitive etc.

Has anyone coded for a display?  Having your own helm display.

Thinking I may do just that with my 5 inch Nextion NX8048T050 TFT display.
Any advice that someone wants to share

Larry
Title: Re: NMEA 2000 Shield
Post by: seamaster on Feb 18, 2017, 06:35 am
Hi Timo,
Thanks for the response! I was occupied trying to rebuild my nav-PC as my M2 SSD in my intel NUC just decided to quit.
I'm back on the project now and I will try to source some parts to build few different units. I do agree- separate units will be cleaner to install.
On different note: Is there some PGN that reports bilge pumps cycles in the Nmea 2k? I have some n2k documentation that I can send you in email. Send me your email address so I can fwd you what I have.
 My is MVseawitch at gmail. Send me quick email and I will fwd you what I have.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 18, 2017, 08:34 am
SUCCESS!!!!

Now I build a complete setup!
NMEA2000 Simulator -> ESP8266 -> MCP2515 -> CAN-BUS -> MCP2515 -> ESP8266

And guess what.... It works :)

So I guess the reason for the errors in transmission was because I didn't have a complete CAN-BUS setup...


Good that you got it running. I have to design a way for NMEA2000_mcp to avoid SREG problem.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 18, 2017, 09:09 am
It should be straight forward to apply all the other sensors to the engines now.  I will probable use a few arduino's to do so, one for temp the other pressure, resisitive etc.

Has anyone coded for a display?  Having your own helm display.

Thinking I may do just that with my 5 inch Nextion NX8048T050 TFT display.
Any advice that someone wants to share

Larry
[/quote]
Hi Larry and all,

I quickly looked in to the Nextion and it has same problem as with all these cheap displays - only max 250 nits. I think that for outside you need 600 nits or even more. Sunlight readable systems are normally providing 800-1300 nits.

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.
Title: Re: NMEA 2000 Shield
Post by: WheelSea on Feb 19, 2017, 08:22 pm

Thanks for the reply,
I am going to abort doing a display.  This was purchased for use inside the boat on the watermaker.  Instead I will find a sunlight readable monitor and use a windows based machine.  Actisense will be coming out with an update to NMEA 2000, soon I hope.  Going to look at building the arduino actisense reader, I have not looked at the code to see what it may output.  Starting to read up on OpenSkipper?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 20, 2017, 06:47 am
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)
Title: Re: NMEA 2000 Shield
Post by: seamaster on Feb 21, 2017, 05:30 am
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?
 
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 21, 2017, 07:46 am
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.
Title: Re: NMEA 2000 Shield
Post by: seamaster on Feb 21, 2017, 08:06 am
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)
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 21, 2017, 08:11 am
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.
Title: Re: NMEA 2000 Shield
Post by: seamaster on Feb 21, 2017, 08:26 pm
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?


Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 21, 2017, 09:04 pm
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.
Title: Re: NMEA 2000 Shield
Post by: seamaster on Feb 26, 2017, 06:42 am
Hi Timo,
Excuse my ignorance but I'm not exactly clear what sources I need to download?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 27, 2017, 06:39 am
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.
Title: Re: NMEA 2000 Shield
Post by: flemmingdjensen on Mar 19, 2017, 08:44 pm
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?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Mar 20, 2017, 06:40 am
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.
Title: Re: NMEA 2000 Shield
Post by: flemmingdjensen on Mar 20, 2017, 08:57 pm
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
Title: Re: NMEA 2000 Shield
Post by: r2d290 on Apr 12, 2017, 10:51 pm
Alright, my turn to try to get this working. Some struggles, so any help would be highly appreciated.

Hardware Setup:

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.



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");
  }
}


Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 13, 2017, 07:37 am
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
Title: Re: NMEA 2000 Shield
Post by: r2d290 on Apr 13, 2017, 11:47 am
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");
  }
}


Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 13, 2017, 01:07 pm
Sorry I did not read it carefully. I read that it was #define N2k_CAN_INT_PIN 10, which would define that pin 10 will be used for interrupt. You must have #define N2k_SPI_CS_PIN 10 (or 9) for UNO.

You do not need interrupt wire for communication. In tha case you must not have #define N2k_CAN_INT_PIN xx as you do not. Interrupt is critical, if you read bus data, because otherwise you will easily loose data.

Do you have UNO connected to the bus? Since you have NGT, I'll prefer to connect UNO and NGT to the bus with right terminator resistor. Leave MFD out at this moment. Then you can read bus traffic via NGT. I also prefer to change NGT to read oll messages instead of filtering anything. This you select on NMEA Reader. Since you now have:
NMEA2000.EnableForward(false);
That disables all message forwarding to USB. So it won't print any messages anymore.
You could also uncomment
NMEA2000.SetForwardType(tNMEA2000::fwdt_Text);
So it will show something as clear text.

So if you do not see any messages sent by UNO on NMEA Reader, then you have to really debug, what goes wrong with UNO. You can search println on NMEA2000.cpp and uncomment those in some places and see, if you find place, where it stops. As I mentioned I do not have UNO, you have to do the tests.
Title: Re: NMEA 2000 Shield
Post by: r2d290 on Apr 13, 2017, 09:07 pm
Hello

Thanks for the reply and clarification regarding interrupt. I've left the boat now, but I'm eager to get back with more information within a few days.

Quote
Do you have UNO connected to the bus?
I'm not totally clear on this question. If the "bus" is defined by the thing on the boat that looks like:
TTTTT (the thing that the MDF, the CD-player and my NGT is connected to), then yes - the Arduino is connected to the bus, but via the NGT. Or did you mean the MOD-bus shield? Then yes, the Modbus-shield is connected to the pins in the UNO.

So: MFD<-->TTTT <--NGTcabel--NGT--NGTcabel(with DB9-connector)-->Modbus-shield <--> Arduino <--> USBcabel --> PC.

And when I was reading from the entire system with NGT, it was like:
MFD<-->TTTT <--NGTcabel--NGT--NGTcabel(with DB9-connector)--> <--DB9toUSB-cabel--> PC.

Hope this made sense. If not, please ask for clarification :)

Quote
Since you have NGT, I'll prefer to connect UNO and NGT to the bus with right terminator resistor. Leave MFD out at this moment. Then you can read bus traffic via NGT
Do you mean that I can connect my UNO (or do you mean the MOD-BUS DB9-connector?) to to the TTTTT in the boat, without using the NGT in between? That would be too awesome. How is that done? Do I need a special cabel or something, since the Mod-Bus shield has a DB9-connector, and the TTTTT has a circular connector with 5 pins. What does the NGT-1 even do, btw? I thought it was kind of "decrypting" the NMEA-2000 signal to a serial-signal.

Btw: What is the "right" terminator resistor, and where is this supposed to be placed?
If I don't remember totaly wrong, there is already a resistor at the end of the TTTTT. Does this have anything to do with it?

I have TeamViewer to the computer on the boat, so I tried what you said regarding changing filtering in NMEA Reader. I could not find this option. The closest I found was Edit -> Preferences -> Transfer: Receive All, but this option was disabeled by a reason? See attached pic.

Code: [Select]
NMEA2000.EnableForward(false);
That disables all message forwarding to USB. So it won't print any messages anymore.

The only thing it prints to the Serial monitor is my Serial.println()-lines. But (and this might be important?) before I added this line, it only printed rubbish - mostly squares without line break. I have tried all the baude-rates on the serial-monitor, but I assume the correct is 115200. Is it supposed to print anything else than rubish to the Serial-monitor?
But - even with that line, I'm still abel to read things on the NMEA-reader through the USB-cabel when the Arduino is set to debug-mode..

Quote
You could also uncomment
NMEA2000.SetForwardType(tNMEA2000::fwdt_Text);
So it will show something as clear text.
Well, yes - it returned "something" as clear text now, but still a lot of rubbish. See attached picture.
Actually - I think the rubish is printed regardless of the EnableForward(false)-line.

Quote
As I mentioned I do not have UNO, you have to do the tests.
I will be more than happy to do some troubleshooting with this - If you can only get me started with the part with connecting the Arduino to the bus without the NGT, so that I can use the NGT to troubleshoot with.

Again, thanks a lot!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 14, 2017, 06:57 am
I am sorry to tell you that you have understood this a bit (or maybe a lot) wrong. The bus means NMEA 2000 bus - see e.g. image on bottom of page http://www.actisense.com/products/nmea-2000/ngt-1/ngt-1. Devices on bus we can call just device or also as node sometimes. Each device on bus will get own address or also called source on code. Bus is similar as street, which has houses each with own number so that post knows where to deal messages (=letters).

So now you have MDF. This is one device. NGT is an other device. On picture there are also wind and log sensors. They both are own devices. All has been connected together with bus cable, which actually has two communication wires CAN L (blue wire) and CAN H (white wire) Other three wires on bus cable are shield (gray), 0 V (black) and 12 V (red). There is no magic with this cable. If you like to save expensive  NMEA2000 connectors, you can search DeviceNet connectors and you will find same stuff. Or you can even just cut the cable and use screw terminals.

The point of my NMEA 2000 library is to make device that connects directly to the bus (CAN L and CAN H). And if you like you can also take power for the board from the bus, if you have right voltage converter like UNO has. So to connect UNO to the bus is similar as my schema https://github.com/ttlappalainen/NMEA2000/blob/master/Documents/ArduinoMega_CAN_with_MCP2515_MCP2551.pdf. And if you do not want to glue MCP2515, MCP 2551 and other stuff yourself, you should buy http://wiki.seeed.cc/CAN-BUS_Shield_V1.2/.

So you configuration, where you have UNO with MODBUS shield can not work at all, since the communication on N2k bus (=NMEA 2000 bus) is different than on serial on the other side of NGT. No I do not actually understand, why lower level library mcp_can even reports that communication opens, if you have wrong shield!

When you have right shield, you connect your UNO just an other device as in picture I mentioned above. And the termination resistors marked by A2K-TER-F on picture are just 120 ohm resistors on nice (and expensive) package.

If your NGT id not tightly srewed to the boat, take it with you to home and you can start to develop system at home. Then buy CAN bus shield and connect it to NGT on N2k side. Also connect termination resistors to your short bus - for short test bus one is enough. Then connect NGT ont the serial side to PC with serial to USB as you had. And finally connect UNO USB to PC. Now with TemperatureMonitor example you have bus system with two devices - UNO and NGT. With NMEA Monitor you should see what your TempertureMonitor (UNO) sends to the bus. When taht works, you can go to the boat and connect them to same bus with MFD, and you should see TemperatureMonitor as a device on MFD device list.

And some answers:
- Yes, you can connect UNO to TTTTT with CAN bus shield.
- You do not need special cable. As I mentioned, you just need to connect CAN L and CAN H on shield to related wires on the bus. Or you can by NMEA 2000 T-bone and suitable connectors.
- Yes, NGT converts NMEA 2000 to Actisense serial format, which I also use in my library on PC side communication. E.g. Maretron uses a bit different encoding. You need NGT to get data to PC. You you can use Arduino DUE or Mega or Teensy with my example ActisenseReader.
- Terminal resistors has to be on both end of the bus. So you can have bus through the boat from aft to bow and devices connected on the middle (as in picture) with some T-connector. Terminals should then be on the aft and bow ends of the cable. Each cable from T-connector to device must not exceed 6 meters.

Have a nice eastern!
Title: Re: NMEA 2000 Shield
Post by: r2d290 on Apr 14, 2017, 10:09 am
Hello.
Thanks for your great reply. Now, things is starting to be a bit more clear.

Quote
So you configuration, where you have UNO with MODBUS shield can not work at all, since the communication on N2k bus (=NMEA 2000 bus) is different than on serial on the other side of NGT. No I do not actually understand, why lower level library mcp_can even reports that communication opens, if you have wrong shield!
I'm so sorry for the confusion. I don't know why I was suddenly start talking about Modbus-shield. I don't have a modbus-shield, I have - as you link to - a CAN-BUS Shield V1.2 :)

Actually, I think I will go back to the boat now, bring back a few NMEA2000 Connectors, the two terminal resistors, the ngt and the UNO with CAN-bus shield, and see what more I can do :)
Title: Re: NMEA 2000 Shield
Post by: r2d290 on Apr 14, 2017, 04:23 pm
Wohoo, I made it :) The MFD is now showing a water temperature of 15.5 degrees (Wished it was so well).
It was a bit easier when I did not have the NGT between the bus and the CAN-bus shield :)

Now, time to start experimenting with some real data. Thank you so much for your help :)
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 15, 2017, 05:57 am
Great you got it running. You could also test does it work with interrupt by defining right line with
#define N2k_CAN_INT_PIN xx
Since system has to handle all messages, without interrupt it may loose address claiming or ISO request messages, which MDF:s use time to time to check are devices alive. If you look MFD device list, your device may time to time disappear, if those messages has been missed. This is not critical for information like temperature, but like I have my Arduino as NMEA0183->NMEA2000 converter for GPS, my MFD start to alarm, if it looses device.

Please report, if you get your UNO system working and what exeptions there may be. With execptions I mean e.g. those buffer definitios etc.
Title: Re: NMEA 2000 Shield
Post by: xotet on May 07, 2017, 11:14 am
Hi Timo, first of all thanks for your work and thanks to share with all the comunity.

 It´s possible to adapt the library to work with arduino ZERO + CAN BUS shield? since is the same size factor than UNO and more powerfull??

 I´m planing my project wich consisit of a simple Tanks and Battery Monitor with an LCD on the main cabin.

 Thanks in advance



 
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 08, 2017, 05:25 am
Hi,

I do not see why not. The main problem with Uno was low memory, which could be fixed with buffer settings. So with Zero board you do not need to define smaller buffers.

I could not find information is CAN BUS shield compatible with Zero board. Please note that Zero uses 3.3 V IO. Also you need to check, which IOs are CS and int.

Have you checked https://hackaday.io/project/11055-kbox? It's nice hw with lot of ready functions.
Title: Re: NMEA 2000 Shield
Post by: xotet on May 11, 2017, 01:46 pm
Hi,

I do not see why not. The main problem with Uno was low memory, which could be fixed with buffer settings. So with Zero board you do not need to define smaller buffers.

I could not find information is CAN BUS shield compatible with Zero board. Please note that Zero uses 3.3 V IO. Also you need to check, which IOs are CS and int.

Have you checked https://hackaday.io/project/11055-kbox? It's nice hw with lot of ready functions.
Thanks Timo

 I found Kbox very interesting since include also a bridge to nmea0183 to nmea2000 and wifi hotspot, hopefully I can use with my AIS nmea0183.

Title: Re: NMEA 2000 Shield
Post by: seamaster on May 13, 2017, 09:11 am
Hi again guys!
after couple of months of other tasks I'm back on my project. everithing went well until i ran into problem, so i need your help to resolve it.
Here is my setup:
Simple bus with 2 devices made by me. each device is terminated with 120ohm resitor between Net-L and Net-H.
on the receiving side, Arduino Uno with CanBus shield running the Actisense_listener example code:
Code: [Select]

#define N2k_SPI_CS_PIN 10
//#define N2k_CAN_INT_PIN 21
#include <SoftwareSerial.h>
#include <Arduino.h>
#include <NMEA2000_CAN.h>
//SoftwareSerial mySerial(3, 4); // RX, TX
void setup() {
  Serial.begin(4800);
 //  mySerial.begin(38400);
  NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text
  NMEA2000.SetForwardStream(&Serial);  // PC output on due native port
 
  NMEA2000.Open();
}

void loop() {
  NMEA2000.ParseMessages();
// if (Serial.available()) {
 //   mySerial.write(Serial.read());

}




on the transmitting side Teensy 3.2 with MCP2551 running the Temperature monitor example code:

Code: [Select]


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

#include <Arduino.h>
#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,22);
  //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 1500

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");
  }
}



I have terminal program (CoolTerm) connected to the USB/Serial port on the Arduino Uno (listener) to monitor what will be coming over the N2K bus. When I connect to the port it shows me that:
See attachment called Coolterm1.png
(http://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=211714)
when I start the Teensy 3.2
and open the Serial Monitor to the Teensy USB/Serial port I get this

See attachment called Teensy_Monitor1.png
(http://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=211716)

on the receiving side (Arduino Uno board)  get this:
See attachment called Coolterm2.png
(http://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=211718)

unfortunately the reception stops right a way after few lines are received.
if i reset the Teensy board, it reboots and i receive few lines again on the Uno board. Please note I do not need to do, touch/reset/restart/disconnect-reconnect or any of this sort  to the uno board. I just leave it alone to wait for the next transmission from the Teensy board.

If i look at the serial monitor on the teensy side, i notice that it continue to send PGNs (or at-least looks that way for about a 30-45sec:

See attachment call Teensy_Monitor2.png

(http://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=211720)
and then it comes up with the message that one of the PGNs has failed to send.

I'm lost here... Im not sure if this is HW or software issue. Im thinking the HW is fine as few messages go through with no problem but then the translissin to the N2K buss seams to stop (no more bl=inks on the receive and transmit LEDs) while the serial monitor keep shows the PGNs being generated and flying by...

Is it a buffer of some kind that gets filled/blocked? I'm willing to run any tests to troubleshoot that issue but i have to admit, I think I'm way better with HW than with SW (please note i said "better", not "good"  :smiley-confuse: )  

Any help or any ideas how to fix that are appreciated!
 
I receive some PGN, but then it stops.. Why, oh why?

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 14, 2017, 07:40 am
First I prefer to switch Uno and Teensy sketches. Uno does not have not enough memory with default buffers. Read library issue https://github.com/ttlappalainen/NMEA2000/issues/20 and at least start from my post on 15.4.2017. Also use Serial.begin(115200); instead Serial.begin(4800); despite this is not the problem in this case.

As you see on your first two pictures sent and received PGN:s 60928 and 130312 messgaes does not match. So I expect there is already some memory overflow on Uno.

On your last picture I expect that Teensy will not actually send anything at all. As default library has 40 frame send buffer. So it can buffer 40 single frame messages like PGN 130312 and when this buffer becomes full, it will cause error "... send failed". Note that as default library will forward own messages to stream (=USB in your case), when they have been tried to send. It does not mean that they have been actually sent to bus. So now in your last case on Teensy CAN bus control logic tries to send messages without success. It is probably trying to wait bus as become free, but it is blocked for some reason.

Note also that library does not work with latest Teensy FlexCan library. See issue https://github.com/sarfata/NMEA2000_teensy/issues/5. But as you have managed to receive something on Uno, I expect that you do not have 1.35 or newer Teensyduino.
Title: Re: NMEA 2000 Shield
Post by: seamaster on May 16, 2017, 08:34 pm
Hi Timo,
Thanks for the reply and recommendations. One remark only for clarification - I did not take the screen grabs simultaneously, therefore there could be difference in the transmit and received PGNs captured. It doesn't necessary means that we have the data corruption on the UNO board.

After reading your post, here is what i did:

I made a new Teensy3.2 board with MCP2551 which I will call NEW TEENSY for the purpose of that post. it has the same connections as the original one I made.
The first teensy board that I made I will be calling ORIGINAL TEENSY
and the Arduino UNO with CAN shield I will be calling UNO
Test cases:
1. Benchmark
 a. UNO on the receiving side,
 b.  ORIGINAL TEENSY on the transmit side
Result 1: when i run the listener code on the UNO I get "CAN ready" on the serial monitor of the UNO. When I run "Battery monitor" example on the ORIGINAL TEENSY, I receive couple of PGNs on the UNO serial monitor, then it stoppes (as i explained in my previous post)
2. Test with the NEW TEENSY
 a. UNO on the receiving side,
 b.  NEW TEENSY on the transmit side
Result 2: when i run the listener code on the UNO I get "CAN ready" on the serial monitor of the UNO. When I run "Battery monitor" example on the NEW TEENSY, I receive couple of PGNs on the UNO serial monitor, then it stoppes. in my opinion both teensy boards behave identical..
3. Test TEENSY only boards as recommended by you:
 a. NEW TEENSY on the receiving side
 b. ORIGINAL TEENSY on the transmit side (same SW that successfully sens few PGNs to the UNO in the BEnchmark case)
Result 3:
the NEW TEENSY does not get anything on the serial monitor when i run the listener SW. I do not get the "CAN ready" message :(
When i run the The Battery Monitor on the ORIGINAL TEENSY, there is nothing showing up on the NEW TEENSY serial monitor
4. Test two TEENSY only boards (same as Test 3 but reversed board functions)
 a. ORIGINAL TEENSY receiving
 b. NEW TEENSY transminting
Result 4:
Same as Result 3 nothing on the receiving board serial monitor


So after doing all that I think that there is some problem either with the listener code, or with the HW receiving portion on the Teensy boards (both of them).
But what bugs me is that I'm not getting the "CAN ready" message... so it makes me think that its the SW implementation on the Teensy
Any comments?

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 17, 2017, 07:05 am
The examples I have published has been cross tested with Mega and Teensy boards with Arduino 1.81 and Teensyduino 1.35 except FlexCAN library has been from Teensyduino 1.33.

So I made cross test again but also updated Arduino IDE to 1.82 and Teensyduino 1.36. ActisenseListener on Mega and TemperatureMonitor on Teensy.
-> Listener works and listens messages from my Garmin MFD. Monitor does not send anything.

So I replaced "C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\FlexCAN" with http://www.kave.fi/Apps/Arduino/Teensy/FlexCAN.zip and rebuild all - !!NOTE!! rebuild all is important!
-> TemperatureMonitor now appears on Garmin and also messages appears on ActisenseListener in clear text.

Then I swithed ActisenseListener to Teensy and TemperatureMonitor to Mega. Again everything works fine.

So this proofs that both code works on Teensy and Mega. Important is  - what I mentioned earlier post - that you need old version of FlexCAN library.
Title: Re: NMEA 2000 Shield
Post by: seamaster on May 17, 2017, 06:14 pm
Hi Timo,
thanks for the help!
I'm glad to report that the problem is solved. After i read your latest post i went to "manage my libraries" checked my installed libraries. I found two instances of FlexiCAN. One was listed under legacy in the application container (MAC) and the other one under mydocuments\ARDUINO\libraries.
I did remove both and then added zip file FlexiCAN library.
Success!
Off I go to the next step - buy my new Simrad EVO3 display to replace my failed Furuno depth-sounder, so I can continue my pet project :)
Thanks a lot again!
(http://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=212263)
Title: Re: NMEA 2000 Shield
Post by: seamaster on May 26, 2017, 02:35 am
Hi all,
here is a brief update:
yesterday I received my Simrad NSS9 EVO3 display. Last night i hooked up the teensy 3.2 and MCP2551 to it and ran some battery monitor code on it and it works! it's great that all proof of concept worked well, with little hiccups... now the real work should start.

Next is to design the proper schematic, board layout, and of course write the software.
I'm planning to have at least 4 temp probes inputs (TMP36), 6X 0V-30V  inputs and 2X 16bit 0V-3.3V inputs to measure current with 500uV shunts
One issue that I noticed is that simple resistor divider does not work that great as i get some noise on the readings. Someone helped me write some code for running average and the readings are much smoother now, but i would prefer to add some RC filtering on the input pins as well.

I noticed also that the MFD will not display what I put in the manufacturer information. it always states "Manufacturer: Unknown"
shouldn't it display
"Manufacturer: SeaNav"
based on the example code below?
Code: [Select]

const tNMEA2000::tProgmemConfigurationInformation BatteryMonitorConfigurationInformation PROGMEM={
                                       "SeaNav, john.doe@unknown.com", // Manufacturer information
                                       "First attempt", // Installation description1
                                       "No real information send to bus" // Installation description2
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 26, 2017, 05:28 am
Unfortunately NMEA 2000 devices rely only manufacturer code set by last parameter of SetDeviceInformation. List of codes can be found by googling e.g. "NMEA 2000 Manufacturer Code - Product Code" So the code 2046 I have in examples is the biggest possible value. Note also that if you have old NMEA 2000 device, which can not be updated anymore, it will also show "unknown manufacturer" for newer manufacturers. This is one (of many) stupid thing on closed NMEA 2000 standard.

So you have 3 choices:
1. Do not care.
2. Use some registered code on list and it will show you that manufacturer.
3. Register youself as manufacturer and your device. The costs are only something like 9000-15000 dollars.
Title: Re: NMEA 2000 Shield
Post by: bwz0 on Jun 13, 2017, 01:08 pm
Is a CAN-shield with MCP2515 & MCP2551 the recommended way to go or should I look for something else? Any opinions on which one has the best quality?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 13, 2017, 01:55 pm
If you will use my NMEA 2000 library, I prefer to system with at least 8 kB RAM. You can use Arduino Mega with CAN-shield. Arduino Due and Teensy 3.2 has more RAM to use. Also Teensy uses less power. For Teensy check issue 50 under my library. If you are handy and can make your own soldering, you can use schemas under library documentation. For easy way to use teensy there is "Teensy CAN-Bus Breakout Board Include Teensy 3.2".
Title: Re: NMEA 2000 Shield
Post by: seamaster on Jun 13, 2017, 07:11 pm
I'm just finishing new PCB with teensy 3.2, 8 analog 0-30V DC inputs and 4 temp inputs for TMP36 sensors providing GND, 3.3VDC and signal connection. It also have protected CAN interface mcp2551 and m12 n2k connector to directly plug into N2K network with or without termination. My prototype is working very well and I can't wait to get the first 3 boards. On the weekend I also added a compass module to the prototype, but did not have the properly tilt compensated board so it was just proof of concept. It worked well, at least as well as not tilt compensated compass could work. I ordered some 10 DOF boards and maybe in the future will have inexpensive rate compass with N2K output as well.
After the first boards are done I'm planing to develop different version with analog amplifier for measuring thermocouple to measure EGT.
I also need to figure out how to measure 0-1V positive as well as negative voltage to have an implementation for measuring battery shunt.
If there is an interest for these boards I will plan for larger run in the future.
If there is other ideas of what other interfaces are needed, please let me know.
Timo,
as soon as I have the hardware made, I will send you one of my first 3 populated boards as a tocken of appreciation for he hard work you've done to make that project possible.
Cheers!
Title: Re: NMEA 2000 Shield
Post by: bwz0 on Jun 13, 2017, 08:28 pm
If you will use my NMEA 2000 library, I prefer to system with at least 8 kB RAM. You can use Arduino Mega with CAN-shield. Arduino Due and Teensy 3.2 has more RAM to use. Also Teensy uses less power. For Teensy check issue 50 under my library. If you are handy and can make your own soldering, you can use schemas under library documentation. For easy way to use teensy there is "Teensy CAN-Bus Breakout Board Include Teensy 3.2".
Thank you! Will your library also work with the Teensy 3.6 and the "Dual CAN-Bus adapter for Teensy 3.5, 3.6" https://www.tindie.com/products/Fusion/dual-can-bus-adapter-for-teensy-35-36/ ?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 13, 2017, 09:08 pm
Thanks. It is really nice to see that people has started to use library for real devices. Maybe we could in future have simple and cheap NMEA 2000 devices available.

I personally prefer small sized simple devices spreaded around. It is rather hard to organize centralize cabling to one point for everything. With the central cabling there is also problem with noise specially with analog signals. So instead use idea of NMEA 2000 bus so that you would have bus cable through the boat and then e.g. one "sensor device" on each tank or battery. E.g. Maretron already have small tank sensor.

Also I like more simple header connector as used in DeviceNET (see on Farnell codes 1717025 and 1717013) instead of expensive NMEA 2000 connector, which also takes a lot of space. I have made several split boxes with those for price of one "real" connector. My 5 connector splitbox requires only about 45x100x40 box.

Then if you are sailor, you may think that 10 small Teensy will take too much power. For slow data like tank and battery sensors they could measure value e.g. every minute and send it to the bus and then goto low power sleep. To arrange that one needs one master, which collects data and forwards it to bus every second or two to keep MFD happy. When I have time, I'll make sample for that.

Hopefully you got ideas of my opinions.

And I'll be happy, If I will get one board. I could replace my "Alba Combi" with it. You can send me private post for further information.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 13, 2017, 09:28 pm
Thank you! Will your library also work with the Teensy 3.6 and the "Dual CAN-Bus adapter for Teensy 3.5, 3.6" https://www.tindie.com/products/Fusion/dual-can-bus-adapter-for-teensy-35-36/ ?
It may require new class instead of old NMEA2000_Teensy. I'll try to study it.
Title: Re: NMEA 2000 Shield
Post by: bwz0 on Jun 14, 2017, 12:24 am
It may require new class instead of old NMEA2000_Teensy. I'll try to study it.
I ordered it, so I'll try to let you know when I get around to try it in a few weeks time.
Title: Re: NMEA 2000 Shield
Post by: seamaster on Jun 16, 2017, 10:40 am
Hi Timo,
I have one NSS9 Evo3 Simrad MFD and i just got from Ebay AC42 simrad autopilot computer that i interfaced to the MFD. I added Heading and Rudder Angle output from the Teensy prototype board and at first it all appears good. I can read the heading and the rudder angle on the MFD. then I tried to commission the autopilot and as a part to the there is a sequence that one needs to perform to set the hard over to hard over limits. With my little cheat board with potentiometer on one of the analog inputs i could perfectly simulate rudder movement. the MFD shows me the rudder going to port and then to Starboard, then I center it as the calibration routine for the AP requires, but unfortunately the rudder calibration never completes, therefore I cant continue with the AP commissioning. Im sure you are wondering why i am asking you that, as you probably don't have the same AP and the chances are you don't know what the issue is, but I wanted to pick your brain on rudder PGN.
I did some digging and i found out that the MFD that controls the AP could be seeing the rudder angle but the PGN overall is not what it expects to see, and that's why the rudder calibration fails.
The way I understand your code, for rudder angle in N2kMessages.h you have:

Code: [Select]

// Rudder
// Input:
// - RudderPosition         Current rudder postion in radians.
// - Instance               Rudder instance.
// - RudderDirectionOrder   See tN2kRudderDirectionOrder. Direction, where rudder should be turned.
// - AngleOrder             In radians angle where rudder should be turned.
// Output:
//  - N2kMsg                NMEA2000 message ready to be send.
void SetN2kPGN127245(tN2kMsg &N2kMsg, double RudderPosition, unsigned char Instance=0,
                     tN2kRudderDirectionOrder RudderDirectionOrder=N2kRDO_NoDirectioOrder, double AngleOrder=N2kDoubleNA);

inline void SetN2kRudder(tN2kMsg &N2kMsg, double RudderPosition, unsigned char Instance=0,
                     tN2kRudderDirectionOrder RudderDirectionOrder=N2kRDO_NoDirectioOrder, double AngleOrder=N2kDoubleNA) {
  SetN2kPGN127245(N2kMsg,RudderPosition,Instance,RudderDirectionOrder,Angle Order);
}



so my conclusion was to write something like:

Code: [Select]



void SendN2KRudder() {
#define rudderUpdatePeriod 100
  static unsigned long RudderUpdated = millis();
  tN2kMsg N2kMsg;

  if ( RudderUpdated + rudderUpdatePeriod < millis() ) {
    RudderUpdated = millis();


    SetN2kRudder(N2kMsg, (avg2 / 2 - 280) / 3.14 / 18), 0); //avg2 is just function to read the pot and some random math to get my reading convert to rad angle that represents -40 to +40 deg


    NMEA2000.SendMsg(N2kMsg);
    delay (10);

  }
}


as I mentioned earlier it kind of works but can't complete the rudder calibration sequence. I called simrad tech support and they ask me to reset the AP settings and the MFD setting which i did later on, but it did not help.


then I start doubting the validity of the PGN I was  outputting and experimented with passing more to the function (as you see fro my code I am passing only the rudder angle in rad and the instance number). once i added more then these two parameters, I got en error compiling.  Regardless I continued digging and found something that really got me to write you this message. In your code the first parameter  to output is the rudder angle followed by the instance number, etc, ets,
I did find the string for PGN127245 here:
http://www.nmea.org/Assets/july%202010%20nmea2000_v1-301_app_b_pgn_field_list.pdf (http://www.nmea.org/Assets/july%202010%20nmea2000_v1-301_app_b_pgn_field_list.pdf)

and at least to me looks that it has different order the definition in your code:

PGN 127245   Field Field Description
Rudder order command in direction or angle with current rudder angle reading.
1 Rudder Instance
2 Direction Order
3 Reserved Bits
4 Angle Order
5 Position
6 Reserved Bits

Do you have an example outputting
PGN 127245, while passing all parameters such as RudderDirectionOrder and RudderDirectionOrder?
just in case here is the link to the AP manual http://www.simrad-yachting.com/Root/Installation%20Manual/SimradYachting/English/AC12_AC42_IM_EN_20222568_E_w.pdf (http://www.simrad-yachting.com/Root/Installation%20Manual/SimradYachting/English/AC12_AC42_IM_EN_20222568_E_w.pdf)
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 16, 2017, 11:49 am
First do not compare order of c++ function parameter list and the order of PGN definition. The point is that since you normally do not need all parameters, why you should have them in that order on function? If you want to compare, you have to goto look into the function code. But I think you do not need to, since I have tested rudder PGN against Actisense NMEA Reader as I allways do with new PGNs. Also, if data would be wrong, you would not see any rudder angle on your MFD.

Then about calibration. There are two possibilities:
1. AP expects also direction order (and order angle) parameter set right.
2. AP expects specific Simrad rudder sensor and tries to calibrate that with proprietary command, which we do not have any information.

Case 1 you can test, if you calculate from changes right value for the direction order and put some value for direction angle.

Case 2 is complicate, since you should do reverse engineering with full Simrad system. Can be time consuming.

It is also possible that AP uses standard Group Function commands to set direction order fields for you Teensy. If you have latest library version, it will automatically respond for that command with "no support". But it may be that AP is not either happy for that. You can listen data with some device - even with your Teensy by using mode N2km_ListenAndNode and enable forwarding. Then you look does AP send any 126208 PGN:s (Group Function PGN) to your device.

Offset you can easily program to your Teensy, but can you manually set hard limits. If you can, then you could forget automatic calibration.
Title: Re: NMEA 2000 Shield
Post by: seamaster on Jun 17, 2017, 11:59 am
Hi Timo,
thanks for the reply.
I did spend all night again looking at the possible solution
I noticed that the the new library required me to change 
Code: [Select]


const tProductInformation BatteryMonitorProductInformation PROGMEM={
                                       1300,                        // N2kVersion
                                       192,                         // Manufacturer's product code
                                       "SeaWitch_Monitor",    // Manufacturer's Model ID
                                       "1.0.0.13 (2016-09-19)",     // Manufacturer's Software version code
                                       "1.0.0.0 (2015-08-03)",      // Manufacturer's Model version
                                       "12340002",                  // Manufacturer's Model serial code
                                       1,                           // SertificationLevel
                                       1                            // LoadEquivalency
                                      };                       

to
Code: [Select]

const tNMEA2000::tProductInformation BatteryMonitorProductInformation PROGMEM={
                                       1300,                        // N2kVersion
                                       192,                         // Manufacturer's product code
                                       "SeaWitch_Monitor",    // Manufacturer's Model ID
                                       "1.0.0.13 (2016-09-19)",     // Manufacturer's Software version code
                                       "1.0.0.0 (2015-08-03)",      // Manufacturer's Model version
                                       "12340002",                  // Manufacturer's Model serial code
                                       1,                           // SertificationLevel
                                       1                            // LoadEquivalency
                                      };                       


and

Code: [Select]

const tNMEA2000::tProgmemConfigurationInformation BatteryMonitorConfigurationInformation PROGMEM={
                                       "SeaNav, john.doe@unknown.com", // Manufacturer information
                                       "First attempt", // Installation description1
                                       "No real information send to bus" // Installation description2
                                      };


to
Code: [Select]

const char BatteryMonitorManufacturerInformation [] PROGMEM = "John Doe, john.doe@unknown.com";
const char BatteryMonitorInstallationDescription1 [] PROGMEM = "Just for sample";
const char BatteryMonitorInstallationDescription2 [] PROGMEM = "No real information send to bus";



in order to compile properly. I'm not saying that's wrong :) I'm just beginner in programing and i have no idea most of the time why I'm making changes. I just compare the new examples to my code and try to make it work :)

Once it start working I also noticed that the device name is not showing up anymore on my MFD but rather show "???". I bet this is a result of my attempt to get my code running with the new library and the changes I did above.




(http://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=215695)

Then I noticed something else -  the "rudder angle" is shown as (Simrad) group, while the "commanded rudder direction" is shown as (Global) group. All the rest of the devices on the bus are part of the Simrad group. I have no idea why "commanded rudder direction" is shown as (Global) group and it can't be changed as there is no Simrad selection in the dropdown menu as there is on the "rudder angle" (see the first picture).

(http://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=215699)

(http://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=215701)

Then I tried to change the instance from 000 to 001 and the device will not take it. I don't think this was something I was successful of doing before upgrading the library either.

(http://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=215697)


Let's go back to the problem at hand. My rudder angle simulator is not being liked by Simrad AP calibration procedures so im trying to understand why and possibly fix it. I did read your email carefully and some parts I understood, but for other parts my programing experience is not enough to make the right conclusions from your email.
I did program another Teensy as listener and captured the bus during my attempt to calibrate the rudder angle on the AP from the MFD. Then I searched for PGN 126208  but it wasn't there. I have attached the capture to this post. Just for clarification, I have the following devices on the N2K bus: Simrad NSS EVO3 MFD, Teensy rudder angle simulator, Simrad AC42 AP computer and another Teensy that is setup with the listener only code. I see more devices showing up in the log file, but I believe that the MFD separates the chart-ploter, the depth-sounder, the AP controller, etc.etc.

One think I would really like if you can help me with is what is the syntax of the parameters of the rudder message. I could make it compile only with passing 2 parameters. if I attempted to pass more than 2 i got errors compiling (from looking at your code i think they should be 4). Very frustrating as my abilities to understand the code are not that great. can you tell me what  parameters I pass to the rudder function, what is the syntax and what each one does?

I see "SetN2kPGN127245(N2kMsg,RudderPosition,Instance,RudderDirectionOrder,AngleOrder)" in your library
and I tried many different combinations in my code, but again it was only successful with 2 parameters
e.i.
Code: [Select]

SetN2kRudder(N2kMsg,((avg2-512)/3.1415926535897932384626433832795/180),1);
    //avg2 is just function to read the pot and some random math to get my reading convert to rad angle that represents -40 to +40 deg



Thanks in advance for spending time to look at my problems.


PS
I just received email that they are parting the big production PCB boards and my PCBs will be send in the mail to me in 48hrs! How exciting! I will post some pic immediately when I get them.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 17, 2017, 02:25 pm
Have you noticed that on the library main page, if you scroll down there is "Changes" section, where specially compitibility changes has been notified. Time to time I unfortunately find something, which is not good for some reason, so I have to change library compatibility. So please read "Changes" section allways carefully.

I also prefer not to copy from examples totally as they are. So. e.g. change name BatteryMonitorProductInformation for e.g. SeaSwitchRudderAngleProductInformation. Also change contents like versions, dates, etc. to match your code. Also remember to define LoadEquivalency to right value. This is n on formula n * 0.050 mA, which tells how much power your device takes from the bus.

You can not change instance of "Rudder Angle"-device, because currently it requires to write specific "Command Group Function" handler for rudder PGN. Currently default handler responds that change is not supported.

You can call it e.g.:
SetN2kRudder(N2kMsg,DegToRad(RudderAngle),1,N2kRDO_MoveToStarboard,DegToRad(RudderCommandedAngle));

Note that you can use library function DegToRad() for conversion.

I'll recheck that product information should be send right to the bus. I'll inform later.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 18, 2017, 09:01 am
I tested product information sending and it seem to work. But I have to test it also with MFD. Your MFD should query product information from your device. I have to check could support for Comand Group Function cause that some MFD:s could query product information by using it instead of ISO request.
Title: Re: NMEA 2000 Shield
Post by: seamaster on Jun 18, 2017, 10:43 am
Hi Timo,
Thank you for your instructions. After I received your reply I managed to output completely
PGN127245 string, I think... and read the compatibility section in your library so now I see the proper name, but stiill struggling outputting rudder angle on the top of the other two with your multi  device sample.
Back to the problem on hand: On the Simrad display I still see difference in the groups. The rudder angle Bellingham nags to the simrad group and the rudder commanded angle belongs to the global group. The AP rudder angle calibration still does not work. :( at this point I am almost positive that maybe the AP needs some response from the Rudder angle sensor, but not too sure as I couldnt not find anything like that in my data capture during an attempt to calibrate the rudder portion of the AP dock setup.
The datasheet for the Simrad N2K rudder angle sensor refers output only PGN127245.
http://www.simrad-yachting.com/Root/Simrad-Documents/RF25_Instruction_Rev.A.pdf (http://www.simrad-yachting.com/Root/Simrad-Documents/RF25_Instruction_Rev.A.pdf)
So I will still try to concentrate providing the proper output from my simulated sensor. With your help I got the sintax ok, but the data I put in it is still bogus... I output proper rudder angle from -35 to 35 deg, that incontrol with potentiometer, but the rest of the data is static. I just plugged some direction and random number for commanded angle DegToRad(19)
I would like to understand little better how this works, so I do have few questions about the paremeters.
setN2kRudder(N2kMsg,DegToRad(RudderAngle),1,N2kRDO_MoveToStarboard,DegToRad(RudderCommandedAngle);
1. What is the second parameter "1"? Is that the instance?
2. What is the "MoveToStarboard" how and when you change it to "MoveToPort"? In your function I see 0 is unknown, 1 starboard, 2 port(if I remember correct...) so it surprised me that I needed to put in the string rather than the un. char 0, 1, or 2 which of course I was trying without success before your explanation. Do I have to create a function to compare the readings and then based on the fact that they get larger or smaller one replaces MoveToPort with MoveToStarboard and vice versa?
3. How you calculate "RudderCommandedAngle"?
4. Why are these parameters required? If they are what I think they are, why are they not calculated by the AP or by AP controller? Why rudder indicator should tell ap in which direction is moving? The APis the one issuing the commands to the steering to move so it should know already...
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 18, 2017, 04:08 pm
1. It is instance value. If you would have 2 rudder sensors, they all should have different instance value.

2. N2kRDO_MoveToStarboard is not a string. Strings will be marked on code with "...". N2kRDO_MoveToStarboard is a value of enumerated type tN2kRudderDirectionOrder. The point for enumerated types is to limit values only to allowed group and also make code readable. If that would be define as uchar, you should comment you code e.g. ...1 /* move starboard */... and also you could set value to e.g. 75, which is not allowed for that setting.

I think normally this PGN comes from AP, which uses integrated sensor. So then AP can say "Current Rudder Angle is 5, I am moving rudder To Starboard and the goal is 15" with this PGN. When you have standalone sensor, it should not use other than angle and instance values. For rest values it should give defaults as I have in function (N2kRDO_NoDirectionOrder,N2kDoubleNA). I was just guessing that may be that during calibration your AP will expect those commaned values. Can be wrong. But if you want to try, you should provide delta of angle.

3. Partially answered on 2. Also here you can ted delta angle.

4. Also answered on 2. Stand alone sensor should not provide these values.

What manufacturer code you have used for you Rudder sensor? If you have used 1875 (Simrad), then your AP may think that is manufactured by Simrad and may try to use their proprietary calibration system. I do not know any std sensor calibration system, so it is best to mfg code, which is not know (=registered) - e.g. 2046.

From your log I can see that probably your AP (source 0) is providing Rudder PGN with all fields as "unavailable" value.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 19, 2017, 05:46 pm
I ordered it, so I'll try to let you know when I get around to try it in a few weeks time.
There is now new version of NMEA2000 library, NMEA2000_teensy library and also under my repositories developed version of FlexCAN library.

I do not have dual CAN Teensy, so I can not test library with it. But you should not need NMEA2000 with dual CAN except if you are going to write some gateway system.
Title: Re: NMEA 2000 Shield
Post by: seamaster on Jun 19, 2017, 06:11 pm
Hi timo,
I tried the new code with 3 device output and it worked well. Then I tried adding 3rd device and I wasn't successful outputting 3 devices. I read the documentation and it says it is for two devices can you please confirm that it is for two devices only.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 19, 2017, 06:26 pm
Sorry, but I am bit lost. What do you mean with 2 devices? MultiDevice support? In principle it should have only memory limitation. Or something else?
Title: Re: NMEA 2000 Shield
Post by: seamaster on Jun 19, 2017, 08:32 pm
LOL! I know what the "Or something else" limitation is :) Most likely my ability to write code.
I will sweat it little longer and then if I don't succeed I'll post my code with the attempt to add another device. This time I thought I have it right, damn! LOL :smiley-confuse:
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 20, 2017, 04:17 am
With "Something else" I meant that do you mean with 2 devices multi device support or something else. Device has so many meanings that I was not sure.

And about the multi device support - keep you code simple at the beginning and use just single device definition like in the simple example TemperatureSensor. I started multi device thinking in the very beginning, but soon noticed that other devices on bus actually does not care what you say you are. Roughly saying you can show you device as wind instrument and send only cabin temperature. Others are happy for someone sending cabin temperature.
Title: Re: NMEA 2000 Shield
Post by: seamaster on Jun 20, 2017, 10:28 am
Hi,
I did try hard for a long time and finally i discovered the "magic bullet"
Apparently I was missing something very simple

Code: [Select]

 NMEA2000.SetDeviceCount(2);

After I changed the number of devices to 3 it all worked as suppose to.
I did laugh at myself... for a long time. Still shorter time than what I spent trying to figure out why only 2 devices were showing up on the MFD.

I have a question about
NMEA2000.SetProductInformation
and
NMEA2000.SetDeviceInformation
it appears that if the second one is remed out everithing still works, or does it?
 
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 20, 2017, 11:52 am
In these small devices it is not good to use new/free to extend vectors. That is why you have to first say that "I'll have 3 devices, so reserve me this big vector" with NMEA2000.SetDeviceCount(3); So there will be only one new commad to make vector and no free to cause hole to small memory.

It is best to define both. SetDeviceInformation is the most important, since it defines unique ID for you device. Specially serial number should be different. If you do not define SetDeviceInformation, my library tries to survive by changin some instance value, but your MFD probably can't handle it.

SetProductInformation you need so that your MFD will show different names. Otherwise it will show same name for both devices.
Title: Re: NMEA 2000 Shield
Post by: seamaster on Jun 24, 2017, 07:10 pm
I'm very excited as the boards arrived on Friday. Here is the first look:
(http://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=216502)
Next stop is assambly and revival of the first 3 boards
Title: Re: NMEA 2000 Shield
Post by: FXVT on Jun 26, 2017, 11:46 pm
Bonjour Timo,

I am still waiting for the Mega board I ordered, so I continue my test with Arduino Boards.
Anyway, parts of my latest sketch work, but not together.

There are 2 main parts:
-   Acquiring datas from the serial port of a Victron BMV700 battery Monitor: Current (A),  Voltage (V) and capacity (%)
-   Sending those datas to the SeaTalkNG network (NMEA2000).
I can send datas to a Raymarine MFD or B&G display if I write test values directly in the     
Code: [Select]
SetN2kDCBatStatus(N2kMsg,0,13.87,5.12,35.12,1) command. That is ok.


I can get data from the BMV700 and print them on the serial Monitor. So I gess this part works.
But for that, I must comment (//) all the lines who send the N2K messages, especially this command
Code: [Select]
// tN2kMsg N2kMsg;

As soon as I uncomment these lines, I only get null values for Current, Voltage and Capacity
I get :
"0.00   0.00   0.00"
, instead of, for example:
 "-3.45   12.90   95.45"

Code: [Select]
     // Print the values on the Serial Monitor
     Serial.print (Current);
     Serial.print ("   ");
     Serial.print (Voltage);
     Serial.print ("   ");
     Serial.println (SOC);


During the test I have modified the structure of your Battery Monitor Example, copying the SendN2kBattery subroutine in the main loop.

Why the tN2kMsg N2kMsg; command seems to RAZ my datas ?

Regards, thanks for your great job.
François-Xavier.

Code: [Select]
// From http://www.jw5zla.com/?p=7 Interfacing the Victron BMV-700
// and Timo Lappalainen'NMEA2000 libraries

#include <Arduino.h>
#include <SoftwareSerial.h>
#include <SPI.h>
 
SoftwareSerial Victron(0,3);    // RX= Pin 0, TX= Pin 3(Not used)

char p_buffer[80];
#define P(str) (strcpy_P(p_buffer, PSTR(str)), p_buffer)

#define N2k_SPI_CS_PIN 9        // Valeur 10 pour le shield www.elecrow.com, 9 pour le Seeedunio

#include <NMEA2000_CAN.h>       // This will automatically choose right CAN library and create suitable NMEA2000 object
#include <N2kMessages.h>
 
char c;
String V_buffer;  // Buffer to hold data from the Victron monitor
String E_buffer;  // Buffer to hold data from the ethernet shield
 
float Current;
float Voltage;
float SOC;


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

// ---  Example of using PROGMEM to hold Product ID.  However, doing this will prevent any updating of
//      these details outside of recompiling the program.
const tProductInformation BatteryMonitorProductInformation PROGMEM={
                                       1300,                        // N2kVersion
                                       100,                         // Manufacturer's product code
                                       "Moniteur Batterie Arduino", // Manufacturer's Model ID C'est la ligne qui est détectée comme appareil par le Triton
                                       "1.0.0.0 (2017-06)",         // Manufacturer's Software version code
                                       "1.0.0.0 (2017-06)",         // Manufacturer's Model version
                                       "00000001",                  // Manufacturer's Model serial code
                                       0,                           // SertificationLevel
                                       1                            // LoadEquivalency
                                      };                                     

// ---  Example of using PROGMEM to hold Configuration information.  However, doing this will prevent any updating of
//      these details outside of recompiling the program.
const char BatteryMonitorManufacturerInformation  [] PROGMEM = "FX VAN THUAN";
const char BatteryMonitorInstallationDescription1 [] PROGMEM = "BMV700 Victron & Arduino";
const char BatteryMonitorInstallationDescription2 [] PROGMEM = "Send Informations to the N2K bus";


 
void setup()
{
  Serial.begin(19200);
  Victron.begin(19200);


  // Set Product information
  NMEA2000.SetProductInformation(&BatteryMonitorProductInformation );
  // Set Configuration information
  NMEA2000.SetProgmemConfigurationInformation(BatteryMonitorManufacturerInformation,BatteryMonitorInstallationDescription1,BatteryMonitorInstallationDescription2);
  // Set device information
  NMEA2000.SetDeviceInformation(1,      // Unique number. Use e.g. Serial number.
                                170,    // Device function=Battery. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                35,     // Device class=Electrical Generation. See codes on  http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                999     // Just choosen free from code list on http://www.nmea.org/Assets/20121020%20nmea%202000%20registration%20list.pdf                               
                               );                         
                                 
  // Uncomment 3 rows below to see, what device will send to bus                           
  // Serial.begin(115200);
   NMEA2000.SetForwardStream(&Serial);
   NMEA2000.SetForwardType(tNMEA2000::fwdt_Text);     // Show in clear text. Leave uncommented for default Actisense format.
 Serial.println ("ETAPE 1");
  // If you also want to see all traffic on the bus use N2km_ListenAndNode instead of N2km_NodeOnly below
  NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly,22);
  // NMEA2000.SetDebugMode(tNMEA2000::dm_ClearText);     // 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);                      // For this simple example, limit buffer size to 2, since we are only sending data
   NMEA2000.SetN2kCANSendFrameBufSize(30);               // essai suite lecture forum
  Serial.println ("ETAPE 2");
    NMEA2000.Open();
  Serial.println ("ETAPE 3");

 
}
 
void loop() {
 
  // Victron
 
  if (Victron.available()) {
    c = Victron.read();
 
    if (V_buffer.length() <80) {
      V_buffer += c;
    }
 
    if (c == '\n') {  // New line.
 
      if (V_buffer.startsWith("I")) {
        String temp_string = V_buffer.substring(V_buffer.indexOf("\t")+1);
        double temp_int = temp_string.toInt();
        Current = (float) temp_int/1000;
      }     
 
      if (V_buffer.startsWith("V")) {
        String temp_string = V_buffer.substring(V_buffer.indexOf("\t")+1);
        int temp_int = temp_string.toInt();
        Voltage = (float) temp_int/1000;
      }     
 
      if (V_buffer.startsWith("SOC")) {
        String temp_string = V_buffer.substring(V_buffer.indexOf("\t")+1);
        int temp_int = temp_string.toInt();
        SOC = (float) temp_int/10;
      }     
      V_buffer="";
    }
   
  }
     // Print the values on the Serial Monitor
     Serial.print (Current);
     Serial.print ("   ");
     Serial.print (Voltage);
     Serial.print ("   ");
     Serial.println (SOC);


//---------------------- Section N2K

     #define BatUpdatePeriod 1000
     static unsigned long TempUpdated=millis();
// tN2kMsg N2kMsg;

   if ( TempUpdated+BatUpdatePeriod<millis() )
   {
        TempUpdated=millis();
    /*
    //SetN2kDCBatStatus(N2kMsg,0,13.87,5.12,35.12,1);     // test
    SetN2kDCBatStatus(N2kMsg,0,Voltage,Current,22.22,1);
    NMEA2000.SendMsg(N2kMsg);
   
    //SetN2kDCStatus(N2kMsg,1,0,0,56,92,38500,0.012);     // test
    SetN2kDCStatus(N2kMsg,1,0,N2kDCt_Battery,SOC,0,0,0);
    NMEA2000.SendMsg(N2kMsg);
    */
         Serial.print(millis()); Serial.println(", Battery send ready");

   
   }   // Fin de la boucle conditionnelle de temps

             
          NMEA2000.ParseMessages();
 
}
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 27, 2017, 06:25 am
Are you are still using Uno, I think it is simple memory problem. When you have tN2kMsg N2kMsg; on loop, it will make a reservarion on stack for that object. The total size of N2kMsg is about 240 bytes. That is over 10% of Uno memory.

You can try to squeeze memory more.
- Change NMEA2000.SetForwardStream(&Serial); -> NMEA2000.SetForwardStream(0);
- comment NMEA2000.SetForwardType(tNMEA2000::fwdt_Text);
- uncomment NMEA2000.EnableForward(false);
- change NMEA2000.SetN2kCANSendFrameBufSize(30); -> NMEA2000.SetN2kCANSendFrameBufSize(20);
- you can try even set NMEA2000.SetN2kCANMsgBufSize(1);

Make own functions for Victron and SendN2kInfo, which have own local variables and call them on loop. In this way it is sure that their local varables does not take memory from stack at same time.

Also you have buffers
char p_buffer[80];
...
String V_buffer;  // Buffer to hold data from the Victron monitor
String E_buffer;  // Buffer to hold data from the ethernet shield

If these are not needed globally, move them inside some function, so they will need RAM on stack, when needed and then released. I have not checked how String class works in point of memory use as global or local.

And also you have to define all options on NMEA2000_CompilerDefns.h to disable all new features to save memory.

I would say that using Uno is just banging your head to the wall!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 27, 2017, 06:34 am
And also either disable interrupt by commenting  #define N2k_SPI_CS_PIN 9 to save one extra frame.

Remember also use format
Serial.println (F("ETAPE 2"));
for all string printing. Without F(...) "EATPE2" string takes RAM instead of Flash.
Title: Re: NMEA 2000 Shield
Post by: FXVT on Jun 27, 2017, 08:52 am
Bonjour Timo,

Thank you for your prompt reply.

Yes I am still working with a Uno board, waiting for the Mega to be delivered.

Lake of memory ! That is what I guessed.
When I add some lines, I loose the Victron values little by little. For example, Voltage or current go down to zero, or even both of them.

I will apply your advices and tell you the result.

Regards.
FX VAN THUAN
Title: Re: NMEA 2000 Shield
Post by: FXVT on Jun 27, 2017, 09:23 pm
Bonjour Timo,

Yesssssss !
I have modified the sketch according to your advices and it woooooooorks !
Thank you !

Thanks to your tricks, I have win around 5 % of memory, and it is enough. after compilation it use 90% of the UNO board memory.
I am on the limit.

Here are some pictures. The Arduino is well recognized by the Triton T41 B&G and the i70 Raymarine, and the datas are displyed on the a78 Raymarine MFD and the T41

The next sketch will be the termometer of the engine water and the fridge.

Regards.
FX VAN THUAN
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 27, 2017, 10:04 pm
But after all memory savings it it rather clear that you can not add much more code for your Uno.

Which Victron device you have? Do you know, does they have some output also on Victron MPPT solar charger? One can connect external display to it, but I have not seen any data how they send it, what protocol etc. Could it be same as in your device?
Title: Re: NMEA 2000 Shield
Post by: FXVT on Jun 28, 2017, 11:40 pm
Bonjour Timo,

I use a BMV700 Victron Battery Monitor
https://www.victronenergy.com/battery-monitors/bmv-700
It has 2 connectors at the rear:
- RJ-11 to the shunt
- JST 4 as Serial TTL 3.3V outpout.

His protocol is described here:
http://www.plaisance-pratique.com/IMG/pdf/BMV_Text_Protocol_1_.pdf
http://www.deszynski.com/victron-bmv-700-lan-port/

I have never used the Victron MPPT Monitor who has quite the same housing.
https://www.victronenergy.com/panel-systems-remote-monitoring/mppt-control
May be you will find some information here about the way to make it communicating with other devices:

https://www.victronenergy.com/live/vedirect_protocol:faq
https://www.victronenergy.com/upload/documents/Whitepaper-Data-communication-with-Victron-Energy-products_EN.pdf
https://www.victronenergy.com/live/open_source:ccgx:d-bus
https://www.victronenergy.com/upload/documents/Manual-MPPT-Control-A4-EN.pdf

Regards.
FXVT
https://www.victronenergy.com/live/open_source:start
Title: Re: NMEA 2000 Shield
Post by: seamaster on Jul 06, 2017, 05:52 am
Hello all!
For those of you interested, here is the assembled RevA board
Finally I got to test the RS232 port today. It works great!
So it all works great!

(https://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=217901)

For those of you interested, here are the specs:
8 x 0-30 VDC inputs
4 x 0-5 VDC or 0-3.3 VDC (with analog reference of 3.3v)
Each of the 4 ports above has 3.3vdc supply and ground - for easy connection to temperature or pressure sensors
1 x RS232 port for NMEA0183
1 x NMEA2000 port with MICRO-C male connector (or just bare wires if preferred)
external 12-18VDC power or N2K bus powered - jumper selectable.


I'm planning to make RevB based on feedback I get from the forum and few things that I feel I can improve.
Please let me know what you think should be added or substracted from the board. I prefer to keep it simple and have multiple boards for more interfaces.
This boat was tested with Timo's multi device interface with up to 5 devices.
I simulated:
Heading
Fluid levels
Rudder indicator
Compass
Battery

Please let me know if you have any other uses that I can implement the hardware for.
Cheers!
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 09, 2017, 01:44 am
Hi!

I just added Mercury VesselView to my boat and as part of the process I had to move the engine trim sensor from analog to digital so the ECU could use it to enable ECO MODE.   As such, my analog gauge became non-functional.  

So, I designed a PCB that uses a Teensy and MCP2551 among some other circuitry that can read the NMEA 2000 data and then control the gauge using PWM but I thought it was a better opportunity to convert the analog gauge into a color multifunction display.

I've got everything ready to go -- now I just need to plug into the NMEA 2000 bus to see if the Teensy can handle getting the Engine Trim data...

I'm using the NMEA2000 DataDisplay example, do you think what I'm trying to do (read Engine Trim) will work?  Meaning, will get the updates of position in a "real-time" update?

I will be going to the boat this week to finally plug in the board to the network to start testing -- for the last few weeks it was about the programing the color display, mechanical work, PCB design and 3d designing printing the case pieces.  

Here are photos of the progress so far --
(https://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=218246)

(https://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=218248)

(https://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=218250)

(https://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=218252)

(https://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=218254)

(https://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=218256)

Video showing transitions (by tapping the chrome bezel):
https://www.youtube.com/watch?v=PfXNt46S_9c (https://www.youtube.com/watch?v=PfXNt46S_9c)
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 09, 2017, 07:10 am
Hi,

In principle it should work.
- I expect you have DC-DC converter on your board and you remembered to cut link between VUSB and Vin on Teensy.

- Also hopefully ECU or some system will send trim data to NMEA2000

- DataDisplay is a bit old and does not seem have automatic library selection for board. DataDisplay2 seem to already have handling for EngineRapid (PGN 127488). On that you will need only comment unnecessary handlers on handler list NMEA2000Handlers. Or maybe you already rewrite datadisplay to match your needs?

Your gauge looks very nice and could be used to display different data. With single scroll button besides gauge one select data from NMEA2000 bus - not just trim.

And if you want to see your new gauge on NMEA2000 device list, you have to add device definition commands to setup as e.g. in TemperatureMonitor example. You should then use Class code 120 (Display) and Function code 130 (Display). In principle in NMEA 2000 listen only devices are not allowed. On reason is that each device, which is taking power from bus, should inform it so that total power can be calculated. Just on your own boat this does not matter, if you just remember to keep used power low enough. There are also other things to concern, if you start to change you device more "NMEA2000 certified".
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 09, 2017, 05:56 pm
- I expect you have DC-DC converter on your board and you remembered to cut link between VUSB and Vin on Teensy.
Yes, I have a 12v > 5v DC-DC converter onboard and cut the link.

- Also hopefully ECU or some system will send trim data to NMEA2000
The VesselView Link takes the ECU data and puts it on the NMEA2000 network -- this is all functioning already  on my Lowrance MFD.

- DataDisplay is a bit old and does not seem have automatic library selection for board. DataDisplay2 seem to already have handling for EngineRapid (PGN 127488). On that you will need only comment unnecessary handlers on handler list NMEA2000Handlers. Or maybe you already rewrite datadisplay to match your needs?
Got it -- I meant to say DataDisplay2 example.   I see these handlers in the demo -- are they all good?

Code: [Select]

// Do not forward bus messages at all
  NMEA2000.SetForwardType(tNMEA2000::fwdt_Text);
  NMEA2000.SetForwardStream(OutputStream);
  // Set false below, if you do not want to see messages parsed to HEX withing library
  NMEA2000.EnableForward(false);
  NMEA2000.SetMsgHandler(HandleNMEA2000Msg);
  NMEA2000.SetN2kCANMsgBufSize(2);
  NMEA2000.Open();
  OutputStream->print("Running...");


Your gauge looks very nice and could be used to display different data. With single scroll button besides gauge one select data from NMEA2000 bus - not just trim.
That's the plan -- right now I have two screens ready (Trim and Fuel).  I will add more screens I can cycle through to make it a quick-look MFD.

And if you want to see your new gauge on NMEA2000 device list, you have to add device definition commands to setup as e.g. in TemperatureMonitor example. You should then use Class code 120 (Display) and Function code 130 (Display). In principle in NMEA 2000 listen only devices are not allowed. On reason is that each device, which is taking power from bus, should inform it so that total power can be calculated. Just on your own boat this does not matter, if you just remember to keep used power low enough. There are also other things to concern, if you start to change you device more "NMEA2000 certified".
Good idea!  I'll add that code so the device shows up -- the power usage is pretty low overall.  The Teensy & Display plus the MCP2551 is all that is being used.   Initial measurement looked like about 90mA being pulled from the 12v input side.

Thanks again timolappalainen!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 09, 2017, 08:30 pm
Got it -- I meant to say DataDisplay2 example.   I see these handlers in the demo -- are they all good?
I have tested them against Actisense NMEA Reader, so they should be all right.
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 10, 2017, 10:04 pm
I have tested them against Actisense NMEA Reader, so they should be all right.
At the boat, connected to the network -- I see the data coming in!

However, I'm not getting the device showing up in the "Device List" on my Lowrance HDS7 when I scan the network for devices...

I'm doing the following in code:

Code: [Select]

// Set Product information
  NMEA2000.SetProductInformation("00000001", // Manufacturer's Model serial code
                                 100, // Manufacturer's product code
                                 "Myro Gauge MFD",  // Manufacturer's Model ID
                                 "1.0.0.0 (2017-7-10)",  // Manufacturer's Software version code
                                 "1.0.0.0 (2017-7-10)" // Manufacturer's Model version
                                 );
  // Set device information
  NMEA2000.SetDeviceInformation(000001, // Unique number. Use e.g. Serial number.
                                130, // Device function=Display. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                120, // Device class=Display. See codes on  http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                2041 // Just choosen free from code list on http://www.nmea.org/Assets/20121020%20nmea%202000%20registration%20list.pdf                               
                               );
  // Do not forward bus messages at all
  NMEA2000.SetForwardType(tNMEA2000::fwdt_Text);
  NMEA2000.SetForwardStream(OutputStream);
  // Set false below, if you do not want to see messages parsed to HEX withing library
  NMEA2000.EnableForward(false);
  NMEA2000.SetMsgHandler(HandleNMEA2000Msg);
  NMEA2000.SetN2kCANMsgBufSize(2);
  NMEA2000.Open();
  OutputStream->print("Running...");
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 10, 2017, 10:20 pm
You are missing type definition as default is just listen. So add
  NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode,29);

Also since Teensy has enough memory you do not need to sqeeze it with
NMEA2000.SetN2kCANMsgBufSize(2);
Title: Re: NMEA 2000 Shield
Post by: seamaster on Jul 10, 2017, 10:50 pm
@mavromatis
great project. Interested to know what display you used for that?
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 11, 2017, 01:23 am
You are missing type definition as default is just listen. So add
  NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode,29);

Also since Teensy has enough memory you do not need to sqeeze it with
NMEA2000.SetN2kCANMsgBufSize(2);
Thank you!


@mavromatis
great project. Interested to know what display you used for that?
I was going to go down the route and use an STM32 with a 1.5" round display (from China) but ended up finding this screen from 4d systems (http://www.4dsystems.com.au/product/uLCD_220RD/ (http://www.4dsystems.com.au/product/uLCD_220RD/)) that actually fit perfectly into the 2" analog gauge frame.
Title: Re: NMEA 2000 Shield
Post by: Lunchrat on Jul 11, 2017, 10:52 pm
Hey guys,

Sorry to interrupt- I've got a quick question. I'm trying to read and record (not write) N2K with a tablet or phone. I didn't read all 16 pages of this thread so can anyone point me in the direction of a library (or existing sketch) I can use to read the N2K data on the network?

I saw the mention of that reverse engineered catalog of PGNs but I don't know if someone already compiled it into some easy to use Arduino thing.

Thanks for the help
Title: Re: NMEA 2000 Shield
Post by: seamaster on Jul 12, 2017, 03:34 am
In the library examples, there is an example file called ActisenseListner.ino. This  file listens for the trafic on the N2K network. Here is actually where you should start:
https://github.com/ttlappalainen/NMEA2000/tree/master/Documents (https://github.com/ttlappalainen/NMEA2000/tree/master/Documents)

and here:
https://github.com/ttlappalainen/NMEA2000/blob/master/Documents/NMEA2000_library_reference.pdf (https://github.com/ttlappalainen/NMEA2000/blob/master/Documents/NMEA2000_library_reference.pdf)

it is relatively simple if I figured it out..
good luck
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 12, 2017, 05:49 pm
I've logged down some of the output from the bus and I see some anomaly's I think it's normal as the numbers are Pa (Pascal), right? -- engine wasn't running but the VesselView Link (ECU > N2K bridge powered) -- the VesselView interface showed the correct data. See how the oil pressure and fuel pressure show some interesting values... then go to "not available" in the next update.

These readings were made via a Teensy 3.2 with NMEA2000.SetN2kCANMsgBufSize(2); -- I will check it again with that bit code code commented out (not sure if that causes the issue).


  In Main Handler: 127489
  Engine dynamic params: 0
  oil pressure (Pa): 200.00
  oil temp (C): -0.05
  coolant temp (C): 24.00
  altenator voltage (V): 13.29
  fuel rate (l/h): 0.00
  engine hours (h): 280.97
  coolant pressure (Pa): 0.00
  fuel pressure (Pa): 296000.00
  engine load (%): 0
  engine torque (%): not available




Then next update I get, it seems to cycle over and over:


  In Main Handler: 127489
  Engine dynamic params: 0
  oil pressure (Pa): not available
  oil temp (C): not available
  coolant temp (C): not available
  altenator voltage (V): not available
  fuel rate (l/h): 0.00
  engine hours (h): not available
  coolant pressure (Pa): not available
  fuel pressure (Pa): not available
  engine load (%): not available
  engine torque (%): not available
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 12, 2017, 08:44 pm
Update on trying to send the product info on the network: 

When I try to enable -- NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode,29);

It seems to crash my NMEA network -- the Lowrance MFD Network device list cannot list any items and doesn't refresh and I lose my GPS (since it cannot get my POINT-1 GPS on the network) until I unplug my device. 

Anything look wonky below?  Wonder if it's software or possibly hardware on the TX side of my CAN?

Code: [Select]

 // Set Product information
  NMEA2000.SetProductInformation("00000001", // Manufacturer's Model serial code
                                 100, // Manufacturer's product code
                                 "Myro Gauge MFD",  // Manufacturer's Model ID
                                 "1.0.0.0 (2017-7-10)",  // Manufacturer's Software version code
                                 "1.0.0.0 (2017-7-10)" // Manufacturer's Model version
                                 );
  // Set device information
  NMEA2000.SetDeviceInformation(000001, // Unique number. Use e.g. Serial number.
                                130, // Device function=Display. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                120, // Device class=Display. See codes on  http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                2041 // Just choosen free from code list on http://www.nmea.org/Assets/20121020%20nmea%202000%20registration%20list.pdf                               
                               );
  // If you also want to see all traffic on the bus use N2km_ListenAndNode instead of N2km_NodeOnly below
  //NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly,22);
  //NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode,29);
  // Do not forward bus messages at all
  NMEA2000.SetForwardType(tNMEA2000::fwdt_Text);
  NMEA2000.SetForwardStream(OutputStream);
  // Set false below, if you do not want to see messages parsed to HEX withing library
  NMEA2000.EnableForward(false);
  NMEA2000.SetMsgHandler(HandleNMEA2000Msg);
  //NMEA2000.SetN2kCANMsgBufSize(2); << Don't need this for teensy
  NMEA2000.Open();
  OutputStream->print("Running...");
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 12, 2017, 09:37 pm
If it would be on sw, none of my device would work. I have one board with MCP2551, which bricked and blocks the network too. Others with MCP2562 works still fine.

You get "not available", since your device reads 0xffff for all values and that will be translated as not available. Except for some reason you get 0 for fuel rate.
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 12, 2017, 10:07 pm
If it would be on sw, none of my device would work. I have one board with MCP2551, which bricked and blocks the network too. Others with MCP2562 works still fine.
OK -- will check to see if it's possibly HW related -- if I just listen -- comment out, everything seems to work fine... so it's something on the TX part back into the network.


You get "not available", since your device reads 0xffff for all values and that will be translated as not available. Except for some reason you get 0 for fuel rate.
Sometimes I get not available other times I get the values -- not a big deal because at least I get the values multiple times a second it seems...

Example with engine running:

In Main Handler: 127489
Engine dynamic params: 0
  oil pressure (Pa): 323900.00
  oil temp (F): 31.91
  coolant temp (F): 109.40
  alternator voltage (V): 14.43
  fuel rate (l/h): 3.90
  engine hours (h): 281.00
  coolant pressure (Pa): 9500.00
  fuel pressure (Pa): 296000.00
  engine load (%): 0
  engine torque (%): not available
...
...
... then a few moments later...
...
...
In Main Handler: 127489
Engine dynamic params: 0
  oil pressure (Pa): not available
  oil temp (F): not available
  coolant temp (F): not available
  alternator voltage (V): not available
  fuel rate (l/h): 3.00
  engine hours (h): not available
  coolant pressure (Pa): not available
  fuel pressure (Pa): not available
  engine load (%): not available
  engine torque (%): not available
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 13, 2017, 06:42 am
I still expect hw problem also on rx side. DataDisplay2 does not anything than catches data and shows it directly. As an alternate you could try with ActisenseListener either with Actisense NMEA Reader or by uncommenting line NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); so that you will see data in clear text.

Just for checking that hopefully you have not forgot bus 120 ohm termination resistors, which you should have at both end of the bus. That has happed happened to me with test bed on disconnecting bus from wrong place.
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 13, 2017, 04:42 pm
I still expect hw problem also on rx side. DataDisplay2 does not anything than catches data and shows it directly. As an alternate you could try with ActisenseListener either with Actisense NMEA Reader or by uncommenting line NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); so that you will see data in clear text.

Just for checking that hopefully you have not forgot bus 120 ohm termination resistors, which you should have at both end of the bus. That has happed happened to me with test bed on disconnecting bus from wrong place.
120ohm termination resistors are on -- but I'll try uncommenting the fwdt_Text line.

Below is the circuit I'm using with the MCP2551, could be that is incorrect (based it on one I found online that is sold on eBay as a MCP2551 breakout (http://www.ebay.com/itm/MCP2551-CAN-HI-SPD-Transceiver-Breakout-Board-/301881312565)) -- I'll also swap the MCP2551 for a MCP2561 and a MCP2562 to see if that changes anything...

(https://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=218738)
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 13, 2017, 09:37 pm
It should be ok. It is same as I have with Mega (or CAN bus shield) https://github.com/ttlappalainen/NMEA2000/blob/master/Documents/ArduinoMega_CAN_with_MCP2515_MCP2551.pdf. Except I do not have RC filter on CAN-H and CAN-L

With  MCP2562 connect pin 5 to 3.3V as in my drawing https://github.com/ttlappalainen/NMEA2000/blob/master/Examples/TeensyActisenseListenerSender/Documents/Teensy_Actisense_listener_sender_schematics.pdf
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 14, 2017, 06:36 pm
With  MCP2562 connect pin 5 to 3.3V as in my drawing https://github.com/ttlappalainen/NMEA2000/blob/master/Examples/TeensyActisenseListenerSender/Documents/Teensy_Actisense_listener_sender_schematics.pdf
Will do and report back findings... thx.
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 22, 2017, 01:54 am
Will do and report back findings... thx.
Built another board and used a MCP2551 and that one works.

Thanks!
Danny
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 30, 2017, 06:16 pm
@timolappalainen -- First, thanks for your help!

I've got everything mostly working and now I'm only the final stretch (you can see my progress HERE (http://www.mavromatic.com/2017/07/part-i-custom-nmea-2000-2-round-lcd-multifunction-display-for-boat-gauge/)).

I can't seem to get "ENGINE ROOM TEMP" updates... is there something I need to add or enable deeper in the code/library?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 30, 2017, 06:50 pm
Are you sure you have engine room temperature sensor and some device sending data from it?

Engine roome temperature will be sent either by PGN 130312 (obsolte) or 130316. Temperature source field will be then set to N2kts_EngineRoomTemperature.

So as in DataDisplay2, it handles those messages by function Temperature (130312) and TemperatureExt (130316). So if you have device sending engine room temperature with PGN 130312, you use it as in function Temperature:
    if (ParseN2kTemperature(N2kMsg,SID,TempInstance,TempSource,ActualTemperature,SetTemperature)  && !N2kIsNA(ActualTemperature) && TempSource==N2kts_EngineRoomTemperature ) {
  SetTempGauge(ActualTemperature);
}
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 30, 2017, 07:07 pm
Yes, I have one of these on the device network setup as Engine Room Temperature sensor (http://www.lowrance.com/en-US/Products/NMEA-2000/temperature-sensor-en-us.aspx (http://www.lowrance.com/en-US/Products/NMEA-2000/temperature-sensor-en-us.aspx)) -- it shows up on the Lowrance HDS screen just not seeing any messages show up in the output screen.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 30, 2017, 09:24 pm
Do you mean that it does not show on DataDisplay2?

You could program ActisenseListener - if you do not have any Actisense NGT-1  - to your Teensy connected to N2k bus and then listen data with Actisense NMEA Reader. Then you can see, what message your sensor is sending.
Title: Re: NMEA 2000 Shield
Post by: Rinkelein on Jul 30, 2017, 10:29 pm
Just a question. I have been able to read all N2K messages from my Raymarine i70 backbone using a Due, and even transmit them in NMEA 0183 format via WiFi (UDP) to be used in OpenCPN. However sending (Windmonitor) to the backbone does not work, even not with the NMEA simulator. Serial output tells me that PGN'S failed. I've not changed anything to Timo's most recent sketches. Simulator was connected  to the SerialUSB.

Any suggestions are highly appreciated.
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 31, 2017, 05:04 am
Do you mean that it does not show on DataDisplay2?

You could program ActisenseListener - if you do not have any Actisense NGT-1  - to your Teensy connected to N2k bus and then listen data with Actisense NMEA Reader. Then you can see, what message your sensor is sending.
Yes, doesn't show using DataDisplay2 -- I will try programming ActisenseListener to see what type of messages that sensor is sending... will report back.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 31, 2017, 09:20 am
Any suggestions are highly appreciated.
I just tested WindMonitor with my own DUE and it works OK. I made tests with old NMEA2000_due/due_can and new version of both (just released on my GitHub few minutes ago). So I think the problem is not with library.

If you can read, but TX fails, there is some problem with your TX side. Have you checked TX pin is connected? Are terminal resistors OK? Maybe tranceiver does not work on TX?
Title: Re: NMEA 2000 Shield
Post by: Rinkelein on Jul 31, 2017, 11:18 am
Many thanks Timo. We will check the terminal resistor and back with the result. I used a SN65HVD230 and didn't use a 120 Ohm terminator resistor. Also I will use the latest libraries.
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Jul 31, 2017, 05:54 pm
Many thanks Timo. We will check the terminal resistor and back with the result. I used a SN65HVD230 and didn't use a 120 Ohm terminator resistor. Also I will use the latest libraries.
If it helps -- I was having issues with the TX side of things (RX worked fine) and put together another board and that one worked perfectly.  Not sure why yet, I thought it was related to a bad MCP2551 but most likely caused by bad solder joints or some other passives I soldered on the board. 
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Aug 01, 2017, 08:53 pm
Do you mean that it does not show on DataDisplay2?

You could program ActisenseListener - if you do not have any Actisense NGT-1  - to your Teensy connected to N2k bus and then listen data with Actisense NMEA Reader. Then you can see, what message your sensor is sending.
Timo, I installed the ActisenseListener and ran Actisense NR -- if I set the temp sensor to Water I get the values showing up under Name: Temperature and Name: Environmental Parameters -- if the sensor is set to anything else, there is no active data under those items that were updating when set to Water in Actisense NR -- but, the weird bit -- the data showing correctly on the Lowrance HDS and data under the Lowrance Device List.   Are they doing something non-standard?

Here is what I get on the Lowrance:
(https://forum.arduino.cc/index.php?action=dlattach;topic=50893.0;attach=220980)
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 01, 2017, 09:27 pm
What do you mean by "if I set the temp sensor to Water"? Is there some switch to define what sensor is for?

It is very strange, if they would use some proprietary. Anyway if you listen bus at the same time with Actisense NR, while showing data on HDS, you should see the traffic. Actisense NR may show them unknown messages from source 10. There is one possiblity that data will be sent as no extended format. I do not know does library actually handle those messages and forward them to the USB.
Title: Re: NMEA 2000 Shield
Post by: seamaster on Aug 01, 2017, 10:47 pm
Quote
Timo, I installed the ActisenseListener and ran Actisense NR -- if I set the temp sensor to Water I get the values showing up under Name: Temperature and Name: Environmental Parameters -- if the sensor is set to anything else, there is no active data under those items that were updating when set to Water in Actisense NR -- but, the weird bit -- the data showing correctly on the Lowrance HDS and data under the Lowrance Device List.   Are they doing something non-standard?
If you are using Loweance temp sensor please pay attention to the data sheet of the product.  All Lawrence temp sensors output proprietary PGN
**************
Specifications
Temperature Range between -20 and 80 degrees Celsius.
PGNs transmitted
59392 - ISO Acknowledgment
60928 - ISO Address Claim
126996 - Product Information
65285 - Temperature with Instance  //this is the one that's proprietary
**************
I went through this with my Furuno MFD showing the temp sensor, but not reading the data. I was unpleasantly surprised that wasn't the configuration of the sensor for water, engine room  temp, etc., that was screwing up the reading, but rather the Lowrance proprietary PGN.
Maybe if you can capture the raw data from the sensor, Timo can add this PGN to the library if possible to easy interpret what is what...
Cheers!
Title: Re: NMEA 2000 Shield
Post by: seamaster on Aug 01, 2017, 10:57 pm
What do you mean by "if I set the temp sensor to Water"? Is there some switch to define what sensor is for?

Timo,
Lawrance uses their MF Displays to configure their sensors. Here is default sensor configurations -
 an extract from the installation manual:
**********
Fluid Level Sensor - tank levels for fuel*, water, gray water, live well, oil, and black water
• Fuel Flow Sensor - flow rate measurements of fuel for gasoline powered boats
• Fuel Data Manager - fuel used data from fuel flow messages it receives from up to three
NMEA 2000 compatible engines
• Temperature Sensor - temperatures for water*, outside, inside, engine room, cabin, live well,
bait well, refrigeration, and heating system
• Thru-Hull Temperature Sensor - temperatures for water*, outside, inside, engine room, cabin,
live well, bait well, refrigeration, and heating system
• Speed Sensor - boat speed
• Pressure Sensor - pressure data: Engine Boost Pressure, Engine Oil Pressure, Engine Water
Pressure*, Transmission Oil Pressure and Pitot Speed
* Sensor is pre-configured to display this information.

**********
Cheers,
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Aug 02, 2017, 01:35 am
What do you mean by "if I set the temp sensor to Water"? Is there some switch to define what sensor is for?

It is very strange, if they would use some proprietary. Anyway if you listen bus at the same time with Actisense NR, while showing data on HDS, you should see the traffic. Actisense NR may show them unknown messages from source 10. There is one possiblity that data will be sent as no extended format. I do not know does library actually handle those messages and forward them to the USB.
Hi Timo -- like Seamaster stated, Lowrance allows you to setup the sensor via their MFD, I guess that is why they do some proprietary stuff?  Do you want me to ship you one of these sensors setup as Engine Rm or is it easier for me to capture the raw data so we can try to add the functionality to the library?


If you are using Loweance temp sensor please pay attention to the data sheet of the product.  All Lawrence temp sensors output proprietary PGN
**************
Specifications
Temperature Range between -20 and 80 degrees Celsius.
PGNs transmitted
59392 - ISO Acknowledgment
60928 - ISO Address Claim
126996 - Product Information
65285 - Temperature with Instance  //this is the one that's proprietary
**************
I went through this with my Furuno MFD showing the temp sensor, but not reading the data. I was unpleasantly surprised that wasn't the configuration of the sensor for water, engine room  temp, etc., that was screwing up the reading, but rather the Lowrance proprietary PGN.
Maybe if you can capture the raw data from the sensor, Timo can add this PGN to the library if possible to easy interpret what is what...
Cheers!
Bummer!  So are we out of luck? Or do you think there is a way I can capture the raw data from the sensor and share with the group -- just let me know how best to do this?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 02, 2017, 07:27 am
We seem to have information for PGN 65285 for Lowrance proprietary data.
{ "Lowrance: Temperature", 65285, false, 8, 0,
  { { "Manufacturer Code", 11, RES_MANUFACTURER, false, "=140", "Lowrance" }
  , { "Reserved", 2, RES_NOTUSED, false, 0, "" }
  , { "Industry Code", 3, RES_LOOKUP, false, "=4", "Marine Industry" }
  , { "Temperature Instance", 4, 1, false, 0, "" }
  , { "Temperature Source", 4, 1, false, 0, "" }
  , { "Actual Temperature", BYTES(2), RES_TEMPERATURE, false, "K", "" }
  , { 0 }
  }
}

So write handler for PGN 65285 and try code:
bool ParseN2kLowranceTempPGN65285(const tN2kMsg &N2kMsg, unsigned char &TempInstance, tN2kTempSource &TempSource,
                     double &ActualTemperature) {
  ActualTemperature=N2kDoubleNA;
  TempInstance=0;
  TempSource=N2kts_SeaTemperature;
  if (N2kMsg.PGN!=65285L) return false;
  int Index=0;
  uint16_t Manufacturer=(N2kMsg.Get2ByteUInt(Index) & 0x7ff);
  if ( Manufacturer != 140 ) return false; // Not Lowrance proprietary PGN
  uint8_t b=N2kMsg.GetByte(Index);
  TempInstance=(b & 0x0f);
  TempSource=(tN2kTempSource)( (b & 0xf0) >> 4 );
  ActualTemperature=N2kMsg.Get2ByteUDouble(0.01,Index);
 
  return true;
}
Title: Re: NMEA 2000 Shield
Post by: seamaster on Aug 02, 2017, 08:03 am
Quote
if ( Manufacturer != 140 ) return false; // Not Lowrance proprietary PGN
Timo,
don't forget that all of their sensors could be sold and go by either Lowrance, B&G or Simrad names. I think they have different manufacturer numbers/codes.
I found:
SIMRAD 1857;
Lowrance 140;
B&G ??; // I couldnt find one for them in the document here

http://www.nmea.org/Assets/20160116%20_%20jan%202016%20manu%20code%20and%20product%20code.pdf (http://www.nmea.org/Assets/20160116%20_%20jan%202016%20manu%20code%20and%20product%20code.pdf)

My point is: these 3 manufactures need to be included in the code not just Lawrance.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 02, 2017, 12:17 pm
B&G is 381 - on list "NMEA 2000 registration list". So change rule to:
  if ( !(Manufacturer == 140 ||
         Manufacturer == 1857 ||
         Manufacturer == 381) ) return false; // Not Lowrance, Simrad or B&G proprietary PGN
Title: Re: NMEA 2000 Shield
Post by: Rinkelein on Aug 02, 2017, 02:56 pm
I just tested WindMonitor with my own DUE and it works OK. I made tests with old NMEA2000_due/due_can and new version of both (just released on my GitHub few minutes ago). So I think the problem is not with library.

If you can read, but TX fails, there is some problem with your TX side. Have you checked TX pin is connected? Are terminal resistors OK? Maybe tranceiver does not work on TX?
Just to let you know that we have tested the TX side but weren't successfull. Several fora stated that this could be caused by the chip SN65HVD230. I've ordered a MCP2551 instead and will let you know later on. Thanks so far.
Title: Re: NMEA 2000 Shield
Post by: Rinkelein on Aug 02, 2017, 03:02 pm
I just tested WindMonitor with my own DUE and it works OK. I made tests with old NMEA2000_due/due_can and new version of both (just released on my GitHub few minutes ago). So I think the problem is not with library.

If you can read, but TX fails, there is some problem with your TX side. Have you checked TX pin is connected? Are terminal resistors OK? Maybe tranceiver does not work on TX?
Just to let you know that we weren't able to get the TX side working. From other fora we learned that this could be caused by the SN65HVD230 chip. We have ordered a MCP2551 and let you know the results later on. Many thanks so far.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 02, 2017, 03:28 pm
With DUE you need to remember to power MCP2551 with 3.3V only. I prefer MCP2562, since you can power it with 5V and provide 3.3V to pin 5 for defining IO levels.
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Aug 02, 2017, 04:54 pm
We seem to have information for PGN 65285 for Lowrance proprietary data.
{ "Lowrance: Temperature", 65285, false, 8, 0,
  { { "Manufacturer Code", 11, RES_MANUFACTURER, false, "=140", "Lowrance" }
  , { "Reserved", 2, RES_NOTUSED, false, 0, "" }
  , { "Industry Code", 3, RES_LOOKUP, false, "=4", "Marine Industry" }
  , { "Temperature Instance", 4, 1, false, 0, "" }
  , { "Temperature Source", 4, 1, false, 0, "" }
  , { "Actual Temperature", BYTES(2), RES_TEMPERATURE, false, "K", "" }
  , { 0 }
  }
}

So write handler for PGN 65285 and try code:
bool ParseN2kLowranceTempPGN65285(const tN2kMsg &N2kMsg, unsigned char &TempInstance, tN2kTempSource &TempSource,
                     double &ActualTemperature) {
  ActualTemperature=N2kDoubleNA;
  TempInstance=0;
  TempSource=N2kts_SeaTemperature;
  if (N2kMsg.PGN!=65285L) return false;
  int Index=0;
  uint16_t Manufacturer=(N2kMsg.Get2ByteUInt(Index) & 0x7ff);
  if ( Manufacturer != 140 ) return false; // Not Lowrance proprietary PGN
  uint8_t b=N2kMsg.GetByte(Index);
  TempInstance=(b & 0x0f);
  TempSource=(tN2kTempSource)( (b & 0xf0) >> 4 );
  ActualTemperature=N2kMsg.Get2ByteUDouble(0.01,Index);
 
  return true;
}

That's great Timo!  I guess I should have looked under the covers deeper -- Will add this method to my code and test at the boat today... will let you know.  My sensor is branded Lowrance with a manufacture code of 140 so we should be good.

Just to be clear, for the handler I'm adding:
Code: [Select]

...
{130314L,&Pressure},
  {130316L,&TemperatureExt},
  {65285,&LowranceTemp},
  {0,0}
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Aug 03, 2017, 02:26 am
That worked!  However, the source is "sea" not "engine room" -- I can live with that but not sure if you want to correct that in the library if you want to officially support this sensor.

This code:
Code: [Select]

void LowranceTemp(const tN2kMsg &N2kMsg) {
    unsigned char TempInstance;
    tN2kTempSource TempSource;
    double ActualTemperature;
   
    if (ParseN2kLowranceTempPGN65285(N2kMsg,TempInstance,TempSource,ActualTemperature) ) {
        OutputStream->print("Lowrance Temperature source: "); PrintN2kEnumType(TempSource,OutputStream,false);
        PrintLabelValWithConversionCheckUnDef(", actual temperature (F): ",ActualTemperature,&KelvinToF);
    } else {
      OutputStream->print("Failed to parse PGN: ");  OutputStream->println(N2kMsg.PGN);
    }
}

bool ParseN2kLowranceTempPGN65285(const tN2kMsg &N2kMsg, unsigned char &TempInstance, tN2kTempSource &TempSource,
                     double &ActualTemperature) {
  ActualTemperature=N2kDoubleNA;
  TempInstance=0;
  TempSource=N2kts_SeaTemperature;
  if (N2kMsg.PGN!=65285L) return false;
  int Index=0;
  uint16_t Manufacturer=(N2kMsg.Get2ByteUInt(Index) & 0x7ff);
  if ( Manufacturer != 140 ) return false; // Not Lowrance proprietary PGN
  uint8_t b=N2kMsg.GetByte(Index);
  TempInstance=(b & 0x0f);
  TempSource=(tN2kTempSource)( (b & 0xf0) >> 4 );
  ActualTemperature=N2kMsg.Get2ByteUDouble(0.01,Index);
 
  return true;
}


Produces:
Code: [Select]
Lowrance Temperature source: sea, actual temperature (F): 88.88
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 03, 2017, 05:58 am
Are you sure it is returning everything right and my code was right? Did you test output with different temp source - does it change? If the enum tN2kTempSource does not match to Lowrance, we need to define own:
Code: [Select]
enum tN2kLowranceTempSource {
                            N2kLts_EngineRoomTemperature=0
                            };

const char* tN2kLowranceTempSourceStrs[] = { "engine room" };

and solve what enum values are.
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Aug 03, 2017, 07:32 am
Are you sure it is returning everything right and my code was right? Did you test output with different temp source - does it change? If the enum tN2kTempSource does not match to Lowrance, we need to define own:
Code: [Select]
enum tN2kLowranceTempSource {
                            N2kLts_EngineRoomTemperature=0
                            };

const char* tN2kLowranceTempSourceStrs[] = { "engine room" };

and solve what enum values are.
I didn't try changing the TempSource -- but the TempInstance returned should have been 3 (as shown on my Lowrance HDS) which is "Engine Room", not 0 and Sea Temp as passed in the handler.  

Code: [Select]

bool ParseN2kLowranceTempPGN65285(const tN2kMsg &N2kMsg, unsigned char &TempInstance, tN2kTempSource &TempSource,
                     double &ActualTemperature) {
  ActualTemperature=N2kDoubleNA;
  >>>> TempInstance=0;
  >>>> TempSource=N2kts_SeaTemperature;
  if (N2kMsg.PGN!=65285L) return false;
  int Index=0;
  uint16_t Manufacturer=(N2kMsg.Get2ByteUInt(Index) & 0x7ff);
  if ( Manufacturer != 140 ) return false; // Not Lowrance proprietary PGN
  uint8_t b=N2kMsg.GetByte(Index);
  >>>> TempInstance=(b & 0x0f);
  >>>> TempSource=(tN2kTempSource)( (b & 0xf0) >> 4 );
  ActualTemperature=N2kMsg.Get2ByteUDouble(0.01,Index);
 
  return true;
}


But the code you provided didn't seem to get that  from the message data?

The Lowrance PGN I used in the handler was "65285", not "65285L" -- not sure if that matters?
Code: [Select]

...
 {130316L,&TemperatureExt},
 {65285,&LowranceTemp},


Interestingly, the Actual Temperature was correct value.

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 03, 2017, 08:01 am
Change your printing code to:
Code: [Select]

OutputStream->print("Lowrance Temperature (");
OutputStream->print(TempInstance);
OutputStream->print(") source: ");
OutputStream->print((unsigned char)TempSource);

and try with different sources (engine, water, cabin) and report the results.

L is integer literal and defines value to be treated as long. Actually for PGNs should have been UL
Title: Re: NMEA 2000 Shield
Post by: mavromatis on Aug 04, 2017, 08:11 pm
Change your printing code to:
Code: [Select]

OutputStream->print("Lowrance Temperature (");
OutputStream->print(TempInstance);
OutputStream->print(") source: ");
OutputStream->print((unsigned char)TempSource);

and try with different sources (engine, water, cabin) and report the results.

L is integer literal and defines value to be treated as long. Actually for PGNs should have been UL
So it looks like the TempSource is the issue -- the TempInstance is correct:

DEBUG:: Lowrance Temperature (Instance: 3 source: 0) // 3 is engine rm
DEBUG:: Lowrance Temperature (Instance: 4 source: 0) // 4 is cabin



Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 04, 2017, 08:56 pm
Please do not quote everything.

Change code to:
TempSource=(tN2kTempSource)(b & 0x0f);
TempInstance=( (b & 0xf0) >> 4 );
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Aug 06, 2017, 04:09 pm
Hi Timo and all,

I tend to built a depth alarm for NMEA 2000 first and later maybe something more ambitious. Have arduino due board and in the mail is coming http://copperhilltech.com/can-bus-mini-breakout-board/. I guess for NMEA-bus that 120 Ohm resistor has to picked off as bus has its own terminations. When trying to verify examples in Timos library following error is generated:


Arduino: 1.8.3 (Windows 10), Board: "Arduino Due (Programming Port)"





C:\Users\heikki\AppData\Local\Temp\arduino_build_230965\sketch\DataDisplay.ino.cpp.o: In function `__static_initialization_and_destruction_0':

C:\Users\heikki\Documents\Arduino\libraries\NMEA2000-master\src/NMEA2000_CAN.h:78: undefined reference to `tNMEA2000_due::tNMEA2000_due()'

collect2.exe: error: ld returned 1 exit status

Using library NMEA2000-master at version 1.1.141 in folder: C:\Users\heikki\Documents\Arduino\libraries\NMEA2000-master
Using library due_can-master at version 2.0.1 in folder: C:\Users\heikki\Documents\Arduino\libraries\due_can-master
exit status 1
Error compiling for board Arduino Due (Programming Port).



Left some jargon of in between the error message in order to make message shorter. What could possibly go wrong here?

Br:  Heikki
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 06, 2017, 06:42 pm
Reload the NMEA2000_due (https://github.com/ttlappalainen/NMEA2000_due) library. I can produce that error if I remove file NMEA2000_due.cpp from path libraries\NMEA2000_due-master so I expect you are missing that file.
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Aug 06, 2017, 06:52 pm
I will try as Timo suggested. There is a file like that in the location with size of 3KB.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 06, 2017, 07:56 pm
Then you could also try to remove completely your NMEA2000_due-master directory. Then it should give error:
In file included from xxx\Arduino\Examples\xxx\xxx:x:x

xxx\Arduino\libraries\NMEA2000/NMEA2000_CAN.h:77:26: fatal error: NMEA2000_due.h: No such file or directory

 #include <NMEA2000_due.h>

If not you have NMEA2000_due.h somewhere, where it should not be.
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Aug 06, 2017, 07:58 pm
Now examples seem to verify correctly. Since my adventure with arduino is 5 days old I uninstalled and deleted everything related to arduino and downloaded everything again. Strangely enough computer still had stuff for due board left.
Title: Re: NMEA 2000 Shield
Post by: marcop20 on Sep 21, 2017, 12:45 am
Hi Timo, I'm using your library and I want to congratulate you first and foremost for the work you've done.

We come to the question ......

I joined n2k at my Lowrance Elite Ti and although I can see the device and all the data stream I can not see product information.

In their place I see blank fields, and in the selection of sources I see three question marks

I see that another user with the Lowrance HDS (page 14) had the same problem and then seems to have resolved it.

You could help me please

I'm using the latest version of your library, arduino-mega and shield can-bus V1.2
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 21, 2017, 06:33 am
Hi, and thanks.

I did not find your reference for "Lowrance HDS" - I made just quick search with "Lowrance" and "HDS".

Have you tested that with e.g. example TemperatureMonitor and not done any memory squeezing prefered for Uno board? You could also try does it help to enable interrupt by adding line
Code: [Select]
#define N2k_CAN_INT_PIN xx
before any includes. xx is the pin where interrupt has been connected on CAN_BUS shield.

You could also enable rows on example:
Code: [Select]
  delay(5000); // add this row to have time to open serial monitor
  Serial.begin(115200);
  NMEA2000.SetForwardStream(&Serial);
  NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text. Leave uncommented for default Actisense format.


And record the communication and email me.

In principle MDF devices should query "Product information", when they see new device on the bus. There are two way to do that and current version of library support only PGN request. I will publish new version of library within few days after finishing tests. That support also responding to query done by "Request group function" for "Product information". Meanwhile there are two possibilities:
1. Email me directly so I can send you a test release, which has that support.
2. Add to loop() code to send ProductInformation in every 1-2 sec.
Code: [Select]
#define ProductInformationSendPeriod 2000
void loop() {
  static unsigned long ProductInformationSendTime=millis()+ProductInformationSendPeriod ;
    if ( ProductInformationSendTime<millis() ) {
       NMEA2000.SendProductInformation();
       ProductInformationSendTime=millis()+ProductInformationSendPeriod ;
    }
}


Even if 2. will work, I prefere to test without it with new release. And I would like to get anyway the information for the solution.
Title: Re: NMEA 2000 Shield
Post by: marcop20 on Sep 21, 2017, 02:21 pm
Hi Timo .....
I solved Method 2, that is, sending the ProductInformation every two seconds as recommended by you.
Anyway I attach you the log obtained on Arduino's serial monitor.

Code: [Select]

CAN device ready
Start address claim for device 0
Pri:6 PGN:60928 Source:22 Dest:255 Len:8 Data:1,0,C0,FF,0,84,32,C0
Pri:3 PGN:127488 Source:22 Dest:255 Len:8 Data:0,F8,43,FF,FF,7F,FF,FF
Pri:3 PGN:129026 Source:22 Dest:255 Len:8 Data:1,FC,D0,4E,A,0,FF,FF
Pri:3 PGN:127488 Source:22 Dest:255 Len:8 Data:0,F8,43,FF,FF,7F,FF,FF
Pri:3 PGN:129026 Source:22 Dest:255 Len:8 Data:1,FC,D0,4E,A,0,FF,FF
Pri:3 PGN:127488 Source:22 Dest:255 Len:8 Data:0,F8,43,FF,FF,7F,FF,FF
Pri:3 PGN:129026 Source:22 Dest:255 Len:8 Data:1,FC,D0,4E,A,0,FF,FF
Pri:3 PGN:127488 Source:22 Dest:255 Len:8 Data:0,F8,43,FF,FF,7F,FF,FF
Pri:3 PGN:129026 Source:22 Dest:255 Len:8 Data:1,FC,D0,4E,A,0,FF,FF
Pri:6 PGN:127508 Source:22 Dest:255 Len:8 Data:1,F8,4,FF,7F,FF,FF,1
Pri:6 PGN:127508 Source:22 Dest:255 Len:8 Data:0,64,5,A,0,FF,FF,0
Pri:6 PGN:130316 Source:22 Dest:255 Len:8 Data:1,1,4,74,7D,4,84,B
Pri:6 PGN:130312 Source:22 Dest:255 Len:8 Data:1,1,4,F2,72,23,73,FF
Pri:6 PGN:130311 Source:22 Dest:255 Len:8 Data:1,4,F2,72,B6,35,F6,3
Pri:6 PGN:130310 Source:22 Dest:255 Len:8 Data:1,C1,70,95,74,F6,3,FF
Pri:6 PGN:127513 Source:22 Dest:255 Len:8 Data:1,D2,1,9A,1,5F,82,61
Pri:6 PGN:127506 Source:22 Dest:255 Len:9 Data:1,1,1,56,5B,8C,5,D2,0
Pri:2 PGN:127257 Source:22 Dest:255 Len:8 Data:1,E3,FD,A3,1,AF,FA,FF
Pri:6 PGN:127489 Source:22 Dest:255 Len:26 Data:0,A0,19,B,E,C5,8A,8D,5,39,0,4C,6B,75,0,FF,FF,FF,FF,FF,1,0,0,0,7F,7F
Pri:6 PGN:127493 Source:22 Dest:255 Len:8 Data:0,FC,4C,1D,3B,D,5,FF
Pri:3 PGN:126992 Source:22 Dest:255 Len:8 Data:1,0,93,44,0,73,F4,24
Pri:6 PGN:129029 Source:22 Dest:255 Len:47 Data:1,93,44,0,73,F4,24,0,80,2,D6,50,2E,57,8,0,80,76,D2,4E,5C,1F,3,A0,37,A0,0,0,0,0,0,10,1,C,50,0,32,0,DC,5,0,0,1,F0,0,C8,0
Pri:6 PGN:129539 Source:22 Dest:255 Len:8 Data:1,6C,78,0,B0,FF,FF,7F
Pri:2 PGN:127250 Source:22 Dest:255 Len:8 Data:0,1A,9B,F4,FD,C0,3,FD
Pri:6 PGN:129038 Source:22 Dest:255 Len:27 Data:41,15,CD,5B,7,80,86,45,D0,C0,B5,BB,F,7,40,D,D0,7,FF,FF,FF,E0,93,0,0,F1,FF
Pri:6 PGN:127501 Source:22 Dest:255 Len:8 Data:2,CD,FF,FF,FF,FF,FF,FF
Pri:6 PGN:130314 Source:22 Dest:255 Len:8 Data:0,2,0,0,A0,F,0,FF
Pri:2 PGN:127245 Source:22 Dest:255 Len:8 Data:1,F9,97,FC,69,3,FF,FF
Pri:6 PGN:127501 Source:22 Dest:255 Len:8 Data:3,FF,DF,FF,FF,FF,FF,FF
Pri:3 PGN:127488 Source:22 Dest:255 Len:8 Data:0,F8,43,FF,FF,7F,FF,FF
Pri:3 PGN:129026 Source:22 Dest:255 Len:8 Data:1,FC,D0,4E,A,0,FF,FF
Pri:3 PGN:127488 Source:22 Dest:255 Len:8 Data:0,F8,43,FF,FF,7F,FF,FF
Pri:3 PGN:129026 Source:22 Dest:255 Len:8 Data:1,FC,D0,4E,A,0,FF,FF
Pri:3 PGN:127488 Source:22 Dest:255 Len:8 Data:0,F8,43,FF,FF,7F,FF,FF
Pri:3 PGN:129026 Source:22 Dest:255 Len:8 Data:1,FC,D0,4E,A,0,FF,FF
Pri:3 PGN:127488 Source:22 Dest:255 Len:8 Data:0,F8,43,FF,FF,7F,FF,FF
Pri:3 PGN:129026 Source:22 Dest:255 Len:8 Data:1,FC,D0,4E,A,0,FF,FF
Pri:3 PGN:127488 Source:22 Dest:255 Len:8 Data:0,F8,43,FF,FF,7F,FF,FF
Pri:3 PGN:129026 Source:22 Dest:255 Len:8 Data:1,FC,D0,4E,A,0,FF,FF
Pri:3 PGN:127488 Source:22 Dest:255 Len:8 Data:0,F8,43,FF,FF,7F,FF,FF
Pri:3 PGN:129026 Source:22 Dest:255 Len:8 Data:1,FC,D0,4E,A,0,FF,FF
Pri:6 PGN:127508 Source:22 Dest:255 Len:8 Data:1,F8,4,FF,7F,FF,FF,1
Pri:6 PGN:127508 Source:22 Dest:255 Len:8 Data:0,64,5,A,0,FF,FF,1
Pri:6 PGN:130316 Source:22 Dest:255 Len:8 Data:1,1,4,74,7D,4,84,B
Pri:6 PGN:130312 Source:22 Dest:255 Len:8 Data:1,1,4,F2,72,23,73,FF
Pri:6 PGN:130311 Source:22 Dest:255 Len:8 Data:1,4,F2,72,B6,35,F6,3
Pri:6 PGN:130310 Source:22 Dest:255 Len:8 Data:1,C1,70,95,74,F6,3,FF
Pri:6 PGN:127513 Source:22 Dest:255 Len:8 Data:1,D2,1,9A,1,5F,82,61
Pri:6 PGN:127506 Source:22 Dest:255 Len:9 Data:1,1,1,56,5B,8C,5,D2,0
Pri:2 PGN:127257 Source:22 Dest:255 Len:8 Data:1,E3,FD,A3,1,AF,FA,FF
Pri:6 PGN:127489 Source:22 Dest:255 Len:26 Data:0,A0,19,B,E,C5,8A,8D,5,39,0,4C,6B,75,0,FF,FF,FF,FF,FF,1,0,0,0,7F,7F
Pri:6 PGN:127493 Source:22 Dest:255 Len:8 Data:0,FC,4C,1D,3B,D,5,FF
Pri:3 PGN:126992 Source:22 Dest:255 Len:8 Data:1,0,93,44,0,73,F4,24
Pri:6 PGN:129029 Source:22 Dest:255 Len:47 Data:1,93,44,0,73,F4,24,0,80,2,D6,50,2E,57,8,0,80,76,D2,4E,5C,1F,3,A0,37,A0,0,0,0,0,0,10,1,C,50,0,32,0,DC,5,0,0,1,F0,0,C8,0
Pri:6 PGN:129539 Source:22 Dest:255 Len:8 Data:1,6C,78,0,B0,FF,FF,7F
Pri:2 PGN:127250 Source:22 Dest:255 Len:8 Data:0,1A,9B,F4,FD,C0,3,FD
Pri:6 PGN:129038 Source:22 Dest:255 Len:27 Data:41,15,CD,5B,7,80,86,45,D0,C0,B5,BB,F,7,40,D,D0,7,FF,FF,FF,E0,93,0,0,F1,FF
Pri:6 PGN:127501 Source:22 Dest:255 Len:8 Data:2,CD,FF,FF,FF,FF,FF,FF
Pri:6 PGN:130314 Source:22 Dest:255 Len:8 Data:0,2,0,0,A0,F,0,FF
Pri:2 PGN:127245 Source:22 Dest:255 Len:8 Data:1,F9,97,FC,69,3,FF,FF
Pri:6 PGN:127501 Source:22 Dest:255 Len:8 Data:3,FF,DF,FF,FF,FF,FF,FF
Pri:3 PGN:127488 Source:22 Dest:255 Len:8 Data:0,F8,43,FF,FF,7F,FF,FF
Pri:3 PGN:129026 Source:22 Dest:255 Len:8 Data:1,FC,D0,4E,A,0,FF,FF
Pri:3 PGN:127488 Source:22 Dest:255 Len:8 Data:0,F8,43,FF,FF,7F,FF,FF
Title: Re: NMEA 2000 Shield
Post by: marcop20 on Sep 21, 2017, 02:34 pm
Timo...
I forgot ..... if you have a version of the new library I would be happy to test it.
And .... thanks again for all the work you did
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 21, 2017, 02:52 pm
Method 2 is not right and good solution. Also your record did not had any message from Lowrance. Was it connected? Sorry I forgot to say that you have to comment line
Code: [Select]
// NMEA2000.EnableForward(false); // Disable all msg forwarding to USB (=Serial)
And you should:
- Program Mega with some dummy program, which does not communicate with N2k bus
- Turn Lowrance on. Should not have any Temerature monitor info!
- Open Mega serial monitor
- Program TemperatureMonitor to Mega
- Now it Mega should start after delay(5000) - did you add it - to initialize it on the bus

Also leave peridical SendProductInformation away from this test. I would like to get list of conversation between Mega and Lowrance. I am looking for, which message it uses for query.

You can send you email with private message, so I can send code to you.
Title: Re: NMEA 2000 Shield
Post by: marcop20 on Sep 21, 2017, 08:17 pm
Hi Timo ....
I compared the two logs obtained with and without the modification in the loop .....

It looks like PGN: 126996 is not sent


Title: Re: NMEA 2000 Shield
Post by: pkeiramo on Oct 03, 2017, 11:27 am
Hello Timo and thanks for the great job you have done!

I'm trying out to use your NMEA0183 library and NMEA0183ToN2k.ino example within it.

I can't compile it because it seems that HardwareSerial.availableForWrite() method is not implemented for Arduino Due. How did you get around this? I understood that you have used Due also.

I have Arduino Time library, Standard C++ library for Arduino and NMEA2000 library.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 03, 2017, 12:09 pm
They did implemented that for Due some time ago, but it has been left halfway. But you just need to add to both:
"C:\Users\<your account>\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino\Print.h"
and
"C:\Users\<your account>\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino\HardwareSerial.h"

virtual definition under public methods:
public:
...
    virtual int availableForWrite(void) = 0;
...

Then it compiles with DUE too. Note that path depends of your core version, but you understand what files I mean.
Title: Re: NMEA 2000 Shield
Post by: pkeiramo on Oct 03, 2017, 08:18 pm
Yes - now it compiles. Thanks!

My target is to get my old Raymarine RC435 plotter connected to NMEA2000 network. We'll see, how story continues...
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 04, 2017, 01:40 am
Do you need both direction communication? I had problem with due Serial - with lot of traffic both direction it stopped communication time to time. That was before there was availableForWrite. I do not know about other Serials.

Keep me updated - I may have unpublished code/ideas.
Title: Re: NMEA 2000 Shield
Post by: pkeiramo on Oct 04, 2017, 11:49 am
I think that there is no need to send any messages to plotter. It can receive only WPL and RTE messages and I don't see much use for sending them to plotter from network.


But you'll never know - maybe appetite grows during coding. I'll keep you updated.
Title: Re: NMEA 2000 Shield
Post by: Rinkelein on Oct 07, 2017, 12:29 pm
Dear Timo,

On August 2nd I indicated that we would purchase the MCP2551 in order to be able to send PGN´s to the backbone. In the meantime the chip has arrived an we were able to make it work as the photo´s will prove.

Many thanks and for those who can read Dutch, please visit my website. Apart from being able to read and write to the backbone I also managed to convert the PGN´s into NMEA0183 and send them over WiFi and use if with OpenCPN.

http://rinkelein.000webhostapp.com/NMEA2000.html

Title: Re: NMEA 2000 Shield
Post by: Heikkif on Nov 27, 2017, 08:20 pm
Thank you Timo for great work on this,

I was able to read data from NMEA 2000 bus to Arduino Due but sending data to bus so that it could be seen on Garmin GNX 20 does not seem to work. I have connected both with MCP2562 as the drawing here shows:https://github.com/ttlappalainen/NMEA2000/blob/master/Documents/ArduinoDUE_CAN_with_MCP2562.pdf and also with this: http://copperhilltech.com/can-bus-mini-breakout-board. This test arrangement for hardware works http://copperhilltech.com/blog/app-note-testing-arduino-due-with-2-can-bus-breakout-boards/. I have uploaded sketches temp monitor and wind monitor as they are in examples folder but no wind data nor temp data when eco/temp sensor is not present can be seen on display. Only data source visible is the eco/temp sensor when it is connected. Actisense reader sees transmission when requested lines are commented/uncommented for testing. Library is of latest version.

Any advice how to debug this futher?

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Nov 27, 2017, 09:43 pm
I just tested few days ago TemperatureMonitor example with due and it works as it should. Some things:
- Remember to use at least one terminator resistor on bus even with short test bus wires.
- Check that you use due_can from my repository: https://github.com/ttlappalainen/due_can . Others does not compile or possibly does not work right.

Have you checked that you see any data e.g. with example ActisenseListener?
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Nov 29, 2017, 08:51 pm
Hi again Timo,

Made sure the due_can is the correct one from your repository. There is a termination resistor on the bus but only at the other end when using MCP2562. When uncommenting
 Serial.begin(115200);
 NMEA2000.SetForwardStream(&Serial);
and commenting //NMEA2000.EnableForward(false); Actisense NMEA Reader shows the data being sent
but nothing can be seen on display. Log shows some timeouts on updating operating mode, product info, configuration info. There is one unknown line on data view PGN 126993 and ISO address Claim seems to come when reset is pushed.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Nov 30, 2017, 08:21 am
Uncomment also NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); and look due output with serial monitor in. In text mode it shows possible internal errors in clear text. I expect you would get "Send failed" text.

When you read messages from sender USB, it shows messages, which it has tried to send to the bus. It does not mean that they have gone out to the bus from the lower level library. So in text mode you will see if libray buffers start to over run dues to sending proboem.

It is still unclear for mee, which side you read ISO address claim and 126993. Do you have other board connected to the bus or just due and you read its USB?

126993 is heartbeat PGN and old NMEA Reader does not know it.
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Nov 30, 2017, 06:50 pm
Here is what is seen on serial monitor:

Initialize buffers
CAN device ready
Start address claim for device 0
202 : Pri:6 PGN:60928 Source:22 Dest:255 Len:8 Data:69,B6,1,FF,0,82,96,C0
2703 : Pri:6 PGN:130312 Source:22 Dest:255 Len:8 Data:1,1,4,7D,73,FF,FF,FF
2703 : Pri:6 PGN:130311 Source:22 Dest:255 Len:8 Data:1,44,7D,73,FF,7F,FF,FF
2705 : Pri:6 PGN:130310 Source:22 Dest:255 Len:8 Data:1,C1,70,FF,FF,FF,FF,FF

that goes on until

45220 : Pri:6 PGN:130311 Source:22 Dest:255 Len:8 Data:1,44,7D,73,FF,7F,FF,FF
PGN 130310 send failed
45224 : Pri:6 PGN:130310 Source:22 Dest:255 Len:8 Data:1,C1,70,FF,FF,FF,FF,FF
PGN 130312 send failed
47721 : Pri:6 PGN:130312 Source:22 Dest:255 Len:8 Data:1,1,4,7D,73,FF,FF,FF
PGN 130311 send failed
47721 : Pri:6 PGN:130311 Source:22 Dest:255 Len:8 Data:1,44,7D,73,FF,7F,FF,FF
PGN 130310 send failed
47729 : Pri:6 PGN:130310 Source:22 Dest:255 Len:8 Data:1,C1,70,FF,FF,FF,FF,FF

It makes no difference if arduino is connected to bus with display or not. So far I have tried only with one arduno. I have two arduinos and available so I could add another to the bus and see what it sees an the bus. Would Actisense listener be the sketch to download to the other arduino? So far I only have tested hardware with one arduino with this test program:
 http://copperhilltech.com/blog/app-note-testing-arduino-due-with-2-can-bus-breakout-boards/
 and it works and also have been able to read depth sounder from the bus.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Nov 30, 2017, 08:45 pm
That was I expected. When it comes to situation that send fails continuously, internal buffers are full and so it gives error. This means that no message goes out. This is normally caused, when there is no connection to the bus. Most common error has been that CAN-L and CAN-H has been crossed or chip (MCP2562) STBY signal is not connected to GND. Also missin terminal resistor is common reason, but that you already checked.

I just made a test with due. When it is connected to the bus, but there is no other devices on, it start to give error. Immediately, when I turn on any other device, it start to send normally.
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Nov 30, 2017, 09:21 pm
With the same connection I can read depth sounder info from the bus so the connection could be ok. Also that two channel test shows the connection should be ok.  Could it be that GNX 20 is "refusing" to communicate with non genuine NMEA 2000 device? Would it be interesting to know if the other arduino with actisense listener sketch is reading what the other with temperature monitor is sending? Would two arduinos one sending  and one recieving see each other as devices on the bus?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 01, 2017, 05:48 am
N2k bus devices does not normally care who is sending data. They can show e.g. speed data even knowing anything about sender device. This of coarse may denpend of MFD, but e.g. my Garmin GMI 20 does not care. It just shows on devices "unknown device"

Two Arduinos communicate also well. There are examples MessageSender and DataDisplay2, which I have used to test different messages. They does not act as like normal N2k bus device. TemperatureMonitor is the most closes of certified device. So by connecting two TemperatureMonitor to the bus, they do all handshaking and sees each other, but since they are just sending data, they does not listen each other messages. If you change mode to N2k_ListenAndNode and enable message forwarding, then they will forward others messages.

I have to do some more tests. If you have some device sending on bus, then everything works fine, when you connect device. If I start due first and then connect my MFD, it start to work right. If I have due and then connect other TemperatureMonitor, it may get totally blocked.

So you could try cnnecting your MFD, depth sounder and due to the bus and then start due.
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Dec 01, 2017, 06:46 pm
I was testing Wind Monitor with eco and display last autumn but no wind info showed up on the display. It was then when I was able to read depth from the bus. Now depth sounder is at the boat and arduino and display are at home.
 When testing two arduinos in the bus should they be connected with separate T-connections or is it ok to connect them at the same branch?
 Can the send failed caused by failing hand shake? I will test two arduinos this weekend. The other could be loaded with TemperatureMonitor but which sketch to load to the other?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 01, 2017, 08:00 pm
For test bed it is enough to connect CAN-L/CAN-H with wires. I personally do not use M12 connectors at all, since they require so much space. Instead I use pluggable board connectors (see e.g. farnell codes 1717013 and 1717025 Connector order is shown on my drawing https://github.com/ttlappalainen/NMEA2000/blob/master/Examples/TeensyActisenseListenerSender/Documents/Teensy_Actisense_listener_sender_schematics.pdf). With those you can make CAN bus divider for 5 connectors to 100x55x40 mm box with about 20 €.

Due should work with just display connected. You could also use ActisenseListener example on due and when you turn on display, it should send ISO Address (PGN 60928) claim at the beginning. It is strange, if you do not receive anything from display.

There is actually no handshaking betwee N2k devices. They just do address claiming, which means they ask "I would like to use address 20". If other devices on the bus are happy for that, thats it. If there is other device using address 20, it compares its "name" to other and then either responces "I have address 20" or "I would like to use address 21" depending of priority of "name". All this will be done just using ISO address claim PGN.

The block I caused on my test was because of having two TemperatureMonitor with same "name" on the bus. This should never happen, since as I have documented for SetDeviceInformation: "Each device from same manufacturer should have unique number.". So if you have two TemperatureMonitor, you have to compile one with e.g. Unique number=112233 and other with Unique number=112234
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Dec 03, 2017, 05:03 pm
Played with two dues and display connected as a bus. Both dues can see display info trough actisense listener as it is turned on. When the other due has Temperature monitor loaded it can't be seen on the other board with actisense listener. Also send failed appears after a while as previously.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 04, 2017, 04:13 pm
Unfortunately I can not produce that. I have only one due, so I can not test with two dues. But with due/TemperatureMonitor and Teensy/ActisenseListener it works fine. If I disconnect Teensy, "Send failed" appears, but immediately after powering it on, also due starts to send.
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Dec 06, 2017, 05:33 pm
To exclude software problem is it possible to download program to due from a file instead of first compiling it from sketch and libraries on my own computer? If so then both problems with libraries and Arduino programming IDE on my computer would be excluded.  Other way around would be to test my hardware with known working environment.
I think I have the correct due can and NMEA 2000 due as if I remove either of them compiling fails and when I download them from your repository compiling is successful.  Could there be a problem in the IDE on my computer?
I have two different CAN transceivers and they both receive but neither of them send with this software. Anyhow I have tested them both with a test program behind this link and it says they are ok: http://copperhilltech.com/content/Due_2CAN_Channel_Test.zip
After testing i have removed all of that CAN stuff from my computer.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 06, 2017, 06:21 pm
I have IDE 1.83, I do not believe that is the problem. Could you recheck STBY pin on MCP2562! In Coppertechhill code there is code:
Code: [Select]
cRetCode = Can0.begin(lBaudrate, ENABLE_PIN_CAN0);
and
#define ENABLE_PIN_CAN0      62

In my examples there is no enable pin used and STBY has been expected to be connected to GND. Start e.g. TemperatureMonitor and measure with voltmeter that STBY has 0 voltage.
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Dec 06, 2017, 07:37 pm
The IDE on my computer is the same then. Pins 2 and 8 are connected to ground on MCP2562. If i solder another MCP2562 with connections for due and mail it to you after having tested what it does would you test it yourself? You would not have to return it.
Title: Re: NMEA 2000 Shield
Post by: Johannes_BlackSam on Dec 06, 2017, 10:03 pm
Hi Timo and all.

I'm new here and for starters I'd like to say thanks to all of you for contributing tons of useful information on this topic. In fact, the info is so much it is overwhelming, for me being a newbie anyway.

Since this topic was started lots have changed with regards to new hardware available and changes to sketches as well, where to start.

I guess keeping it simple is the way to go for starters.

Basically I need some guidance as to what direction to go in in order to inject IMU heading data into my fishing boat NMEA2000 network.

I don't have any hardware yet so this is a fresh start, I'd like to keep it as cheap, small, simple and the least power consuming as possible. (with "No Hardware" I'm not referring to my boat equipment, I mean no MicroPrcessor Unit, CanBus Shield, Serial Converters etc.)

At a later stage I'd like to further my knowledge with NMEA0183 <-> NMEA2000 data sharing and monitoring.

Some direction and opinions would be much appreciated.

Thanks guys.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 06, 2017, 10:07 pm
Heikkif - yes, I can test it.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 06, 2017, 10:17 pm
As I have many times mentioned on this list I prefer at least Teensy 3.2. It draws only 90 mA current.

But before goint to hw, it is best to have some kind of idea about the goal. Either you did not mention what your IMU sends.
Title: Re: NMEA 2000 Shield
Post by: Johannes_BlackSam on Dec 06, 2017, 10:29 pm
As I have many times mentioned on this list I prefer at least Teensy 3.2. It draws only 90 mA current.

But before goint to hw, it is best to have some kind of idea about the goal. Either you did not mention what your IMU sends.
Haven't bought any components yet, I was hoping for good recommendations before I go out and spend money.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 06, 2017, 10:56 pm
Yes, but I can not give any recommendations, if you do not define any goal. And what about IMU - do you have any? Do you have or have you planned to buy some MFD? What sensors you would like to have? Did you thought to use PC, phone tablet? Etc.
Title: Re: NMEA 2000 Shield
Post by: Johannes_BlackSam on Dec 07, 2017, 12:21 am
I was thinking of using the SparkFun 9DoF Razor IMU, can it be combined with your Teeny 3.2 setup in order to inject heading data to NMEA2000 network?

I would probably use my PC for starters to set everything up and monitor for correct operation, thereafter it should be externally powered and run as a standalone system as to have a stable heading on my Lowrance Elite 7Ti unit.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 07, 2017, 05:24 am
One company has started to make Teensy based sensor boards for NMEA2000. They contacted me due to my library and send me some sample boards. There is one nice ready IMU board. I can ask are they ready to sell.

On the other hand I have tested different IMU:s and none of then can not beat my GPS compass, which gives reliable 1 deg heading in any condition and boat tilt. You can get reasonable GPS compass in about 1000 € or spent 50-100 hours with IMU:s.
Title: Re: NMEA 2000 Shield
Post by: Johannes_BlackSam on Dec 07, 2017, 11:24 am
One company has started to make Teensy based sensor boards for NMEA2000. They contacted me due to my library and send me some sample boards. There is one nice ready IMU board. I can ask are they ready to sell.
I'd be interested thanks

You can get reasonable GPS compass in about 1000 € or spent 50-100 hours with IMU:s.
Lowrance Point 1 GPS/Heading antenna €280, but that defeats the object of accomplishing the task myself as a project.

Thanks for your input.
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Dec 07, 2017, 05:18 pm
Hi Johannes and Timo,

A bit offtopic maybe. I have been building compass also. It works but accuracy is not within 1 deg more like 3 degs. Self made compass might be feasible to control tiller pilot as gyro and heel data is also available from IMU.  I am using DUE for this as it was the first thing I bought for another purpose. Sparkfun has currently 3 products for this purpose. There are other sources also. For MPU 9250 there is no library from Sparkfun that would run on DUE. Haven't found elsewhere either. I am using LSM9DS1 which I can read to DUE. Otherwise ok but magnetometer needs temperature compensation and that I had to program on Arduino. I haven't found out how sensors own temperature compensation works. The sensor has temperature output but it looks like the resolution is a bit coarse compared to the slope of compensation needed. That limits the accuracy. LSM9DS1 means lot of calibration and each sensor needs its own calibration so if one needs to replace the sensor the calibration has to be done again.   Third one on Sparkfun would be that razor Johannes mentioned. It uses MPU 9250. It is not clear to me if the libraries can be loaded to for example teensy as well. If so then why not to use MPU 9250 and some board that is easily CAN-compatible. MPU 9250 should have factory calibration data stored in it. I do not know if the sketches can use it. People mention good calibration is needed with MPU 9250 also.
Some links worth checking:

http://sailboatinstruments.blogspot.fi/2014/08/a-low-cost-marine-compass-part-3.html
http://sailboatinstruments.blogspot.fi/2016/04/building-your-own-nmea-2000-device.html (this made me buy DUE when I found out Garmin GNX 20 does not have shallow water alarm)
http://www.pypilot.org/
https://github.com/seandepagnier/RTIMULib2
https://github.com/kriswiner/MPU9250
https://create.arduino.cc/projecthub/mitov/arduino-accelerometer-gyroscope-compass-mpu9250-i2c-sensor-79f5bf


Title: Re: NMEA 2000 Shield
Post by: Johannes_BlackSam on Dec 07, 2017, 05:47 pm
Thanks Heikkif, I'll look at your links and see what I can find useful.

I see the Genuino 101 has onboard IMU, wonder if this is worth looking at and if it would be compatible with the Tweeny 3.2 setup to get IMU data onto the Can Bus network?
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Dec 07, 2017, 08:43 pm
"I see the Genuino 101 has onboard IMU" It has gyro and accel but for compass magnetometer is also needed.
Title: Re: NMEA 2000 Shield
Post by: Johannes_BlackSam on Dec 07, 2017, 09:07 pm
"I see the Genuino 101 has onboard IMU" It has gyro and accel but for compass magnetometer is also needed.
Aahaa, thanks mate
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Dec 09, 2017, 02:50 pm
Hi,

I want to try to use a DUE to translate all the analog engine data from my V8 to be shown on my Raymarine Axoim through NMEA2000.

To do so I wanted to play a bit with the DUE and the multidevice example file.
I get this error while compiling it:

"In file included from /home/thomas/Arduino/libraries/NMEA2000_due-master/NMEA2000_due.cpp:28:0:
/home/thomas/Arduino/libraries/due_can-master/src/due_can.h:23:24: fatal error: can_common.h: No such file or directory
 #include <can_common.h>"

I added all the libraries from github which where asked for, also the due_can but without  luck.

First I tried it under Windows but there I got a lot of error due to the path to the libraries as there where wirtten / instead of \ in the pathes (if this was the reason for).

So can you help to find why it wants the can_common.h even if it not existing in the due_can libraries or what I am doing wrong?

I just choosed the example "MultiDevice" and added  the NMEA200_DUE librarie due to I want to use the Due.

Regards!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 09, 2017, 07:24 pm
I have not yet updated the docs. Collin has made some changes and it does not compile anymore and I have not had time to check those. Please remote you current due_can completely and install the one under my repositories: https://github.com/ttlappalainen/due_can

In c/c++ language one should use only /, since then code in compatible with Linux and Mac. Translator will take care of right way of pointing directories.

Also I do not any use for you to start with MultiDevice example. I prefere to use some simpler example like TemperatureMonitor.
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Dec 10, 2017, 05:23 pm
Hi again Timo,

I soldered another MCP2562 with connections for DUE. Is it ok to post it to Kave Oy with your name?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 10, 2017, 05:37 pm
Please send me personal message, so I'll give you address.
Title: Re: NMEA 2000 Shield
Post by: Yneptik on Dec 20, 2017, 09:18 pm
Hi Timo.

I'm quite new with Arduino but your work seems to be huge and amazing.

I would like to use the NEMA 2000 library to make a remote control for an Raymarine EV100 Autopilot.
This new generation of autopilots talks with seatalkNG which is, I think NMEA2000.
I want to use a 433Mghz remote.

Have you ever try this ? Do you think it could be doable ?

In advance, thanks



Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 21, 2017, 04:41 am
Yes it is doable. I have the same problem. But there is big challence, since all autopilot control commands are proprietary. This means that there is no documentations about them. So this requires bus traffic spying and some knowledge of the NMEA2000 protocol, since you have to read messages bit by bit to find out how autopilor will be controlled.

I have older model SPX-10 and I would imagine they use same protocol. Last summer I did some spying and I think I found a way to send course command to pilot and the way how to turn pilot on/off. Anyway I have not tried that yet.

So now it depends very much about you total skills can you do it or not.
Title: Re: NMEA 2000 Shield
Post by: Yneptik on Dec 21, 2017, 08:24 am
Thank you for your answer.

My skills in C/C++ are almost at zero :( .
I will try to investigate all of this and I will at first try to do an NMEA0183 -> NMEA2000 converter to train...
I'll tell you if I go further.

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 21, 2017, 09:01 am
But have you used other languages? C/C++ is not the easiest to start.

In my repository there is also NMEA0183 library, which I have used for my NMEA0183 -> NMEA2000 converter. There is also ready example.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Dec 25, 2017, 05:14 pm
Hello Timo,

I made to proto types of can adapters now. One for the 2560 and the other for the DUE.

So now my plan is to get the DUE to send GPS data from a Blox NEO-6m (NMEA2K based GPS) on the NMEA2K bus. I have a MFD from Raymarine (Axiom 9") which shell show all analog data from the engine and use the new build external GPS reciever.

I think the best is to start to simulate the engine temp as first try and get it shown on the MFD.

My problem is that I am a bit confused about what hae to be used (libray) where and how.
I found the NMEA2K sender example. I guess this is the one to use with the CAN shield to send the messages on the bus. BUT do I have to use a seperate Arduino to convert the analg signal to nmea2k message which than will be send through the DUE which is running the sender library?

I have read a lot of sites from this post but this made it more worth?!  :smiley-eek:

So like I wrote the plan is to grap all analog data signals from the engine and drop it to the MFD through nmea2k.

Lets say I have engine coolant temp, rpm, oil pressure, battary voltage/charge, gasoline/hr, tank level, rudder position and air temp in the engine room.

How would you organize this and what is to be used where? I meen for example 2560 for coolant temp behind the DUE which is running the sender?

Would be great if you could help me to understand the general setup!

Thank you and happy holidays to all!

Br
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 25, 2017, 07:30 pm
I rather prefer to take TemperatureMonitor as first example to make something work. You can run it either with Mega (2560) or DUE. It will compile on both without problems. Others have had problems with DUE to send data to bus for some reason, which is not yet clear for me. In any case load mcp_can and due_can libraries from my GitHub repository, since e.g. newest due_can on Collin repository does not work with NMEA 2000.

So in principle all your data "engine coolant temp, rpm, oil pressure, battery voltage/charge, gasoline/hr, tank level, rudder position and air temp in the engine room" can be collected with one board and send to bus. Practically this is not the point of NMEA 2000 bus. Instead you should have board there, where is you information to simplify cabling. So e.g. "engine coolant temp, rpm, oil pressure, air temp in the engine room" to one board near engine. Others could be on other board or what would be easiest if you think it on cabling view. E.g. I have NMEA 2000 cable going through the whole boat and in front I have depth/log device and on the other end there is autopilot. Other devices are between those. This is the idea of single bus system.

So you do not need to put 2560 behind DUE. Just simply read e.g. coolant temp on 2560 and send it to bus, if you have CAN  BUS shield for 2560.

Anyway start with TemperatureMonitor and when you have that visible on MFD, continue developing. You can then find examples of other messages on example MessageSender.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Dec 26, 2017, 01:17 pm
Hey Timo,

thanks for your answer!

So since I would like to have an all in one solution later I think I start with the Due. For that I have build the "shield"m with the MCP2562 based on the pdf from the nmea library for the due.

When I try to compile the watertemp example with added nmea2000_due.h I get the error to use the mcp_can from collin. If I understood it right, I now edited the NMEA200_due.cpp and changed out the mcp_can from collin to the one from from your repository right (NMEA2000_mcp)?

If I do so I get a couple of error message reffering to the nmea2000_due complaining about can0 is not declared and so on. Aren' t all those part of the due_can library from collin? He is also writing the can_common is neccessary to use that library.

I tried at last now to load this libraries with the tempmonitor:

Code: [Select]

#include <Arduino.h>
#include <NMEA2000_CAN.h>
#include <N2kMessages.h>
#include <NMEA2000_due.h>
#include <NMEA2000_mcp.h>



Regards..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 26, 2017, 02:15 pm
You do not need to touch any file under NMEA 2000 library. Either you do not need to edit TemperatureMonitor to get it running. It compiles and works as untouched for Due, Mega and Teensy 3.2-3.5.

- Remember to load due_can from my github repository. Do not load anything from collin!
- Remember to set right board. People often set "Arduino Duemilanove or Diecimila" for Due! It must be "Arduino Due (Programming port)"
- Delete all duplicate libraries from your Arduino\Libraries path. So you can not have due_can-master and e.g. due_can-test paths there.

In you sample you have included both Mega and Due object for your code. #include <NMEA2000_CAN.h>  does that automatically for you. So please do not touch code, before you know what you are doing.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Dec 26, 2017, 02:50 pm
Hey..

got it. It compiled well. Thx!

Next step than to get it shown on the MFD!

You wrote you have an autopilot installed? Is this a diy design? I am currently building as well an autopilot based on Jack E. design which is nice one with enhanced features also using nmea2k to get the course from gps/mfd.

If yours is diy. How did you solved the problem when the boat is comming into a dangerous situation where you have to react immidiate and take over to manual steering? I have a hydraulic steering today (26 foot cabincruiser).

Br..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 26, 2017, 03:06 pm
No, I have Raymarine pilot. It has simple Standby button to release clutch. Also works with hydraulic systems.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Dec 28, 2017, 05:01 pm
Hello Tino,

I found OpenSkipper, which you also are the author for (nice thx!), and want to use it to simulate my MFD to avoid to take out all the cabling from the boat.

I have usb to ttl cable (ftdi ttl232r 3v3) or usb to RS232 cable. Now I thought to use this with the MCP2515 CAn shield (see picture) to get the data shown with OpenSkipper.

Do I have to use some kind of Arduino inbetween or can I "just" hook this up and I have the NMEA2000 bus on the PC?

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 28, 2017, 05:23 pm
It's Timo ;)

Your MCP2515_can board uses SPI for communication and PC does not have any SPI board. Either you USB-TTL cable does not help, since there is no sw handling that communication from PC. There are some options.

1. Buy Actisense NGT-1 USB. This is the easiest, but expensive (180 € ?)

2. Buy Arduino Mega board and wire your MCP2515_can board to that. Then use ActisenseListener example under my NMEA2000 library examples. Note that your board is made by Niren and it has 8 Mhz clock instead of default 16 MHz, so you have to set that for example.

3. I prefer to by Teensy 3.2 and MCP2562 chip or "Teensy CAN-Bus Breakout Board Include Teensy 3.2". It is much more powerfull than Mega and so more usefull, if you decide to make some own devices to bus. With Teensy you also use ActisenseListener example.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Dec 28, 2017, 06:11 pm
Sorry for the "n"..

damn, I have seen the oscilator right after I posted the picture. I am not sure if I just can change that one out to 16mhz ( I have 8 peaces of this shield). The chip which should be the mcp2551 is on that board a (t)ja1050. Not  sure if that can handle the bandwith. It`s written up to 1mbit. How ever, may I change both the oscilator and the tja1050 to mcp2551. I looked at the chinese to find the one with 16mhz. Looks like they just produce the once with 8 mhz and the 1050 to save money.

Which teensy are we talking about? I found several versions with different proc at mouser.

Is the Due still slower performing than the teensy once?

I made one for the due with mcp2562. Picture attached.

Title: Re: NMEA 2000 Shield
Post by: Libera-8 on Dec 28, 2017, 07:53 pm
Who can help me?
I am trying tu use the NMEA2000 lib, with arduino due, MCP2562 and a Lowrance HDS9 MFD.
Example sketch ActisenseListener is working, I see all Messages from the MFD.
Temperature Monitor is also working via USB and Actisense NMEA reader, but does not send data via can.


Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 28, 2017, 09:16 pm
It should be OK to run mcp with 8 MHz clock. You just need to use
#define USE_MCP_CAN_CLOCK_SET 8
before including NMEA2000_CAN.h

Due used more power and is much bigger board than Teensy. Teensy 3.2 can do a lot. Teensy 3.5 has SD card, if you need it.

If you have due, then try it with it. Now there are three cases with problems on sending data to bus from due. So I am not sure can there be something with newer Dues, since my old from 2 years back has no problem. Or is there some mix with libraries.

Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Dec 29, 2017, 10:29 am
Good morning,

I have build up 2 mega's with the existing mcp2515 shields I have. Made the changes regarding the clock frequenz.
The first one got the ActisenseListener flashed and on the other I tried several different like windsensor or temp sensor.

OpenSkipper is always finding the one with the sensor flashed on but I guess just through the com port. I get shown wind speed and angle in OS but it looks like there is nothing recived through the bus. Both H & L are connected through a short kabel (5 cm).
I didn't used yet any termination resistor, can that be the reason?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 29, 2017, 10:34 am
You need to allways use terminating resistors!
Title: Re: NMEA 2000 Shield
Post by: Libera-8 on Dec 29, 2017, 10:56 am
Hello Timo,
First I thank you verry much for your work on NMEA2000.
Yes, teensy looks very good, I would rather take teensy today.
But I use with the DUE the quadinput for an incremental poti, one of the two analog outputs and the Yun-Shield to transfer programs wireless.
I tested with two DUE, both have the same problem.
- First I had the fatal error: can_common.h: No such file or directory
- Then test with clean environment, all libraries deleted,
only due_can-master, NMEA2000_due-master, NMEA2000-master;
fatal error was gone even though the libraries were the same.
But can does not send.

Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Dec 29, 2017, 12:26 pm
Hey Libera-8,

same isseu here with two mega. Did you used termination resistors? I didn't used it so I will try now with termination resistor on both ends. have to be between 100-120 Ohm like I know on each end between H&L.

Had also the same problems with compiling errors. If you completly clean out all libraries and just install the once needed it is working just fine.

I will report soon if this was the problem, resistor..
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Dec 29, 2017, 12:45 pm
Hei,

looks like it is working. NICE!

So no Resistors on the ends, no signal. And yes I should know that of course..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 29, 2017, 01:26 pm
Libera-8,

Did you load due_can library from my repository? I have not yet checked changes, what collin80 had made, so I can not say does that work even you would load all missing libraries.
Title: Re: NMEA 2000 Shield
Post by: Libera-8 on Dec 29, 2017, 03:30 pm
Timo,
I am not sure.
I tested again now several times and with two different systems.
Your due_can lib is working without compiling error, but can does not send.

due_can 2.0.1 from Collin brings compiling error with due, can_common.h: No such file or directory

due_can 2.0.0 from Collin is working completely.

Would you tell Collin?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 29, 2017, 03:34 pm
I have to make comparison to see changes and ensure I have run tests with same version as on my repository.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Dec 29, 2017, 07:15 pm
Hallo Timo,

sorry flooding the topic may with stupid questions...

I got delivered the rudder position sensor. It is a Hall Effect Sensor, Position, 90°, 4.5 V to 5.5 V, Pin, Cylinder Rotatable, 200 mV.

A view pages earlier I have read that you added rudder position to the library. I could not find something in the reference about it.

Do you have an example how to integrate it?

Thank you!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 29, 2017, 09:03 pm
Look at the MessageSender example on line 123  SetN2kRudder(N2kMsg,DegToRad(5),1,N2kRDO_MoveToStarboard,DegToRad(-5));
For the unnecessary vales use defined NA value.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 31, 2017, 04:38 am
Hi all Due users,

I am extremely sorry about problems with Arduino Due board. I tested own board only by loading due_can from my repository, but did never checked NMEA2000_due library. For some mistake it was not updated to final repository. That was the reason, why it did not send anything to the bus with due_can lbrary under my repo.

Now they are up to date and all should work (as they should have). Under my library posts I read that alo collin80 due_can version works, but for the latest version you have to download also can_common library.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Dec 31, 2017, 02:26 pm
Hei Timo,

I am 100% sure there is no reason at all to apologize.. :-)

A question:

    SetN2kRudder(N2kMsg,DegToRad(5),1,N2kRDO_MoveToStarboard,DegToRad(-5));

How do I integrate this reading from the hall sensor into this sentence?

 rudderValue = map(rudderSens, 40, 980, -5,5);

I don´t get the SetN2kRudder splittet up so I understand what is happening here.

Thank you..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Dec 31, 2017, 03:27 pm
You can read parameter descriptions on N2kMessages.h.
If you get rudder angle in radians:

Code: [Select]
rudderValue = map(rudderSens, 40, 980, -5,5);

then just call

Code: [Select]
SetN2kRudder(N2kMsg,rudderValue);
NMEA2000.SendMsg(N2kMsg);


Note that you can let function to use default values for rest of the parameters.

Note that when you need to do that periodically, you have to do like in TemperatureMonitor example:
Code: [Select]

#define RudderSendPeriod 100 // ms
void SendRudder() {
  static unsigned long RudderSendTime=millis()+RudderSendPeriod;
  if ( RudderSendTime<millis() ) {
    RudderSendTime+=RudderSendPeriod;
    double rudderValue = map(rudderSens, 40, 980, -5,5);
    SetN2kRudder(N2kMsg,rudderValue);
    NMEA2000.SendMsg(N2kMsg);
  }
}

void loop() {
  NMEA2000.ParseMessages();
  SendRudder();
  // ...
}


Never use delay() command in your code!
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Dec 31, 2017, 05:34 pm
Sorry Timo,

I don´t get it.. What is ment here?

Code: [Select]
MessageSender:42: error: expected unqualified-id before ')' token

 void SendRudder() {

                 ^

exit status 1
expected unqualified-id before ')' token
Title: Re: NMEA 2000 Shield
Post by: seamaster on Dec 31, 2017, 10:05 pm
Than means you missed some coma or semi column or some other syntax in your code. Post your code or check what you missed in your last edit before it strted failing to compile.
Happy new year!
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 01, 2018, 01:29 pm
MODIFIED:

I got the code corrected so it don´t drop any error regarding "(){}" or whatever anymore. But still the problem that that value is not calculated and or mapped from the function...

Hey,

Happy new year 2018 to all of you!

I don´t get any further. Compltly stock.  :smiley-confuse:

What is wrong here? It is on an Arduino Mega. A0 is the hall effect sensor with 90 degrees giving values from 40 to 980. The sensor is ok but I can just read a value with serial print (rudderSens) of 54.

Here is the code:

Code: [Select]
// Demo: NMEA2000 library. Send main wind data to the bus.

#include <Arduino.h>
#include <NMEA2000_CAN.h>  // This will automatically choose right CAN library and create suitable NMEA2000 object
#include <N2kMessages.h>
#define N2k_CAN_INT_PIN 21 // Use interrupt  and it is connected to pin 21
#define USE_MCP_CAN_CLOCK_SET 8
int rudderSens = A12;   // Input from the rudder position hall sensor 90 degrees
float rudderValue;


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

void setup() {
  // Set Product information
  NMEA2000.SetProductInformation("00000002", // Manufacturer's Model serial code
                                 100, // Manufacturer's product code
                                 "Simple wind monitor",  // Manufacturer's Model ID
                                 "1.1.0.22 (2016-12-31)",  // Manufacturer's Software version code
                                 "1.1.0.0 (2016-12-31)" // Manufacturer's Model version
                                );
  // Set device information
  NMEA2000.SetDeviceInformation(1, // Unique number. Use e.g. Serial number.
                                130, // Device function=Atmospheric. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                85, // Device class=External Environment. See codes on  http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                2046 // 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, 23);
  // NMEA2000.SetDebugMode(tNMEA2000::dm_Actisense); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega
  NMEA2000.EnableForward(false);
  NMEA2000.ExtendTransmitMessages(TransmitMessages);
  NMEA2000.Open();
}


void loop() {

  NMEA2000.ParseMessages();
  SendRudder();
  Serial.println(rudderSens);
  Serial.println(rudderValue);
}

double ReadRudderPosition() {
  rudderValue = map(rudderSens, 40, 980, -5, 5);
  return rudderValue; // Read here the true temperature e.g. from analog input
}

#define RudderSendPeriod 100

void SendRudder() {
  static unsigned long RudderSendTime = millis() + RudderSendPeriod;
 tN2kMsg N2kMsg;
  if ( RudderSendTime < millis() ) {
    RudderSendTime += RudderSendPeriod;
    double rudderValue = map(rudderSens, 40, 980, -5, 5);
    SetN2kRudder(N2kMsg, rudderValue);
    NMEA2000.SendMsg(N2kMsg);

  }
}





With ActisensListener on the first board and the windmonitor example I get all showing up on the NMEAReader and OpenSkipper. As soon as I flash the rudder nothing is showing up or I just get 66 as value.

I must say that it is a bit hard to understad for me the NMEA2K libray. I just work with arduino now about a month and my programming skills are more in the direction of PLC programming.

Thank you all for the help!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 01, 2018, 09:27 pm
If you have 8 Mhz clock you have to have definition before #include <NMEA2000_CAN.h>. That is shown on examples. So write:
Code: [Select]

#define N2k_CAN_INT_PIN 21 // Use interrupt  and it is connected to pin 21
#define USE_MCP_CAN_CLOCK_SET 8
#include <NMEA2000_CAN.h>


Note that you have also defined above the interrupt pin to be 21. If interrupt pin is not connected from your board to pin 21, you have to define right pin. If you do not know the right pin, leave it undefined, so library runs without interrupt. With wrong pin definition library won't work at all. It is  the same with wrong clock set definition.

Then note that Arduino map uses integer calculations. So define your own:
Code: [Select]

double dMap(double x, double in_min, double in_max, double out_min, double out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}



Also remember to use 0x for hex values. So write:
int rudderSens = 0xA0;


 Then you should get for your rudderSens=0xA0=160
(160-40)*(5 - -5)/(980-40) + -5 = -3.72

But actually I do not understand your scaling. Why you are scaling to -5 <-> 5 radians?
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 02, 2018, 10:55 am
Hey Timo,

Thank's for the detailed answer.

I skale from -5 to due to the example I saw. Thats all.

If I connect the hall sensor to analog and judt do the 5/1023 I get the value 40 to 980. The sensor is giving 0.5 to 4.5 v  by 90 degree rotation.

Of course it would be better to have a higner resulution as I need this value as well for the autopilot later on.

Regards..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 02, 2018, 11:42 am
But if your sensor is giving values 40..980 on 90 deg rotation, it means it turns from -45° .. 45°. Then you should have do scaling:
double rudderValue = map(rudderSens, 40, 980, -pi/4, pi/4);
or
double rudderValue = DegToRad(map(rudderSens, 40, 980, -45, 45));
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 02, 2018, 12:42 pm
I am still learning a lot..

yes, would make of course sens to do so.

Resulution is at the 90 degree version 0.022. Which is 2045 per 45 degrees of turn if I got that right. But this is o much as the resolution is 10 bit (1024 steps at 5v) on the analog input right?

Details from the sensor:

BI TECHNOLOGIES / TT ELECTRONICS
6127V1A90L.5 -  Hall Effect Sensor, Position, 90°

Output Voltage 0.2 Vdc (4%) to 4.8 Vdc (96%) Typical (see Feature Codes table)
Output Overvoltage Limits 10 Vdc to -0.3 Vdc; output may be shorted to ground or supply without damage
Output Current ±8 mA Max.
Output Load 1 kΩ Min., 10 kΩ Typical
Input Voltage 4.5 to 5.5 Vdc
Supply Voltage Absolute Limits 20 Vdc Max., -10 Vdc Min.
Independent Linearity1 ±0.5% (0.25% Available)
Hysteresis 0.2% Max.
Resolution 0.088° for 360° travel, 0.011° for 45° travel
Supply Current 8.5 mA Typical, 12 mA Max.
Dielectric Strength 750 V rms
Insulation Resistance 1,000 MegΩ Min.
Electrostatic Discharge (ESD) Passes 2 kV human body model and 15 kV air discharge
Bulk Current Injection (BCI) Passes 2-500 MHz at 200 mA
Actual Electrical Travel 360° Typical (see Ordering Information)
Title: Re: NMEA 2000 Shield
Post by: Libera-8 on Jan 04, 2018, 10:12 am
Is there someone who has examined the can bus in volvo penta engines?
 
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 04, 2018, 05:47 pm
Hello Timo,

I am really sorry to bother you with the rudder position thing.. I do try it now for the last 6 days and get stuck every time with something else.

That is killing me soon... Back to analog instruments!  :smiley-grin:

This code:

Code: [Select]
void RudderPostion() {
  double dMap(double x, double in_min = 40, double in_max = 1023, double out_min = -45, double out_max = 45){
    return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
  }
}


is producing this error:

Code: [Select]
RudderPosition_NMEA2K_v2:42: error: a function-definition is not allowed here before '{' token

exit status 1
a function-definition is not allowed here before '{' token


This is the hole sketch I thought to use:

Code: [Select]
// Demo: NMEA2000 library. Send main wind data to the bus.

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

int rudderSens = 0xA0;        // value read from the pot
double rudderValue = 0;
const unsigned long TransmitMessages[] PROGMEM = {127245L, 0};

void setup() {
  // Set Product information
  NMEA2000.SetProductInformation("00000002", // Manufacturer's Model serial code
                                 100, // Manufacturer's product code
                                 "Rudder Position monitor",  // Manufacturer's Model ID
                                 "1.1.0.22 (2016-12-31)",  // Manufacturer's Software version code
                                 "1.1.0.0 (2016-12-31)" // Manufacturer's Model version
                                );
  // Set device information
  NMEA2000.SetDeviceInformation(1, // Unique number. Use e.g. Serial number.
                                155, // Device function=Atmospheric. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                40, // Device class=External Environment. See codes on  http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                1851 // 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, 23);

  // NMEA2000.SetDebugMode(tNMEA2000::dm_Actisense); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega

  NMEA2000.EnableForward(false);
  NMEA2000.ExtendTransmitMessages(TransmitMessages);
  NMEA2000.Open();
}

#define RudderSendPeriod 100 // ms
void SendRudder() {
  static unsigned long RudderSendTime = millis() + RudderSendPeriod;
  tN2kMsg N2kMsg;
  if ( RudderSendTime < millis() ) {
    RudderSendTime += RudderSendPeriod;
    double dMap(double x, double in_min = 40, double in_max = 1023, double out_min = -45, double out_max = 45) {
      return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
    }
    SetN2kRudder(N2kMsg, rudderValue);
    NMEA2000.SendMsg(N2kMsg);
  }
}

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



It took also some time until I have recognized that the usual map function will not work here. I thought your post which showed the userdefiend map function is not mandetorry for this case and I got always wrong values. The strange thing is that I used the standart map function to test the sensor in a simple sketch and it was working just fine like this one:

Code: [Select]

int rudderSens= A0;  // Analog input pin that the potentiometer is attached to
int sensorValue = 0;        // value read from the pot
int RudderPosition;

void setup() {
   Serial.begin(115200);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(rudderSens);           
  // map it to the range of the analog out:
  RudderPosition= map(sensorValue, 54, 1023, -45,45); 
     

  // print the results to the serial monitor:
     
 
  Serial.println(sensorValue); 
}


In case I got the sketch running than I always got a constant rudderposition send which had nothing to do with the sensor value.

If I get this one working fine than I think I get almost every other I thought to implement also working.

Would be gorgeous to get this running with the help of you, without I think I have to buy the commercial version of this sensor for rudder position.

Thousends of thanks in advance!

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 04, 2018, 08:29 pm
Your questions actually belongs to some basic c/c++ syntax forum. That you should study first.

One problem is that you just copied my code sample inside on other function. The new function dMap should be defined alone as own function:
..
double dMap(...) {
...
}
...
void SendRudder() {
...
}
...

That is basic syntax.

Then you have set default values for dMap function parameters:
...
double dMap(double x, double in_min = 40...)
...
Do not use default values, before you understand the meaning of them. You should then call dMap inside your code:
...
void SendRudder() {
...
  double rudderValue=dMap(sensorValue, 54, 1023, -45,45);
...
}

Like you do with map, which is just function as dMap, but defined in some Arduino standard library.

Then note that in your code you defined int RudderPosition. This means that you can have 90 difference values between -45 45. If1 degree accuracy is enough for you, that is fine and then also standard map is fine. If you like to have better accuracy, you have to use double of float.

Then you have defined analog pin as int rudderSens= A0; So on board it says A0..A15 printed, but if you read definition of analogRead:
---------------------------------------------
analogRead(pin)
Parameters

pin: the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the Mini and Nano, 0 to 15 on the Mega)
---------------------------------------------
So you should simply have: int rudderSens=0;

Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 04, 2018, 09:51 pm
Modified:

Hey Timo,

sure you are right that this is basic. The code I posted was ment that I wanted to use that one as base. Not that this was finnished. I worte a lot of versions and I didn´t wanted to post all of the garbage I produced here.


->****** History now
Would be better to have a more accurracy of the rudder angle for sure. As soon as I add dMap to a line I get that it is not declared. Do I declare it I get as double for example I get "dMap can not be used as a function. In other posts I could found exactly the same like you posted it and I compared it to many different sources.
I used the user dMap as a single function and also used double or float (void blabla... analogRead(reudderSens).. , return dmap(....) ) with descriped result. The point is the error appears also
as single function and that was than the point where I didn´t came any further.
<-****** History now

I simply forgot that I create my own map function which I have to call than later in the program. Stupid failure... Sorry


So differences between float double int and other main functions of the reference library I do know about. I saw that analogRead was missing and used it before like I got temp monitor to work like it should. I know not so much, yet. But I know about the simple basics.

I will post thoose questions next time in the forum which belong to this type of questions.

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 05, 2018, 05:28 am
Sorry my a bit rude answer. I meant that you should really study code syntax basics and do some simple trainings. Also play with code by commenting things, moving code to different location or what ever to learn what effects to where and what kind of errors you get. On code below try e.g. comment { at the end of line "double dMap(..." to see how error message leads you totally wrong. Also study to read error messages - it is not sometimes easy with c++.

Below is ready code for rudder, which I may add as example some day. Study it and try to learn.
Code: [Select]

// Demo: NMEA2000 library. Read rudder angle from the Analog sensor

#include <Arduino.h>
//#define N2k_CAN_INT_PIN 21 // Use interrupt  and it is connected to pin 21. Use this with with e.g. Mega board. Check where your interrupt has been connected.
//#define USE_MCP_CAN_CLOCK_SET 8 // Uncomment this, if your CAN shield uses 8 MHz clock instead of 16 Mhz like e.g. on seeedstudio can bus shield
#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 = {130306L, 0};

// *****************************************************************************
void setup() {
  // Set Product information
  NMEA2000.SetProductInformation("00000002", // Manufacturer's Model serial code
                                 100, // Manufacturer's product code
                                 "Rudder Position",  // Manufacturer's Model ID
                                 "1.1.0.22 (2018-01-05)",  // Manufacturer's Software version code
                                 "1.1.0.0 (2018-01-05)" // Manufacturer's Model version
                                 );
  // Set device information
  NMEA2000.SetDeviceInformation(1, // Unique number. Use e.g. Serial number.
                                155, // Device function=Rudder. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                40, // Device class=Steering and Control Surfaces. See codes on  http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                2046 // 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. Comment 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,23);
  // NMEA2000.SetDebugMode(tNMEA2000::dm_Actisense); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega
  NMEA2000.EnableForward(false); // Comment this, if you want to see bus traffic on your serial.
  NMEA2000.ExtendTransmitMessages(TransmitMessages);
  NMEA2000.Open();
}

// *****************************************************************************
void loop() {
  NMEA2000.ParseMessages();
  SendRudder();
}

// *****************************************************************************
// Double replacement for standard map function
double dMap(double x, double in_min, double in_max, double out_min, double out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

// *****************************************************************************
// Function reads rudder postion from A0 input and scales it to angle in degrees
double ReadRudderPosition() {
  double rudderValue = dMap(analogRead(A0), 40, 980, -45, 45);
  // We actually would need here some filter function to prevent noise on analog.
  return rudderValue;
}

#define RudderSendPeriod 100

// *****************************************************************************
void SendRudder() {
  static unsigned long RudderSendTime = millis() + RudderSendPeriod;
  tN2kMsg N2kMsg;
  if ( RudderSendTime < millis() ) {
    RudderSendTime += RudderSendPeriod;
    double rudderValue=ReadRudderPosition();
    Serial.print("Rudder value: "); Serial.println(rudderValue);
    SetN2kRudder(N2kMsg, DegToRad(rudderValue));
    NMEA2000.SendMsg(N2kMsg);
   }
}
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 05, 2018, 11:35 am
Hey Timo,

nothing to appologize for. I expacted almost a little harder answer already as I posted a lot of times about it and got afraid. That´s why I appologized always already in the question for that post.  ;)  Stupid questions, special if they appear so often, deserve sometimes harder answer to reset the brain. And it worked also yesturday evening as I wrote almost the same like you posted now:

Code: [Select]

double dMap(double val, double in_min, double in_max, double out_min, double out_max) {
    return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

int RudderRead() {
analogRead(rudderSens);
int rudderValue = dMap(rudderSens, 40, 980, -45, 45);
  return rudderValue; // Read here the true temperature e.g. from analog input
Serial.println(rudderValue);
}


#define RudderSendPeriod 100

void SendRudder() {
  static unsigned long RudderSendTime = millis() + RudderSendPeriod;
  tN2kMsg N2kMsg;
  if ( RudderSendTime < millis() ) {
    RudderSendTime += RudderSendPeriod;
    SetN2kRudder(N2kMsg, rudderValue);
    NMEA2000.SendMsg(N2kMsg);
   }
}

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


I will compare it carefully to learn the things I do wrong and not just use it as template, promissed!

The debug console from OpenSkipper showed up that it was expacting 6 bit and recieved 8 bit. Not sure if that have something todo with my problem. So I still have 0 as value for the angle. (used my version, not the one you posted now).

I don´t give up so fast. It is now "just" 7-8 days for the rudderfunction I spent. :-)

What is responsible for the 8 bit or 6 bit in the message?

A nother thing I couldn´t figure out the meaning of it is this one:

Code: [Select]
tN2kMsg N2kMsg;


First time I got hit because I tried the rudder and got that tN2kMsg was not defiend in this scope. So I just copied this from other examples from you without knowing what it is. ok so far i know it says that tN2kMsg is the same like N2kMsg. I couldn´t exactly find the point in the library files where this is defiend to figure out what this is. I think at least it is the definition of the message to be sent due to "NMEA2000.SendMsg(N2kMsg);.

Could you may reffer to a point in the library files where I can take a look to get more known with the messages which are sent?

Thanks a lot!

PS:

The Teensy´s arrived today. I ordered 3.2´s and one 3.5. The 3.5 is also 5 volt compatible and have the sd card slot onboard. Thought cool to use for the planned GPS tracker I lke to build in the future.
One difference to arduino´s is that I have to use the FlexCAN library, something else I have to be carefull with? They are not so cheap as Arduino and I don´t want to burn any. I also got the Linx RXM-GNSS-GM delivered. High performance/ precision GPS (and all other sattelites). Looking forward t see the differences comparing to the "cheaper" once.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 05, 2018, 12:43 pm
I noticed that you have to change on the beginning of my example:
Code: [Select]
const unsigned long TransmitMessages[] PROGMEM = {127245L, 0};
This gives right information to other devices on the bus.

In your code int ReadRudder you have to defined it to return integer value. Remember that then compiler will do automatic typecasting from double to int. And there is no warning about that, since Arduino IDE does not have good option to turn all warnings as error. So define double ReadRudder(...) Also inside function define double rudderValue=dMap(...)

Have you checked that you have latest 1.6B version of OpenSkipper? And I think you mean 6 bytes.

tN2kMsg N2kMsg; does say that tN2kMsg  is N2kMsg. It says that you define variable N2kMsg, which is type of tN2kMsg. It is as you write double val; you define variable val, which is type of double.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 05, 2018, 01:21 pm
It is OpenSkipper 1.6.2016.1217.

I ment 6 vytes not bit yes.

During the test I used allover double, also inside the RudderRead function. The "int rudderValue = dMap(rudderSens, 40, 980, -45, 45);" was just a test.

I did changed the PROGMEM number to 127245L. I found this number from the N2KMessage.h after I compared the number from the Windmonitor with N2KMessages.h. So I use this now all the time. 127245 is the number in the first row of rudder "void SetN2kPGN127245". The "L" behind I just left there, couldn´t find out if that is right there or not.
So in your last posted version of the rudder sketch is still the number used from the windmonitor if I understand this correct.

Later I start all over again to be 100% sure.
Title: Re: NMEA 2000 Shield
Post by: mairas on Jan 07, 2018, 09:11 pm
Hi,

I am trying to hack together some new electronics capabilities for my sailboat. I currently have a basic NMEA 2000 bus on the boat. I'd like to add low-cost custom sensors and logging capability to the system. My current idea is to install Signal K on a Raspberry Pi Zero W, and cobble the NMEA 2000 bus to the RasPi with an Arduino. Then it would be relatively simple to create "micro-sensors" with an ESP8266 or such. My ideas for sensors would include temperature/humidity/barometer in different locations, engine tachometer (from the RPM gauge signal), electronic compass, gyrometer etc, and so on. Having all those directly on NMEA 2000 would increase the bus complexity and cost quite a bit, hence the wish for simple wireless devices.

I've successfully built the connecting hardware with an Arduino Due and MCP2562 with Timo Lappalainen's excellent instructions. I'm able to eavesdrop to N2k data with ActisenseListener. Similarly, my B&G Vulcan 7 MFD can see the device and receive data when I load MessageSender.ino to the Arduino. Hence, I believe the hardware connectivity is working.

What I don't get is how to use the Arduino as a simple gateway. Did I understand correctly that  ActisenseListenerSender should basically act as an Actisense NGT-1 replacement? The code doesn't set any N2k product information, and at least the B&G plotter doesn't see any transmitted data. Should I add the product information data myself? What else might I be missing from a functional gateway?

Of course, I'm not above opening my wallet and simply buying an Actisense NGW-1 or similar, but I quite like the DIY aspect and the challenge of not just throwing some off-the-shelf hardware on the problem. :-)

Cheers,

Matti
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 08, 2018, 06:16 am
You do not need NGT-1, exept if you would like to have nice box. With same money you can buy several Teensys. My library does all, what you need.

Also I would not think having devices directly on N2k bus increases costs. You do not need to use expencive N2k connectors. You can simply make your own hub box by using cheap connectors used on DeviceNet (see. e.g. Farnell codes 1717025 and 1717013). Pin order is on Teensy_Actisense_listener_sender_schematics.pdf. With 20 € you can make 5 pos hub with all connectors. I currently have 4 hubs on by boat. The complexity will increase a bit, but then your devices can get power from bus.

ActisenseListenerSender has been designed mostly for testing and logging purposes. It passes messages sent as they are e.g. from my NMEA Simulator (see. kave.fi/Apps). There you can select to send or not the device information. NGT-1 works a bit different way, since it allways shows messages sent from NGT-1, not from Simulator. I can add Gateway example, or you can make it by yourself by combining TemperaturMonitor and ActisenseReader used on ActisenseListenerSender. The other thing I wonder that how did you test that ActisenseListenerSender does not send anything? How did you transmitted data?

Then if you are going to use RPi, it should be possible to integrate library with it by using PiCan2. I have been thinking that, but had no time. Library should compile on Pi and there is NMEA2000_socketCAN for that. As far as I know, SignalK are listen only, so you need anyway code to generate messages. Library has most common message generators on N2kMessages.
Title: Re: NMEA 2000 Shield
Post by: frederikkoopman on Jan 08, 2018, 12:07 pm
Hi all,

Love the work you are doing. I was wondering if the PGN for MOB (I think it is PGN 127233) can be included the library since I want to make a MOB node.

Also i made a PCB design for an atmega 328 (the chip on an Arduino uno) to work with a standard MCP2515 CAN Bus Module. This PCB has I2C or 2 analog connections and a digital connection.

I have used this PCB in 3 applications (a wind monitor, a digital compass and a barometer).

Frederik
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 08, 2018, 12:20 pm
I have warned that library does not fit well to Arduino Uno . You have use defines to disable all rarely used features and set buffers to minimum. I prefer  at minimum Teensy 3.2

Unfortunately I have not found description for PGN 127233. The list of fields does not tell enough - we need bit by bit desrciption. I would use that too. On the other hand, have you checked that some device would listen that message? Older MFD versions does not listen it, so e.g. there is no help for my Garmin GMI 20.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 08, 2018, 05:13 pm
Hey,

which CAN IC is generally best to use with the Teensy 3.2 one?

I have currently MCP2551, MCP2562, MCP25515 and the SN65HVD234.

I try with the MCP2551 at VUSB or 3.3V but I don´t get any luck. I have set the bandwidth first to default 125K and than I tried 500K but got no traffic.

Is there any "finished" can shield wich works fine with the teensy´s?

Regards..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 08, 2018, 06:06 pm
I prefer MCP2562. It uses 5V power, but has pin 5 for defining IO-level. Check my example schematics https://github.com/ttlappalainen/NMEA2000/blob/master/Examples/TeensyActisenseListenerSender/Documents/Teensy_Actisense_listener_sender_schematics.pdf

Which badwidth you mean? NMEA2000 library has fixed bandwidth to NMEA 2000 bus speed 250kps.

Check this one: http://skpang.co.uk/catalog/teensy-canbus-breakout-board-include-teensy-32-p-1507.html
Title: Re: NMEA 2000 Shield
Post by: mairas on Jan 08, 2018, 07:42 pm
Hi,

I think I was being hasty. I dragged out an old Windows laptop and tried your NMEA-Simulator and was able to get values to the MFD just fine. For a while - after some 15-20 seconds (guesstimate) traffic stops and the devices disappear. I wonder is that a feature or an issue in my hardware? I saw a mention that some Dues have problems sending data. Might that be related? If so, I also have an idle Teensy that I can repurpose for this project.

Now that I understand how the ActisenseListenerSender differs from the actual Actisense hardware, it's fine. I might still do the gateway change because I believe the Signal K plugin and canboat expect actual Actisense style operation. I'll be happy to make a PR for that.

There's now a rudimentary signalk-to-nmea2000 plugin available. Only very few PGNs are supported at the moment, but it doesn't seem to complicated to add any I might need. And I still believe I could get a simpler end result that way. I should get by with a simple ESP8266, a cheapo buck converter, a fuse holder and a piece of perf board as well as any sensor device I might be using. If I went to native N2k, I'd need at least a Teensy+tranceiver for each sensor (or sensor group), right?

Thanks for the quick response!

Cheers,

Matti


Using RPi directly would be tempting, but I'm also perfectly happy if I can get the Arduino working. :-D
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 08, 2018, 07:43 pm
I got now the MCP2551 working. I don´t know if this have a reason or if this is neccessary, but it didn´t worked until I added the CS pin to the configuration with
Code: [Select]
#define N2k_SPI_CS_PIN 53  // Pin for SPI Can Select. As soon this was part of the config beside the Integer pin 21 and the clock set to 8 mhz it looked like everything is just fine.

By bandwith i ment the setting from the FlexCAN.h
Code: [Select]
FlexCAN(uint32_t baud = 1000000, .... in the public part of the file. If this have no meaning than I guess it is like you said 250K. By default the setting from the flexcan is set to 500K. I just tested a bit with that number since I didn´t got any communication.

Finnally I am now at that point where I can say that I get a bit more familiar to the coding here. That was a long and also expensive journey:

DON´T RUN 12 V ON THE BUS!

I was so unlucky that I plugged the 12 V into the CAN bus connection so 1 SN65HVD234, 3 MCP2515 shields, 1 MCP2562 and finally one Geniu DUE went to sleep for ever. Was a nice firework.  ;D


Another thing:

TrimTabs

There exists an automatic steering for the TrimTabs from Bennett and another which also is NMEA2K comapatible to show the position of the tabs.
I am very interessted to build something like this as well as this part was very expensive even without NMEA2k and I have no idicator at all on my hydraulic tab at all.

I thought a bit about it, to indicate the position is no big deel and the orgin sensors are not so expensive as well. But the automasation will be a bit harder I guess. A lot of filtering due to waves and motions on the water which shuld not affect the position like making a turn for example.

Did anybody had something like this in mind also?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 08, 2018, 09:45 pm
#define N2k_SPI_CS_PIN 53 is the default setting even you do not use it.

DON´T RUN 12 V ON THE BUS!  This is wrong. You can run 12 V. If you look my schema https://github.com/ttlappalainen/NMEA2000/blob/master/Documents/ArduinoDUE_CAN_with_MCP2562.pdf you will see there must be diode from 12 V.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 09, 2018, 08:49 am
yes I know you can run even more with some IC´s but not how I had it. There was some wrong connections otherwise it haven´t burned all. That was not ment really seriously.
I guess it was a shortage of full current on one line of the bus to somewhere so it glowed away.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 09, 2018, 03:15 pm
Hi Matti,

I passed you post yesterday.

Due problems were my fault - for some reason update for NMEA2000_due was not on public GitHub even it showed on my GUI that it has been sended. I have due and it has been working right. I can try to confirm it again with simulator in evening.

Difference between ActisenseListenerSender  and original Actisense hw is on configurability. My code just forwards N2k messages to USB in Actisense format and opposite. On Actisense hw you can also send commands to enable specifig PGNs for both directions. These so called BEM messages uses same basic format and my code just skips them, since they have wrong "command" code. So in principle ActisenseListenerSender should work in both directions with any sw, which sends or reads data in Actisense format. If the other program would expect some response to BEM messages and does not continue, because it does not get anything, that can block it. But even Actisense own Actisense NMEA reader works fine with ActisenseListener program.

I may also use ESP8266 for some sensors in future. But for important information like engine and main tanks, I will use wired sensors. It is easier then to turn off WiFi to save power.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 09, 2018, 03:52 pm
Hello Timo,

you ment to do add a noise filtering function to the analog input from the rudder position hall sensor.

Do you mean by that smoothing or averaging the signal?

Otherwise wouldn´t it be better to avoid noice by adding pulldown resistor and capacitor to ground?

The smallest amount of code to do an averaging is this example:


Code: [Select]
  float AverageValue = 0;
  int MeasurementsToAverage = 16;
  for(int i = 0; i < MeasurementsToAverage; ++i)
  {
    AverageValue += MeasureValue();
    delay(1);
  }
  AverageValue /= MeasurementsToAverage;

  float AverageValue = 0;
  int MeasurementsToAverage = 16;
  for(int i = 0; i < MeasurementsToAverage; ++i)
  {
    AverageValue += MeasureValue();
    delay(1);
  }
  AverageValue /= MeasurementsToAverage;


I know there are deays part of the code which have to eleminated.

What exactly do you mean by that?

Regards..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 09, 2018, 05:39 pm
That is not good way to average, since you should allways do something. You should never use delay() function withing loop or any function called on loop. Your example stops other processing for over 16 ms. During that time you can e.g. get 40 frames on N2k bus. It is ok, if you have at least 40 frame imput buffer. You think may that you are just sending data and not worried about incoming frames. But the way is just bad programming for this kind of systems. Situation is completely different on multitasking OS, where "delay" would mean that "I give up my task for a while" and OS takes care of running other tasks.

Also it is almost allways best do filtering with code - not to make it by hw. Hw filter is difficult to change.

The code below calculates average for rudder position without wasting any unnecessary time in averaging. So processor will run full speed all other tasks you call in loop(). Note that RudderSamplePeriod*RudderSampleCount must be < RudderSendPeriod .

Code: [Select]

#define RudderSendPeriod 100
#define RudderSamplePeriod 1
#define RudderSampleCount 40

// *****************************************************************************
void SendRudder() {
  static unsigned long RudderSendTime = millis() + RudderSendPeriod;
  static unsigned long RudderSampleTime = RudderSendTime-RudderSampleCount*RudderSamplePeriod;
  static double RudderSampleSum=0;
  static size_t RudderSamplesDone=0;
 
  tN2kMsg N2kMsg;
  if ( RudderSampleTime < millis() ) {
    RudderSampleSum += ReadRudderPosition();
    RudderSamplesDone++;
    if ( RudderSendTime < RudderSampleTime ) {
      RudderSendTime += RudderSendPeriod;
      RudderSampleTime = RudderSendTime-RudderSampleCount*RudderSamplePeriod;
      double rudderValue=RudderSampleSum/RudderSamplesDone;
      RudderSampleSum=0;
      RudderSamplesDone=0;
      Serial.print("Rudder value: "); Serial.println(rudderValue);
      SetN2kRudder(N2kMsg, DegToRad(rudderValue));
      NMEA2000.SendMsg(N2kMsg);
     } else {
       RudderSampleTime += RudderSamplePeriod;
     }
  }
}
Title: Re: NMEA 2000 Shield
Post by: mairas on Jan 09, 2018, 08:56 pm
Hi,

I indeed tested with Actisense's NMEA Reader, and it was able to receive messages properly. Lots of errors in the beginning, presumedly due to failing mode settings etc.

I made an ArduinoGateway sketch that sets the product and device information and NMEA mode properly. I can see the device on my MFD, but I'm still struggling with the data formats. Would it be possible to get a bit of raw data similar to what NMEA-Simulator sends? I'm not sure where to get valid test data to send to the device. At the moment I'm trying to use Signal K and canboat to send data to the Arduino, and I suppose something is wrong with the data format because at least the MFD doesn't show anything. The data canboat is sending is as follows:

Code: [Select]

7,129025,1,255,8,61,72,e8,23,40,37,da,0e
3,126992,1,255,8,ff,ff,84,44,70,9d,3b,2a


In all cases, the message type is 0x94. It isn't clear to me what its significance is.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 10, 2018, 06:13 am
I wonder where you did got the error messages? I have never seen any with NMEA Reader.

On your ArduinoGateway remember to use NMEA2000.SendMsg(N2kMsg); not NMEA2000.SendMsg(N2kMsg,-1); -1 Means that library uses source address set to N2kMsg instead of device address, which may vary due to address claim. If you use -1, it may be that your MFD does not like messages, which source is unknown. With Simulator it works, since it sends also device information.

I expect there is some preformatter between your string and final writing to USB. Actisense format is binary format, which starts with Escape (0x10), StartOfText (0x02) and ends to EndOfText (0x03). Data between is binary and also has to have right checksum. You can find full description of format on ActisenseReader.cpp, function GetMessageFromStream. 0x94 is Request command.

I also checked Arduino DUE and NMEA Simulator combination and it works fine. There is also some things you have to remember. If you use ActisenseListenerSender with DUE and Simulator and you do not read out  - e.g. with NMEA Reader - data sended by DUE, it gets soon stucked. So you can either disable forwarding:
Code: [Select]
NMEA2000.EnableForward(false);
or set forward port to SerialUSB by:
Code: [Select]
#define FORWARD_STREAM SerialUSB
With either of those settings I run DUE as sender and Mega as listener for over 30 min test with all data enabled on NMEA Simulator.

This is one reason I changed to Teensy, since their port does not get stuck, if it is not read out. They are also smaller and uses less power.
Title: Re: NMEA 2000 Shield
Post by: mairas on Jan 10, 2018, 07:34 pm
Hi!

Excellent! The extra -1 argument was the final culprit. Thanks a lot - I'd never have been able to figure it out myself. I made a PR for the ArduinoGateway sketch.

Like you suggested, the messages I quoted indeed weren't the ones written to the serial port. And I believe I earlier ran into issue of Due getting stuck due to unread data. Pretty weird. I think I'll scavenge the Teensy I have and repurpose that into a gateway...

I was still able to get a couple of lines of "Update operating mode" resulting in a timeout on the NMEA Reader Log tab. But the reason for that is by now pretty self-evident.

Again, thanks a lot for your help.
Title: Re: NMEA 2000 Shield
Post by: mairas on Jan 10, 2018, 07:44 pm
See for yourself: location data from B&G Vulcan 7 is being output via ArduinoGateway on an Arduino Due to Signal K node server and then back. :-) System time originates from Signal K.

(https://lh3.googleusercontent.com/xxCfd5APBM-lL7s_v0A1BfX--e7dD932dmrmAHLji_pHhf1giJ-YChdBH0KZ1g4PAs6B2Q7eawKO-zvkZa6QayEWdMT98Z5I47rfYox8GyaQnXKdsccBF-6yBnnkDNBRoF47h5yQ5Ee9cXkzqgD7Idk7Srv3yj99JReGUfqiuvUNgjdT0G3dqFo0cYp1FYr8T5MhGxrac_QxCvVOcJrhSCeogDnI6W8vbtUWdnGF8XGiVypwAKzBD8VsIuTDhC9OzTf1cltv0M4Pg0owBUIz1r0-w215oAwIi8TRxSpohki-qXBlGjYoHJUyscw_1mKmS96frxVijOWmyV1TtPfXaPa36z5jLUk8oyRFj6QOlvyaBRKwr9YyfWG47lVOdYC3tFFPiJpUnRFV42krLv2jlY8IlxSrbrAhMr9XWsl05ZFPt4E08ICOLev6wtf4u4B11A8BqwOkX3g6aaQCyZm7KCPT_FEcBjkYTtOXaonueuqWMPiwyjXzibkCpc3JZQviocXNuckzCJ45uYKqHGufOn1s7LzCRya7oby78dH4kJl7n_LTxf0fbuaQO0hrjaD8y8qw90HZYPGMQnFt3kpJ04CVV8ib3zZbJMFKncE2=w1964-h1472-no)
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 10, 2018, 08:24 pm
Well done!

The next step would be to implement library already to RPi with PiCAN2, so you could skip one extra "Arduino" - and save power for sailboaters. I just have not had time to check that. The one problem, which may appear is sending fastpacket messages. I am afraid that Socket CAN just sends frames from three mailboxes, which causes frame order to be mixed, which is not allowed with fastpackets like product information. That is why I had to improve all other can libraries mcp_can, due_can and FlexCan. On the other hand it could be possible to implement mcp_can directly for RPi instead of using Socket CAN. PiCAN2 board just has same chips MCP2515-MCP2551, so it should not be that hard.

I have forgot "Update operating mode" errros. They are simply because NMEA Reader tries to send BEM messages to define some setting to NGT-1 and since I do not response, it shows errors. Also NMEA Simulator has possiblity to enable it to send "enable all PGN output" BEM message, so that it works also with NGT-1. And actually Signal-K should do that too so that it can send data to bus.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 11, 2018, 04:14 pm
- Using FRAM to log data.

Hello,

I thought using a memory to log some NMEA data like operating hours or some gps points for example.

So I posted a question about what would be the best solution to do so.

The answer was FRAM and since I didn´t know so much about I did some research on it and it sounds like the best solution sincee it is fast, don´t need battery to hold the data and have more write cycles then most other like sd card eeprom and so on. Also what is very important is that there is no cycle / data lost due to high or very low temperatur.


The operating hours should of course also be send on the bus after they are counted and stored so the question is when is the best moment to count and save the data?
Should be an extra board or is that so litle that it doesn´t matter and could be done on the board which generates all the engine data? (I´d like to have all engine data available on the bus so I use one Teensy3.X to do that.)

Any comments and ideas?

Regards..
Title: Re: NMEA 2000 Shield
Post by: Libera-8 on Jan 12, 2018, 10:41 pm
Ho can I read PGN 126996 (Product Information) ?

Or, maybe better, how can I check, if one of two similar devices is alive on the bus?

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 13, 2018, 05:50 am
Hopefully you have enough memory on your system. tN2kDeviceList class is for that purpose and there is example DeviceAnalyzer, where that has been used. You just create object:
Code: [Select]

pN2kDeviceList = new tN2kDeviceList(&NMEA2000);

and that automatically catches new devices and device changes on the bus. In well made system you should glue your data to NMEA NAME. You can e.g. have two devices sending "PGN 127505 Fluid Level" information from different tanks. And both may have same instance values. So the only way is to separate them by source. But due to address claiming, source may change. So here you can then use
Code: [Select]
pN2kDeviceList->FindDeviceByName(name);
and you can then get tNMEA2000::tDevice, where you have all information - also source.
You have to also periodically check ReadResetIsListUpdated and if that returs true, you check your watch devices source again.

The class does not have any enumeration function, but due to structure it is as effient to to use:
Code: [Select]
for ( size_t i=0; i<=N2kMaxCanBusAddress; i++) {
  const tNMEA2000::tDevice *pDevice=pN2kDeviceList->FindDeviceBySource(i);
  if ( pDevice!=0 ) {
    // Do something
  }
}

Note that on tNMEA2000::tDevice you can also read PGN:s they transmits and all other information available from device.

I prefer to have at least Due for using tDeviceList. I have tested it on Mega, but on bigger system memory runs out. Again with Teensy 3.2 you can do a lot more.
Title: Re: NMEA 2000 Shield
Post by: Libera-8 on Jan 13, 2018, 03:59 pm
Timo, thank you for fast reply.
That is, at least at the moment, too complex for me.
I do not understand how the classes are working.
If you can recommend documents to study this stuff, that would be helpful.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 13, 2018, 06:17 pm
What document you mean? About c++ classes, NMEA2000 library or NMEA2000 protocol? For NMEA2000 library there the one inside documents, but there is not much about tDeviceList. For NMEA2000 protocol I have not found good free document. Information is around in small pieces.

But using tDeviceList is far more easier than try to do it yourself from the scratch. And about your original question "if one of two similar devices is alive on the bus", what you actually mean with that? How do you define "similar device"? Do you know their product code? Or do you know the PGN, they should send? For both questions tDeviceList is an simple solution, because it collects all device information automatically just by joining it to NMEA2000 object as I wrote earlier and as it is on DeviceAnalyzer.

I prefer you to study how to use classes. You do not need to write them, but you need to use them.
Title: Re: NMEA 2000 Shield
Post by: Libera-8 on Jan 14, 2018, 06:18 pm
Timo, my problem is my missing knowledge with c++ classes.
So, first I have to look for a c++ book and do my homework.

Maybe you can help me with the following problem:

I can read  PGN 129284 NavigationInfo with Actisense Listener, all 15 fields have the correct information.

But, with the following sketch all fields have wrong info, for instance, SID is always 255.
PGN 126992 SystemTime is working correct.

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 15, 2018, 06:25 am
There was a bug in ParseN2kPGN129284. I updated the fix to the library.
Title: Re: NMEA 2000 Shield
Post by: Libera-8 on Jan 15, 2018, 02:48 pm
Timo, thanks a lot,  it is working fine now.

I also tried PGN129285 and PGN130074 to get position of the next waypoint.
But, with this two PGN´s I got a compiling error with the line
if (ParseN2k...

As I can see in N2kMessages.H,  this data is probably stored in a database.

Do yo have an example, how to read such a database?



Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 15, 2018, 04:17 pm
Unfortunately there is no parser functions for those PGN:s written. Also noticed that I should have been more carefull on accepting merge for those messages, since the writer comments does not match to then parameter list.

There is no database on NMEA2000 protocol. Protocol is just for exchanging data between devices. So the database, all database and route ID:s are manufacturer specific.

Also both of those messages are rather complicate to handle. I do not have NMEA2000 plotter for testing waypoint data exchanging, so I am not how they do it. NMEA2000 fastpacket can carry only few waypoints. So they either send several fastpackets for single route so that you separate data by waypoint start ID. Other possiblity is to use transport protocol, which can move about 1800 bytes data. But even that gets full with long route. And on the other hand currently library does not support large transport protocol packets.

For the 130074 document says "Complex request of this PGN should return the Waypoints of a WP-List". So the devices does not send that automatically. Also other waypoint/route information will be returned with "Complex request" - and I really agree the name of request.

For 129285 document says "It can be requested or may be transmitted without a
request, typically at each Waypoint advance." So also this is rather complex and has same problems as other waypoint/route information PGNs.
Title: Re: NMEA 2000 Shield
Post by: Libera-8 on Jan 17, 2018, 12:31 pm
Timo, thank you for new information.
For me PGN 129284 is sufficient.

I have a Lowrance HDS9, and I checkt how PGN´s 129284,  129285,  130074 are working:

129284: HDS is sending this, as far as I navigate to a waypoint. A route is not necessary.

130074: is send automatically, as far as I save a new waypoint.


129285: is send automatically, as far a route is active.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 21, 2018, 08:54 pm
Hey Timo,

do you have tested the Teensy3.x together with the SN65HVD234?

I have a couple of them and since they are not that cheap and due to the readme of the FlexCAN library the SN65HVD´s seems to be a bit more stable or at least support higher bandwidth at 3.3v ( I know that the NMEA2K library just use 500K) I would like to use them.
They also just need 3.3v and not both 5&3.3v like the MCP2562.

So is there anything against using them instead the MCP2562 in combination of teensy boards?

Regards..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 22, 2018, 09:43 am
That is on the hw side and library does not known anything about it. So if you think it ise better, just use it.

And NMEA 2000 runs 250 kb/s NOT 500 kb/s
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 28, 2018, 06:34 pm
Hello,

even if I am already afraid to ask, is there somebody so nice to explain me what that with SID - Sequencial ID is about?
I am workign on the battery monitor right now and found this for the SID in the N2kMessages.h at DC detailed status:

"Sequence ID. If your device is e.g. boat speed and heading at same time, you can set same SID for different messages to indicate that they are measured at same time."


Thank you!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 28, 2018, 07:55 pm
The explanation for SID has been just copied, but the meaning is same. On Maretron document they write:
Code: [Select]
SID - The sequence identifier field is used to tie related PGNs together. For example, the GPS200 will transmit identical SIDs for 126992 (System Time), 128259 (Speed), 129026 (COG and SOG, Rapid Update), 129029 (GNSS Position Data), 129539 (GNSS DOPs), and 129540 (GNSS Satellites in View) to indicate that the readings are linked together (i.e., the data from each PGN was taken at the same time although they are reported at slightly different times).

Will that explain it better?

So it could be same for DC information. You can provide DC status and battery status information with same SID, if they are measured at same time. Due to transmission delay there will be small difference, when messages will be received, but for same SID receiver can then use same time for values e.g. for calculations.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 28, 2018, 09:09 pm
I guess I got it now, thank you!

To clarify as example:

If I have now an device like GPS I could use the heading SID for a message which will show me the position on the map and could use the same SID and the value generated or measured by one sensor use at the same time in another message wich will be for example feedback for the autopilot.

If I see this right than the matter of this is to reduce the traffic on the bus or at least reduce the amount of times the values to be send needed to be generated or measured by the sensor system or in this case GPS.

So in case of the battery monitor which is for to batteries I could use several values/SID´s like the DCType for both batteries if the same generator is charging both of them.

Hopefully Right?

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 29, 2018, 06:17 am
I did not understood your example. What you mean with "in another message wich will be for example feedback for the autopilot."? In bus system you just mostly provide messages to the bus and not to specific device. Also many PGNs messages can not be sent to specific destination. 

Also you can not use SID for reducing traffic. If your device is sending some message, it should send it in periodically with same defined period. With the complex group function it is possible to change period for specific message, but it should then be steady.

Either I did not understood the last sentence. Normally SID is incrementing value. So if you battery monitor measures 3 batteries and measures all voltages on same time and then start to send messages for each battery, you use for first period e.g. SID=1 for all 3 127508 PGNs - each will have different BatteryInstance. On next  period you set SID=2 for each message. But if you measure values just before sending each msg, you do not measure them at same time. Then you should in principle set SID=1 for first msg, SID=2 for second and SID=3 for last. Then on next period you set SID=4 for first  and so on. This is since they are not measured "at same time".
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 29, 2018, 11:01 am
ok, than i thought completly wrong but understood it now. THX
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 31, 2018, 03:47 pm
Hello,

I came now to the point to connect the MFD ( Raymarne Axiom 9RV ) to the bus of the teensy to test if I get communication to the MFD.

After I didn´t got shown anything from the extern teensy´s on the Axiom ( during the network scan nothing showed up ) I to the messagesender and the Datadisplay to test the communication on the bus. I can see all comming from the messagesender on the datadisplay, but again nothing seems to be available on the MFD.

I stuck now a bit and don´t know where to start to troubleshoot and locate the problem.

Is there any advise you have for me to get further?

Kindly regards..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jan 31, 2018, 05:25 pm
- Again, do you have proper termination resistors on the bus?

- Instead of using DataDisplay, use ActisenseListener example and NMEA Reader. You should see both MessageSender messages and Axiom messages on the bus. If you do not see Axiom, have you crossed CAN L and CAN H.

Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 31, 2018, 06:19 pm
Hello Timo,

termination is 100% ok. First just used the 120 ohm resistor parallel to H/L on each end one. Than after it didn´t worked I connected through an original cable and terminators.

I use the SN65HVD234 with Teensy 3.2 like shown one the picture ArduinoDue_CAN_with_SN65HVD234.jpg. To test I used the standart sketches, just added/modified to use with teensy.

The Actisence listener sketch and listening on the bus with Actisense NMEAReader wasn´t successfull. There is a lot of load during when opend the com port from the Teensy running the actisense listener sketch.

Like mentionedthe datadisplay was showing the data send from the second teensy running the messagesender sketch.

I´ll test from beginning one more time just to be sure..
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jan 31, 2018, 06:40 pm
I located the problem!

Even the Axiom is delivering 12V from the bus connector, I have to connect from extern 12 V to the bus wire. Now it seems to work!
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Feb 04, 2018, 10:29 pm
Hello Timo,

I just found this document PGN NMEA Overview (http://www.nmea.org/Assets/20151026%20nmea%202000%20pgn_website_description_list.pdf) on nmea.org regarding the PGN´s and the temperatur PGN 130312 is deprecated.

Is that the reason why there are to PGN´s ( 130312 & 130316 ) for temperatur in the library?

Thanks.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 05, 2018, 03:28 am
Yes, but unfortunately old devices does not support 130316. So if you are making TemperatureMonitor like system for your boat, you have to check does your viewers support new PGN.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Feb 05, 2018, 10:59 am
Hey Timo,

I have a question.

So first I have participate on some courses about Arduino programming and got much more used to the basics and do understand now as well the library you gave to the world! I hope that I don´t need to ask anymore a lot of stupid questions! :-)

//To 1. part. I just tested it out, looks to be working fine! The jumping around which happend with the internal reciever just disappeared and the position is more accurate now as well. I am not anymore on map at my neighbours house. So that worked perfect! It took some time until the MFD recognized the new signal but finnaly I could selet it.

So here to my my question:

I got this GPS module from Linx which is a lot better than the one I have in my MFD ( I think and hope so at least). So the Linx GPS outputs "NMEA" sentences to serial. I got so far know with the GPS it self so I know how to adjust the settings of the module like setting baud rate, wich sentences to output to serial, frequency and so on.

Now I´d like to use this device instead of the one which is onboard of the MFD. How to do that on the MFD is not a big deal. It is looking for GPS / GNSS devices on the bus.

My actual question is:

1. - already fixed (working fine)
The device outputs NMEA sentences through serial, not more detailed specified. Is that right that these sentences is the NMEA0183 protocol?

If so, can I than just simply use the NMEA0183ToNMEA2K sketch to translate all the information comming from the module to the NMEA2k bus or do I need to read every sentences and cut into the peaces to use the NMEA2000 library positioning / navigation part and forward it by this way to the 2K bus? I looked into the NMEA0183ToNMEA2K library and have seen there all the positioning information. That´s why I thought this can be the right start.

2.
I am looking for some details if there exist any standart for the frequencies used for rapid data and longer periodly send data. What I mean is how many times per second is rapid and how ofteen is the rest of not so fast changing data to be send to the bus?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 06, 2018, 02:28 pm
Mostly there are stupid answers instead of stupid questions.

1. If it uses serial, it is most likely NMEA0183 format. And you need to know right baudrate that is using. Note also that serial is a bit wide definition and hopefully you also know the physical output, since it can be TTL, RS422 or RS232. Connecting RS232 to TTL may burn TTL side.

NMEA0183ToN2k does a lot and it seem to already have basic GPS conversion. There is no direct way to do that. NMEA0183ToN2k reads data from NMEA0183 and collects it to variables (see BoatData.h). When it has enough data, it will forward it. It seem to send at least GNSS, SetN2kCOGSOGRapid and Heading messages.

2. GNSS will be normally sent with 1 sec period. Heading and COGSOGRapid will be send with 100 ms or 50 ms period. NMEA0183ToN2k sends all messages as they arrive, since there is no data send faster.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Feb 06, 2018, 03:58 pm
Thanks Timo!

The gps/gnss i have is using ttl. I could connect it right to serial1 and it was working out of the box with the 0183to2k  library. Some things are missing, but before I need to take a closer look on what exactly the output is from the module to compare what I recieve on the MFD / bus and what exactly is send before I can say what is missing.

I ordered to PCB tofay which I found on OSHPark. They where for AIS implementation. I was missing the tx part onboard and since this was a hell of expensive i thought to give this one a try!

The application part is on github: https://github.com/peterantypas/ais_transponder by Peter Antypas.
One off the "Fans" was wondering about NMEA2K since that one is based on NMEA0183, I guess due to rs232 radio and MFD connection.

How ever, since they where talking about implementation of NMEA2K I posted them the link to your github repository as well to this post. I hope that is ok for your..

If somebody is interessted, Web of Peters github repo: https://github.com/peterantypas/ais_transponder
OSHPark files and details:
RF part: https://oshpark.com/shared_projects/E84PAqMK
Logic part: https://oshpark.com/shared_projects/U0kWDO24


Since AIS is already a part of the library I thought may it would be easy for them to translate it to nmea2k (easy thought). So we will see..
Title: Re: NMEA 2000 Shield
Post by: popeye_70 on Feb 16, 2018, 01:22 pm
One company has started to make Teensy based sensor boards for NMEA2000. They contacted me due to my library and send me some sample boards. There is one nice ready IMU board. I can ask are they ready to sell.
Hi Timo,
compliments for your libraries.

Have you any news about these Teensy sensors?
I would like to make a 9-axis compass to add at NAC-1 autopilot. My target is Lowrance Precision-9, this is what she do:
- Messages: PGN 127250, 127251, 127257, 127252
- Data output: Magnetic heading (20 Hz), rate of turn (20 Hz), pitch/roll (10 Hz), heave (10 Hz)
with a Roll/Pitch range of +-45° and Haeding accuracy +-2°

Do you think it's doable with Teensy board and your libs?
Thanks
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Feb 17, 2018, 04:49 am
Unfortunately thy are not yet on market, but the board is nice.

There is no problem with library to do that except 127252, which is unknown PGN. Teensy boards are good for that. If your prject is large as I would think that compaas would not be, Teensy 3.2 should be enough.
Title: Re: NMEA 2000 Shield
Post by: gwmurray on Mar 03, 2018, 02:31 pm
Hello,
I'm just about to start a project building a tacho, engine hrs, temp and display it on a Raymarine MFD. I have a couple of questions before I start and apologies if these have been answered before, ( I have been through the 28 pages and couldn't see it)

1. Is it possible to connect the CAN bus directly to the SeaTalk bus?

2. The MFD looks for an Engine manufacture when scanning for new devices, do I have to emulate my engine manufacture? (I have a Yanmar)

Many thanks for any pointers, help.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Mar 04, 2018, 06:52 am
1. Which Seatalk version. Read https://en.wikipedia.org/wiki/NMEA_2000 (Raymarine SeaTalk 2, Raymarine SeaTalkNG, Simrad Simnet, and Furuno CAN are rebranded implementations of NMEA 2000, though may use physical connectors different from the standardised DeviceNet Micro-C M12 5-pin screw connector, all of which are electrically compatible and can be directly connected) and make your own decicions.

2. It should not be necessary. MFD:s should just read PGN127488 and PGN127489 information from any manufacturer.
Title: Re: NMEA 2000 Shield
Post by: gwmurray on Mar 04, 2018, 08:30 pm
Brilliant Timo, thanks for the fast response.
Title: Re: NMEA 2000 Shield
Post by: popeye_70 on Mar 06, 2018, 11:59 am
I'm just about to start a project building a tacho, engine hrs, temp and display it on a Raymarine MFD.
.....
(I have a Yanmar)
Hi gwmurray, i have a Yanmar me too, mine is 4JH4 model.
Some infos hoping help you: original gauges are from VDO (mine are EU model, 40-120 C° for water temp and 0-10 bar for oil press) and the PPR (pulse per revolution) value at W wire (tachometer) is 10,29 with Hitachi 80A or 12,10 with Valeo 125A alternator

Unfortunately they are not yet on market
.....
There is no problem with library to do that except 127252, which is unknown PGN.
Hi Timo, just reached new hardware from Mouser...it's my first time with Teensy.

I started loading TemperatureMonitor, but i can't see nothing in Actisense Reader; so uncommenting also:

NMEA2000.SetForwardType(tNMEA2000::fwdt_Text);

i have that in Serial Monitor:

PGN 130312 send failed
PGN 130311 send failed
PGN 130310 send failed

What i'm doing wrong?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Mar 06, 2018, 12:40 pm
What hw you have? It is possible that you hw has enable signal for trasmitter. On library there is no automatic enable. So check from schematics it tranceiver tx enable connected permanetly to enabled state (as in my sample schematics) or to some teensy pin. If it goes to Teensy pin, then add to the beginning of code:
pinMode(PIN(??), OUTPUT);
digitalWrite(PIN(??), LOW);
Title: Re: NMEA 2000 Shield
Post by: popeye_70 on Mar 06, 2018, 01:32 pm
I have Teensy 3.2 board

Arduino 1.8.3
just installed latest Teensyduino, then deleted his FlexCAN library and installed the one found at your github. also installed nmea2000 and nmea2000_teensy libraries

In Arduino, which cpu speed is better to set for the 3.2 board?

i only opened temperaturemonitor.ino, uncommented lines as described in 4.2.1 "Try on PC only" chapter of your reference.pdf file, loaded on board and then opened Actisense Nmea Reader on my notebook with Win7.


EDIT:

problem solved adding:

NMEA2000.SetN2kCANSendFrameBufSize(500);

in setup, as you suggested to other guy in message #157
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Mar 07, 2018, 05:46 am
With NMEA2000.SetN2kCANSendFrameBufSize(500); you just move the point, when it starts to complain that it can not sent messages. TemperatureMonitor uses default value 40, which is enough normally. if you send a lot long messages at same time, you need to use bigger buffer. Note also that 500 eats a lot of memory. It means frames and one frame has 32 bit ID + 8 byte data so totally you have 5500 byte buffer. The Teensy has 64 kB ram, so it is not problem, if you do not write a big program.

I just tested TemperatureMonitor alone in Teensy 3.2 as it is explained in doc. 4.2.1 and it works fine. If you uncomment NMEA2000.SetForwardType(tNMEA2000::fwdt_Text);, then you can not see messages on NMEA Reader, since that changes the format to text. Instead you should see those messages on serial monitor.

I have used default speed on Teensy and not even tested others. But should be ok, with lower speed, since even Arduino Mega works and it is slower than Teensy.
Title: Re: NMEA 2000 Shield
Post by: popeye_70 on Mar 07, 2018, 09:38 am
Hi Timo
first o all, I thank you for your help and for your patience.

I'm still fighting with TemperatureMonitor.ino: I don't understand why it sends that strange 126993 PGN you can see in attached jpg...it not exists!

It probably should have been PGN 126996 "Product Information", or maybe also 126998 "Configuration Information"...and anyway i can't see the "ISO Address Claim" 60928 PGN as described in reference.pdf

Also tried the WindMonitor example, it works fine without NMEA2000.SetN2kCANSendFrameBufSize(500);
but also here i have the 126993 PGN

Maybe this strange PGN overload the buffer of TemperatureMonitor (that sends 3 other PGNs) but still not the WindMonitor buffer that sends only 130306 PGN?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Mar 07, 2018, 11:14 am
PGN 126993 is Heartbeat PGN sent on every 60 sec automatically by the library. This is new required PGN, which you old version of NMEA Reader does not know. The new version of NMEA Reader know it, but unfortunately Actisense have not published that version yet. Heartbeat beat is single frame message an so will not overload anything.

Also ISO Address Claim is problematic with only board/NMEA Reader combination. When you plugin the board, serial port does not exist and it take long time before NMEA Reader can attach to the serial port and on that time ISO Address Claim has already gone. And since no one is requesting it, you will not see it. You can see it e.g. with TyCommander (with test mode) or by adding delay(15000) as first command in setup().
Title: Re: NMEA 2000 Shield
Post by: popeye_70 on Mar 07, 2018, 11:51 am
PGN 126993 is Heartbeat PGN sent on every 60 sec automatically by the library. This is new required PGN
Oh, thank you for that info.
I had not found 126993 PGN even at www.nmea.org site!

So i think i can start write my project, and at the end of the game try to decrease step-by-step the buffer size.
I will try even if something changes using another computer and by feeding the Teensy from external power...maybe the usb port of my old notebook is too tired to work!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Mar 07, 2018, 12:07 pm
Dig deeper - Google "126993 heartbeat pgn corrigendum"
Title: Re: NMEA 2000 Shield
Post by: fredda_lk on Mar 26, 2018, 02:17 pm
Hi Timo
First o all, thank you for your fantastic work.

I'm using a Arduino Mega with MCP2515 Can modified with a 16Mzh crystal. When I'm running your example ActisenseListener everything works great together with Actisense reader!

But when I run DataDisplay2 I get different results every time in my serial port. Sometime I only get 1 sentence, other times I get 10-20 sentences and sometimes I get 200 sentences.
When I restart the Arduino it works directly again and I get some sentences.

Do you have any idea why I'm getting different amount of data?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Mar 26, 2018, 07:12 pm
Where you are getting the data and how much there is data? How many different PGNs and devices?

Just now I do not have idea. I have tested DataDisplay2 with MessageSender on Teensy and it still can catch all that traffic. The serial port may get stuck, if it gets data from PC to Mega direction. But this should not be the case, if you just follow the serial monitor and do not send any data to other direction. The stuck problem can be handled by adding
Code: [Select]
while ( Serial.available() ) Serial.read(); after NMEA2000.ParseMessages(); But I would be surpriced, if that would be the case.
Title: Re: NMEA 2000 Shield
Post by: fredda_lk on Mar 27, 2018, 09:31 am
For now I only have one device connected to the NMEA 2000 network, my engine, as you can see in the attached file.

I'm not sending any data on the serial port, just watching the information send in the example code. 

As you can see in the attachment it just stops sending data in the middle of a sentences, and when I restart the serial port I will receive data from start again. 
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Mar 27, 2018, 12:40 pm
Do you use Arduino Serial monitor? Could you try same with e.g. Putty.

Since you system works fine with Actisense NMEA Reader, I think that the Mega itself handles messages right. I have time to time seen different problems with Arduinos USB-Serial drivers.

Which OS you have?
Title: Re: NMEA 2000 Shield
Post by: fredda_lk on Mar 27, 2018, 05:48 pm
I have mostly used Arduino serial monitor but also Putty both with the same result, unfortunate.
I use win 10. Maybe it's a problem with receiving in windows and not the Mega?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Mar 27, 2018, 06:44 pm
I have W10 too, so it is difficult to say. Please confirm that with ActisenseListener - Actisense NMEA reader it runs without stopping - let it run long. In principle there is not much difference on handling between ActisenseListener and DataDisplay2. You could also try with ActisenseListener in text mode by uncommenting line
Code: [Select]
NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); and then use putty or serial monitor.
Title: Re: NMEA 2000 Shield
Post by: fredda_lk on Mar 29, 2018, 05:32 pm
Yes, the ActisenseListener runs without stop for 15 min. When I uncommenting the text line so I get text-mode I only get 200 sentences again exactly as the DataDisplay2 and it works in 10 seconds….

I have tried another serial converter and connected it with wires to tx0 and Rx0 and get the same resultate as USB port. Both on Putty and Arduino serial monitor.

When I run AtisenseListener and connect it with USB to Actisense Reader and in the same time connect serial reader with wires to Tx0/Rx0 I read data there too, but nothing I can understand.

Is there any buffer in the Mega that is filling up with data when it's in text-mode?


Title: Re: NMEA 2000 Shield
Post by: fredda_lk on Mar 29, 2018, 07:20 pm
Now I have some progress!

When I set the speed of the serial port to 230400 in the arduino program ActisenseListener and DataDisplay2 it runs without any problem when connected to my computer!

I don't now why and how but it works. Any idea?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Mar 29, 2018, 08:44 pm
No ideas. As I mentioned I have transmitted data with Messagesender and received all with Mega 115200 on DataDisplay2. And Message sender sends much more than on yours sample. One difference can be that your data had several 1 frame messages, which can be send faster. But I have not had time to simulate that.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Mar 30, 2018, 09:34 am
I am writing NMEA2000 -> NMEA0183 converion for Rasberry Pi for my friend. With this you just need RPi 3, PiCAN2 (or alternative) and the code for getting GPS data from N2k to e.g. OpenCPN.

Just note, if anybody is interested.
Title: Re: NMEA 2000 Shield
Post by: scottdube on Apr 04, 2018, 05:58 pm
Timo,

This looks really great.  I just stumbled onto your thread as i'm interested in using an arduino to listen on my Seatalk NG network and pull info off to transmit to an mqtt broker.  I have tried to look at the entire thread I have been unable to find if I can use your work to listen to the Seatalk network, either by native seatalk or using a NMEA 2000 converter and connecting the arduino to that?  Any direction would be very much appreciated.

Thanks

Scott
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 04, 2018, 09:40 pm
Seatalk NG is actually same as NMEA2000. There is a simple adapter cable to convert Seatalk NG to NMEA2000, but as far as I know it is just cable with different connectors - so no logic on it. Do not mix Seatalk and Seatalk NG. From Seatalk to Seatalk NG you need converter or device, which supports both like I have Autopilot. Then you see at least some Seatalk data also on Seatalk NG and NMEA 2000.

Waht is mqtt broker? If you do not yet have any Arduino board, I prefer Teensy 3.2 or up.
Title: Re: NMEA 2000 Shield
Post by: fredda_lk on Apr 04, 2018, 10:45 pm
I'm interested in a raspberry Pi solution. I have checked your guide on Github to connect the MCP2515 to the Pi, do you have any code example like the Arduino example, Datadisplay2, to read the NMEA2000 sentences in text mode? Or is that what you are working on now?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 05, 2018, 05:42 am
I added yesterday new example NMEA2000ToNMEA0183. I made it for my my friend for use with OpenCPN to get NMEA0183 data from NMEA2000 network. It also provides all NMEA2000 data to other port in Actisense format e.g. for SignalK server. The example has been tested on RPi3B with home made "PiCAN2" and also on DUE, Mega and Teensy boards.

On RPi3 I used CodeBlocks 16.01, which seem to install easily to Raspberry. The only trick was that one has to do: Plugins-Manage plugins... disable Code completition on CodeBlocks. Otherwise it will just close time to time without any save. I did not made simple makefile yet. I like IDE programming.

For "serial ports" on RPi I used tty0tty "virtual null modem cable". So my example writes data to one serial port so the other program can read it on other. You can find more about tty0tty on https://askubuntu.com/questions/588800/setup-virtual-serial-ports-linux-null-modem-emulator-using-tty0tty and download it from https://github.com/freemed/tty0tty. I am not sure would it have been possible to use pipes instead of tty0tty.

This was my first RPi solution and it took 2 days to get it up - well I spent some hours trying to get Atom for RPi. Anyway the instructions are not complete and one has to google some small tricks to get things working. I may redo everything and write simple step by step guide to get example up and running. But before that I should try to get ESP32 CAN running.
Title: Re: NMEA 2000 Shield
Post by: scottdube on Apr 05, 2018, 05:45 pm
Seatalk NG is actually same as NMEA2000. There is a simple adapter cable to convert Seatalk NG to NMEA2000, but as far as I know it is just cable with different connectors - so no logic on it. Do not mix Seatalk and Seatalk NG. From Seatalk to Seatalk NG you need converter or device, which supports both like I have Autopilot. Then you see at least some Seatalk data also on Seatalk NG and NMEA 2000.

Waht is mqtt broker? If you do not yet have any Arduino board, I prefer Teensy 3.2 or up.
Thanks Timo my install has Seatalk NG not seatalk I was not careful in my post.  So I think I can simply make up a connector and go directly to the arduino.  If I get this right though I need to put a CAN "device" like MCP2562 or similar between the Seatalk NG cable and the arduino?  I'm trying to visualize the connections.  If I do this I do not need an NGT-1 have I got that right?

MQTT is transport telemetry language developed for communication between IOT devices mqtt.org/faq  I'm looking at using the wind and gps info from the Seatalk NG bus along with sensor data that I build from mysensors.org type sensors.  Sending all that through mqtt to a database and displaying via node red.

Thanks for all of your work!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 05, 2018, 08:24 pm
Definetely NGT-1 is not necessary. MCP2562 is CAN tranceiver and it is enough with boards with internal CAN controller like Teensy 3.2/3.5/3.5 or Arduino DUE. Also ESP32 has internal CAN controller, but I am just writing drivers for it, so it is not good choice yet.

If you connect  your device directly to the ST NG, make sure to connect right wires. Also be carfull with power, if you are going to use it. If you have your "Arduino" allways connected to PC, you can just use USB power and connect only CAN L/CAN H wires. If you are going to use bus power, you need to take care that you do not feed them against from bus and USB.
Title: Re: NMEA 2000 Shield
Post by: scottdube on Apr 05, 2018, 08:51 pm
ThanksTimo,

So if If I get the teensy do I still need the CAN transceiver?  It sounds like I do.  I saw your boards you made and it looks like you used both.  Initially I just want to listen to the STNG bus and redistribute the data, but I'm sure I'll want to end up putting data onto it at some point.  It will only be connected to a PC to troubleshoot. Thanks for your advice.  I appreciate it!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 06, 2018, 04:30 am
You allways need tranceiver. Tranceiver is ready only on extension shied/breakout boards. If you are handy with electronics, you can use schematic for Teensy from https://github.com/ttlappalainen/NMEA2000/tree/master/Examples/TeensyActisenseListenerSender/Documents and make board simply by yourself. This has extra USB, which you do not need.

Other option is to buy ready board http://skpang.co.uk/catalog/teensy-canbus-breakout-board-include-teensy-32-p-1507.html. That uses linear DC-DC converter instead of scwithed one as I have on my schematics. As far as I see you should not power that breakout at same time from bus or USB. On my above docs there is also instructions how to separate USB power.

Other options are bigger on size and draws more current.
Title: Re: NMEA 2000 Shield
Post by: scottdube on Apr 06, 2018, 01:46 pm
Timo,

Is there a place where all of the libraries required to run this on teensy 3.2 reside?  I followed your instructions in the nmea 2000 reference but there are libraries missing on compile.  I don't want to just go find those individually as I'm afraid of finding out of date files.

Thanks!

UPDATE:  I think I got it...  It mostly compiles but since I don't have my board yet it appears it won't complete the compile.  I am used to being able to compile without a board attached but it looks like it doesn't work like that for this board.  I will know better when my board arrives.

Thanks!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 06, 2018, 02:18 pm
For Teensy NMEA2000 you need:
- Teensyduino installed.
- https://github.com/ttlappalainen/NMEA2000
- https://github.com/ttlappalainen/FlexCAN_Library
- https://github.com/ttlappalainen/NMEA2000_teensy

Note that on Teensyduino install you should not install FlexCAN. If you did, delete folder:
"C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\FlexCAN"

It should complete compilation without board and there should not be any errors/warning, if you use just compile button at leftmost on Arduino IDE.
Title: Re: NMEA 2000 Shield
Post by: scottdube on Apr 06, 2018, 02:58 pm
You were right, I loaded flexcan when I added Teensyduino.  I'm on a Mac so it took me a while to find but I got rid of the flexcan library in that install and it compiles just fine!  Now to try to get the simulator running!

Thanks again!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 06, 2018, 03:35 pm
Hi all, I just added ESP32 support to NMEA2000 library.
Title: Re: NMEA 2000 Shield
Post by: popeye_70 on Apr 06, 2018, 06:25 pm
Hi Timo,
i have a question about Nmea2000 rules: can i have two devices sending the 127489 PGN (but different fields) at same time?
For example, a device that sends field #11 discrete status 1 data, while another device is sending oil press and water temp?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 06, 2018, 07:03 pm
Yes you can. Take care that you provide "Not available" data to all fields you do not send on each PGN.

Also take care that you set different unique number for your devices. If you use my library, you define it during setup with NMEA2000.SetDeviceInformation(...). It is also best to set ProductInformation right, so you can separate the devices on MFD devicelist.
Title: Re: NMEA 2000 Shield
Post by: scottdube on Apr 06, 2018, 10:20 pm
Is there a place to get the N2K connectors?  I thought I saw it in this thread but I went trhough all 30 pages and did not find it!

Thanks

Scott
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 07, 2018, 01:13 pm
I do not know, what happened my previous reply.

For boards and hubs I have used 5 pos terminal blocks. Below are example Farnell codes:
- 1717013 CTB9208/5 TERMINAL BLOCK, PLUGGABLE, 5POS
- 1717025 CTB9308/5 TERMINAL BLOCK, HEADER, 5POS

Standard 5 pos Micro-C M12 connectors can be found e.g. from tme.eu. Look on
Connectors-Industrial Connectors-Industrial circular connectors-M12 connectors Filter "Number of Pins" to 5 and "Polarization" to "A code - DeviceNet" to get a list of possible NMEA2000 connectors. I used e.g.
- ELWIKA5012PG9 Connector:M12;female;PIN:5;angled 90°
- 12P-05PFFS-SF8001 Connector:M12;female;PIN:5
- 12P-05BMMA-SL8001 Connector:M12;male;PIN:5
- 12P-05BFFA-SL8001 Connector:M12;female;PIN:5
Title: Re: NMEA 2000 Shield
Post by: scottdube on Apr 07, 2018, 03:10 pm
Thanks Timo,

I'm sure I saw that post but I could not find it again!  BTW I got the NMEA Simulator working on my Mac last night and can't wait to try it on the boat.  Should get a teensy board and 2562 delivered today!

Thanks!
Title: Re: NMEA 2000 Shield
Post by: scottdube on Apr 08, 2018, 07:44 pm
So Timo,

Got the teensy running and communicating with the computer, had some challenges as I have a VM running on my mac which is my windows machine.  If anyone has trouble I can share what I needed to do. 

I have the TemperatureMonitor.ino running and it is visible to the Actisence NMEA Reader software.  I do not get the 4 PGNs that you reference in your documents though.

"Now you should see "ISO address claim" (PGN 60928), "Environmental parameters" (PGN 130310) ), "Environmental parameters" (PGN 130311) and "Temperature" (PGN 130312) messages on "NMEA Reader"."

I get all but the 60928 pgn.  I do however get 126993 which is the "heartbeat" I guess.

Any thoughts? 

Also, I am thinking the first stage of this will be as a listener, I just want to make sure I have this right.  I will connect the N2K bus L&H via the CAN BUS that I'm going to build.  If I later want the device to broadcast to the N2K bus do I really need the serial to USB converter you show?  I don't want to then create another physical conversion back to the N2K bus.  But can I connect the TX and RX to the same L&H wires?

Thanks!!!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 08, 2018, 08:29 pm
Ypu probably won't see 60928, since that will be send on the very beginning and the USB is not ready for communication, so NMEA Reader will miss it. If you would have it connected to real bus, some device would probably reaquest it and you would see it and some others then.

What do you mean with "...serial to USB converter you show"?
Title: Re: NMEA 2000 Shield
Post by: scottdube on Apr 08, 2018, 08:45 pm
What do you mean with "...serial to USB converter you show"?

I mean in the schematic and jpg that you have on teensy listener sender it shows 2 USB plugs.

https://github.com/ttlappalainen/NMEA2000/blob/master/Examples/TeensyActisenseListenerSender/Documents/Teensy_Actisense_listener_sender.pdf

 I'm not sure where you were plugging those into.  Unless one is for power or computer.  But my goal is for this box to send the data to another location without a pc in the middle.

Does that make sense?

Thanks you are a great person to help people like this!

Scott
Title: Re: NMEA 2000 Shield
Post by: scottdube on Apr 09, 2018, 03:31 am
Timo,

I built the Teensy with an MPC2562 CAN BUS today, I get it to communicate with the NMEA Reader using the static temp values. I hooked up a DS18B20 and get a different readout but not accurate.  I can't tell what pin you intended the data to go to.  I used what I believe is A0 or pin 14 it is 2 from the end.   I  loaded a different sketch and the output was -127 which usually means the wrong pin is being used for the data or the probe isn't working.

Thoughts on that? 
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 09, 2018, 06:23 am
You do not need second USB. That was for debug/analyze device I made for someone who wanted to send simulated data from my NMEA Simulator on one port and listen with NMEA Reader on other port.

Which code you are using for DS18B20? The sketches I have found are not usable with NMEA2000, since they does not make things asyncronously. Without async. your system may just delay 700-800 ms on which time NMEA2000 library woult be polled and you will loose possible device queries. This leads to situation that you MFD will show up your device and then not. With async. one can get delays to 10ms, which is acceptable, if your device does not do anything else. The best solution would be to use 1-wire with DS2482-100 and improved i2c library.

A0 is pin 14 as you can see on Teensy Pinout. DS18B20 is rather accurate and reliable.
Title: Re: NMEA 2000 Shield
Post by: popeye_70 on Apr 10, 2018, 03:01 pm
Yes you can. Take care that you provide "Not available" data to all fields you do not send on each PGN.
Thank you, Timo.

To test putting the "not available" data in one field i tried with a simpler PGN (the 130313 one) chosing field#5, and i think i found a mistake in the N2kMessages.h file...


I think

SetN2kPGN130313(N2kMsg, SID, HumidityInstance, HumiditySource, Humidity);

should be:

SetN2kPGN130313(N2kMsg, SID, HumidityInstance, HumiditySource, ActualHumidity, SetHumidity);


or maybe i'm looking at wrong/old Nmea 2000 pgn description list?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Apr 10, 2018, 05:08 pm
You were right - it is fixed now. SetHumidity is optional parameter, since it is rarely needed.

... should allways tripple check others commits.
Title: Re: NMEA 2000 Shield
Post by: keith-i on May 15, 2018, 09:59 pm
Hi Timo and others

Firstly, a huge thank you to Timo for developing this excellent resource and making it available to all. It is great fun being able to develop my own devices and realise there is no limit to what can be done other than my limited but growing knowledge of coding.

I have successfully implemented the temperature monitor and that talks to my N2k bus nicely. However, I am having a little trouble getting a thermocouple to work (using a Max31855). At this stage I am just running trials with a Teensy 3.2 on my PC without a can tranceiver connected. After a few seconds of seeing pgn's appear on the serial monitor in the IDE it then just says 'send failed'. Am I doing something wrong in my code or is this some kind of buffer problem because I don't have a tranceiver connected yet?

Quote
CAN device ready
Start address claim for device 0
5600 : Pri:6 PGN:60928 Source:22 Dest:255 Len:8 Data:24,15,C3,FF,0,82,96,C0
5851 : Pri:7 PGN:126993 Source:22 Dest:255 Len:8 Data:60,EA,0,FF,FF,FF,FF,FF
8602 : Pri:5 PGN:130312 Source:22 Dest:255 Len:8 Data:1,1,3,B3,6A,FF,FF,FF
8603 : Pri:5 PGN:130311 Source:22 Dest:255 Len:8 Data:1,C3,B3,6A,FF,7F,FF,FF
11603 : Pri:5 PGN:130312 Source:22 Dest:255 Len:8 Data:1,1,3,B3,6A,FF,FF,FF
11604 : Pri:5 PGN:130311 Source:22 Dest:255 Len:8 Data:1,C3,B3,6A,FF,7F,FF,FF
14604 : Pri:5 PGN:130312 Source:22 Dest:255 Len:8 Data:1,1,3,B3,6A,FF,FF,FF
PGN 130311 send failed
14605 : Pri:5 PGN:130311 Source:22 Dest:255 Len:8 Data:1,C3,B3,6A,FF,7F,FF,FF
PGN 130312 send failed
17605 : Pri:5 PGN:130312 Source:22 Dest:255 Len:8 Data:1,1,3,B3,6A,FF,FF,FF
PGN 130311 send failed
17606 : Pri:5 PGN:130311 Source:22 Dest:255 Len:8 Data:1,C3,B3,6A,FF,7F,FF,FF
Code attached

Keith
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 16, 2018, 06:35 am
Thanks.

The send fails, if you do not have it connected to the bus. Actually it should be enough to have one terminator resistor on tranceiver, but I have not tested. You do not get error message immediately, since if buffers some messages and when buffer comes full, error starts to appear.
Title: Re: NMEA 2000 Shield
Post by: tmsio on May 22, 2018, 12:01 am
Hi to all, thank you Timo for your work.
I m a beginners, but i wold you like to send some data from my ESP32 to N2k network.
I bought one NGT-1 usb gateway, to verify the data trasmitted from my ESP32.
I follow your guide, and i see temperature reading to NMEA reader via serial.
The next step is connect ESP32 to N2K network and read data from my ngt-1.
I connect GPIO4 and GPIO16 to MCP2562 pin 1 and 4 like this schema:
https://github.com/ttlappalainen/NMEA2000/blob/master/Documents/ArduinoDUE_CAN_with_MCP2562.pdf
But i cant read data in NMEA reder via NGT-1.
Where is the error?

Thank You

Emiliano




Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 22, 2018, 06:42 am
With quick look your connections seem to be OK, except I could not see is NGT-1 powered on NMEA 2000 side? You have to feed 12V to NMEA2000 bus, otherwice NGT-1 tranceivers will not get powered and it will not listen/send anything.

On NMEA Reader you can also allow NGT-1 to receive all data. Select Edit-Preferences...-"Transfer: Receive all"
Title: Re: NMEA 2000 Shield
Post by: tmsio on May 22, 2018, 08:25 am
Ouch!!!
Thank You Timo, il try to feed 12v.

:)

Edit:
All work fine!!!!
Thank You Timo
Title: Re: NMEA 2000 Shield
Post by: tmsio on May 22, 2018, 08:51 pm
An other question....
I have two engine, and i send the flow fuel rate of each engine to NGT-1.

engine0---> 56 l/h
engine1---> 23 l/h

This is my code:
Code: [Select]

SetN2kEngineDynamicParam(N2kMsg,0,N2kDoubleNA,N2kDoubleNA,N2kDoubleNA,N2kDoubleNA,Engine0Flow(),N2kDoubleNA,N2kDoubleNA,N2kDoubleNA,N2kInt8NA,N2kInt8NA,true);
NMEA2000.SendMsg(N2kMsg);
SetN2kEngineDynamicParam(N2kMsg,0,N2kDoubleNA,N2kDoubleNA,N2kDoubleNA,N2kDoubleNA,Engine1Flow(),N2kDoubleNA,N2kDoubleNA,N2kDoubleNA,N2kInt8NA,N2kInt8NA,true);
NMEA2000.SendMsg(N2kMsg);


Why in NMEA Reader i see

Engine0  ---> Fuel rate 0,0560 Cubic Metres Per Hour

Engine1  ---> Fuel rate 0,0230 Cubic Metres Per Hour

In  N2kMessages.h declar:
//*****************************************************************************
// Engine parameters dynamic
// Input:
//  - EngineInstance        Engine instance.
//  - EngineOilPress        in Pascal
//  - EngineOilTemp         in Kelvin
//  - EngineCoolantTemp     in Kelvin
//  - AltenatorVoltage      in Voltage
//  - FuelRate              in litres/hour
//  - EngineHours           in seconds
//  - EngineCoolantPress    in Pascal
//  - EngineFuelPress       in Pascal
//  - EngineLoad            in %
//  - EngineTorque          in %
// Output:
//  - N2kMsg                NMEA2000 message ready to be send.

Thank You

Emiliano
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 23, 2018, 04:56 am
This is the way how Actisence shows it and which actually has been better unit for library interface too, since it is SI. Note that 0,0560 m3/h = 56 l/h.

Note also that you should use SetN2kEngineDynamicParam(N2kMsg,1,... for engine instance 1. Otherwise value for engine instance 0 is just jumping between instance values (56 / 23 ).

Title: Re: NMEA 2000 Shield
Post by: tmsio on May 23, 2018, 01:38 pm
But, when i ll connect my esp32 to the nmea network, a garmin or raymarine display what will show?

L/H or m3/h?

And i need to trasform 0,560 in 56?
Example:

lh1 = lh1*1000;

Thank YOU.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 23, 2018, 01:44 pm
On sending by library function you have to use value in l/h. I would expect that on Raymarine or Garmin you can choose the unit.
Title: Re: NMEA 2000 Shield
Post by: simonfe on May 23, 2018, 09:37 pm
Hi I have successfully set up a teensy32 with CAN http://skpang.co.uk/catalog/teensy-canbus-breakout-board-include-teensy-32-p-1507.html and am using MessageSender.ino to interface to a Raymarine E70077 MFD (A-Series).

All the code worked perfectly, thank you Timo. A couple of items that caught me out at the start was forgetting that the SeaTalkNG MUST be supplied with 12V as well as the CAN breakout board, and that the 120 Ohm terminating resistor link must be fitted on the breakout board.

I am able to simulate Engine Temp, Oil Pressure, Battery Voltage and engine RPM by hard coding the relevant fields in the Sketch and I see them appear on the MFD. Next step is to write the A/D and frequency measurements and then do the hardware interface to the sensors and the alternator.

I would like the Raymarine MFD to provide over heat and low oil pressure alarms, I can enable the alarms in the MFD but cannot set alarm limits, so will do this within my sketch.

The part I am stuck on is how to send the right alarm messages over N2K/SeaTalkNG, I cannot find any reference to a pgn for alarm handling, does anyone know where I might be able to find this information?

The alarms I would like to send are:

Engine Overheat
Low Oil pressure
Low Battery Voltage

Thanks
Simon
 
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 24, 2018, 06:25 am
SetN2kEngineDynamicParam function has parameters for: flagOverTemp, flagLowOilPress, flagLowSystemVoltage.

Note that you should have terminal resistor at both end of main bus. SeaTalkNG is also CAN bus so its terminal resistors should be calculated. So totally bus must have two resistors! It is better to have resistors on the main bus and not on board, since if you e.g. remove board, your bus does not work. Each drop cable should not exceed 6 m. See e.g. http://www.yachting-pages.com/content/a-guide-to-nmea-2000-installations-for-yachts.html
Title: Re: NMEA 2000 Shield
Post by: simonfe on May 24, 2018, 09:01 am
Hi Timo,

Many thanks for the guidance, I was looking in the wrong place and had not seen the flags! I will have a play later to test it out

re Termination of the bus, yes understood. In this application I will only have the two devices as it is on a small motor launch and has no multi drop bus, just CAN breakout wired straight to the MFD. I guess that the MFD has no internal termination resistor so perhaps I should reduce the value of the termination resistor on the CAN breakout? It is working ok with the termination 120R on the breakout board, so maybe not an issue. I will later fit the same to our sailing yacht which has a properly terminated multi-drop bus so will not fit the terminator on that installation.

Thanks again
Simon
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on May 24, 2018, 03:05 pm
 I have not met any MDF with internal resistor. It would not be good. On test system with short bus, one terminating resistor is normally enough.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jun 17, 2018, 12:34 pm
Hello Timo,

after a half year now I have found some time again to take a look into NMEA again. This also due to my Princess gets a "new" engine which needs again a digital interface.

We started beside selling diesel based heaters for boat and caravan. I was thinking about if it is possible to control the heaters through the protocol. From the library, I found the "tN2kTempSource" class. Like the name show, it is just a source.

So do you know about devices which can control the cabin temperature through the NMEA2K protocol? I could find yet something about this from my device, the Raymarine Axiom 9. Would be great if I could make an interface which then could control the heaters through some kind of panel or already existing multifunction device.

I am talking about this device https://marine-varmer.no/produkt/planar-2d-12-tm-3995-12v-2kw-pu27/ , please this is not meant as advertisement here. We do not sell outside NO,DK,SE as well. It would be also interesting to control warm water heater which we use the engine water heater for together with a tank.
There is also a SMS module which can turn on and control the heaters. With the right interface it should be able to control whatever device in from the NMEA2K network where it would make sense.

So do you know about devices which are able to controle heating systems, do you have an example like a panel which could be mounted several places on the boat to controle the things?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jun 17, 2018, 06:01 pm
I do not know any common device for controlling heaters. The problem is that there is no standard messages for that, so every manufacturer would use proprietary messages.

On the other hand there temperature PGN:s 130312 (obsolote) and 130316 could be used for tempretature control. They both has field "Set temperature", which can be changed by standard way with Complex groupg function PGN 126208. So in principle your device can provide Cabin current temperature and set temperature with 130316. Then with other device - e.g. MFD it should be possible to change set temperature field on your device and so your heater would start to heat. Unfortunately I do not know does MFD:s support that functionality or if any does, how complex it would be change set temeperature. I mean that it may be behind several click.

Also you can make your own control panel and use proprietary PGN:s. With that you only win that the cabling could be used and you can provide current cabin temperature to the N2k bus. But there is also marketing question about certification. Even my library is "certification ready" the costs for getting you device certified are some thousand dollars. So how meaningfull it is for customers if you sell your system just NMEA 2000 compatible instead of NMEA 2000 certified, if they should connect it with critical network with navigation systems.

It may be easier to make own control panel with some wireless solution .
Title: Re: NMEA 2000 Shield
Post by: sprokkie on Jul 01, 2018, 01:59 pm
My plotter B&G vulcan 9 does not transmit or send the pgn for the binairy bank status  pgn 127501.
There is a way to get c-zone enabled i have to put in a config file.

anyone familiar with C-zone and know how to implement this ?
i eventualy want te set an output with my Vulcan 9
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Jul 01, 2018, 02:06 pm
hello timo
i have got my teensy3.2 + CAN breakout board working
I can send test data (windmonitor example sketch to nmea) to MFD (Raymarine Axiom LH3 - latest versions 3.5)
data displays on MFD as expected - all good.
I can monitor the nmea2000 messages (using actisense reader) and see all my bus devices and respective PGN messages etc - all good. (inc those generated by the sketch)

However when trying the "battery monitor example" .. using same config etc .. i see the various
PGNs generated by the sketch (PGN 127506, 127508, 127513) however i cant get any data
to display on axiom/LH3.
Raymarine manual lists PGN 127506 as supported (latest 3.5 LH3 version) - however respective data fields on MFD are blank (eg battery SOC - ive tried each of the 5 battery instances it claims to support - and note the sketch is sending battery =1)
The LH3 manual states data items support for
"battery - voltage, current, temperature... data items available for up to 5 batteries"
(which also is the same number of engines supported)
the LH3 manual doesnt provide any details on how the available data items map to the list of supported PGNs .
The "engine" related PGNs have a "alternator voltage" field, but no mention of current or temp.
At presentI dont have any devices sending battery voltage (nor do i have an engine gateway,
so no battery voltage or battery data displayed)

So to the question : do you have any clues on which PGNs might be used for the battery temp, current? (other than PGN 127508 - which is not shown on the supported LH3 PGN list .. and the list doesnt have any obvious PGNs listed for battery ... very strange)
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Jul 03, 2018, 05:28 am
further to above
I added the additional hardware (USB port) to my teensy, and using listenersender
sketch I have now been able to use your simulator s/w .
... as an aside - a BIG thanks for providing these tools, tutorials and great work on N2K library...

I can get data from simulator to display on MFD (axiom LH3) - all good, and have confirmed that
indeed the MFD is supporting (& displaying) PGN 127508... this question solved.

However ... whilst using the simulator and changing various parameters and viewing them using
actisense reader & on MFD Ive discovered some inconsistencies:
1) engine load % appears incorrect?
- for example when setting to 30% in simulator, NMEA bus displays 14% on BOTH MFD & actisense reader.
2) engine fuel rate L/Hr
- for example when setting 11.5L/Hr in simulator, NMEA bus displays 0.0052cu m/hr (5.2L/Hr) on actisense reader AND MFD displays 5.2L/Hr also.

the other engine parameters all appear to be OK ... the simulator values match MFD and nmea reader values.

also a couple of additional questions about simulator
3) DC status PGN 127506 - i can enable it in simulator, and see values on nmea bus reader
however it shows 246% for SOC ... and there doesnt appear any way to change this in simulator?
I assume its hard coded?
(MFD doesnt display... but this may be because it expects a value of 100% or less?)
4) Alternator voltage (engine PGN) - these are displayed on MFD and nmea reader - but i cant find anywhere to change these on simulator , once again Im assuming these are hard coded?

Title: Re: NMEA 2000 Shield
Post by: eMTea on Jul 03, 2018, 10:27 am
Hi!

Interesting thread!

I've been thinking about something like this myself, to input data to my MFD at the Garmin 721XS.
I've found a Datalink to NMEA2000 converter for all the engine data, but it does not include all the data I wish to see.

I would like to send to N2k network:
Oil Pressure (from an analog 0-5v sensor)
Raw water temp (from analog sensor)
Raw water pressure (from analog 0-5v sensor), but I don't know if the MFD has a display field for it though.

I see there is a lot of people using N2k and arduino, so please, can you guide me to a place to start learning about protocol and hardware, because can-bus systems is new to me.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 03, 2018, 10:55 am
1) engine load % appears incorrect?
- for example when setting to 30% in simulator, NMEA bus displays 14% on BOTH MFD & actisense reader.
2) engine fuel rate L/Hr
- for example when setting 11.5L/Hr in simulator, NMEA bus displays 0.0052cu m/hr (5.2L/Hr) on actisense reader AND MFD displays 5.2L/Hr also.

the other engine parameters all appear to be OK ... the simulator values match MFD and nmea reader values.

also a couple of additional questions about simulator
3) DC status PGN 127506 - i can enable it in simulator, and see values on nmea bus reader
however it shows 246% for SOC ... and there doesnt appear any way to change this in simulator?
I assume its hard coded?
(MFD doesnt display... but this may be because it expects a value of 100% or less?)
4) Alternator voltage (engine PGN) - these are displayed on MFD and nmea reader - but i cant find anywhere to change these on simulator , once again Im assuming these are hard coded?


I'll try to check the errors above. Some values are just hard coded quicly to get some information to the bus.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 03, 2018, 10:57 am
I see there is a lot of people using N2k and arduino, so please, can you guide me to a place to start learning about protocol and hardware, because can-bus systems is new to me.
You do not need to study protocol - it is bit complex. Just take my library (https://github.com/ttlappalainen/NMEA2000), check the examples and start to build your own systems.
Title: Re: NMEA 2000 Shield
Post by: eMTea on Jul 03, 2018, 11:30 am
OK, thanks for the good work you have done, and shares with the community. :)

I will dig into this and see if I'm able to get familiar :P I've built a sensor based system before, with i2c OLED screen, but this bus system is alot more complex.

What happens if there is two similar PGN's at the same network? If I send some data that is already broadcasted by another device?
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Jul 03, 2018, 05:10 pm
quote "what happens if there is two similar PGN's at the same network? If I send some data that is already broadcasted by another device?"

... nodes on nmea200 broadcast messages at various intervals, the frequency is different
depending on the type of data. (eg engine specific data has a rapid update, whereas something like airtemp would be much slower)
the nodes displaying the respective data (eg MFD) will typically react to whatever is the last recieved data.
so if you have more than one node sending the same PGN data fields,
you would expect the mfd to flip back and forth between the differing values, depending
on the rate of change,
however the frequency and concuurency will likely create some weird and unpredictable behaviour.

... bottom line .. avoid this situation!
.. timos libraries allow data fields within specific PGNs to be "not sent" ... so you can avoid this situation occuring.
( & with the hardware and listener example sketch , and the actisense reader on PC,
its possible to monitor the nmea bus to determine exactly what PGNs and fields are being sent,
and hence then avoid duplication of any data)
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 04, 2018, 06:48 am
To be strict each PGN has defined default update period. Like Engine rapid data has 100 ms and engine dynamic data 1000 ms. I am not sure about temperature PGNs, but if I remember right they are also 1000 ms.

Note also that some PGNs like 130312 Temperature, 130316 Temperature Extended Range has "Instance" field. So there can be several devices sending same PGN and there is no problem, if the instance field differs. Also engine rapid data PGN 127488 has instance field, but that is locked to your engine or generator.

On newer MFD:s one can also define, which device data they show. So there can be several devices sending Depth or GPS position and then you define on MFD, which one it uses. In that case MFD will lock data to device "Name", which is unique for all devices on the bus. Either on this case there is no harm for multiple devices sending same PGN. If I remember right, this locking is mandatory on certified devices.
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Jul 04, 2018, 08:04 am
Timo, i think you are partially correct in respect to defining source for certain PGNs,
and Im sure it varies from mfr to mfr.
Im only using my Raymarine Axion LH3 as basis for my view...
The LH3 allows user to lock the data source for depth, speed thru water, heading, GPS, wind, time & date.
Hence with multiple sources of same (above) PGN, its possible to select (lock) which
the MFD will use.
However I cant find any reference in LH3 for selecting or locking other PGN sources,
eg fuel tank, water tank, battery, environmental etc.
So one does need to be careful with some of these additional data sources to prevent a clash.

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 04, 2018, 10:58 am
Fuel tank, water tank, battery, environmental etc. PGNs works with instance field. E.g. Garmin GMI 20 can not either lock to specific source for those, but you can see different instances. Also GMI does not show anything selectable, if you do not have several instances available. But as you said one has to be carefull,but on the other hand why you would have several sensors on same tank? And if they are on different tank, they re different instances.
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Jul 04, 2018, 11:47 am
yes agree with all your points.

Im learning more about instances at present ... the reader and simulator are brilliant ... for
working out the details that the mfrs "leave out" ....
I just put up every data item i can on screens - and then use your simulator to work out
what shows what ...
one of the confusing things ive discovered, (at least in raymarine world) is that
instance "0" is typically shown as "xxxx 1"
eg battery voltage sent as instance 0 is shown as "Battery Voltage 1"
and instance 1 shows up as "battery voltage 2" ... and so on.
likewise engine instance 0 (port engine) displays as  "alternator voltage 1" .

Im now imersing myself in understanding how your library works !
My plan is to inject onto NMEA a bunch of PGNs that are displayable on MFD,
but for which i dont have NMEA capable sensors (eg fuel tank, water tank, black tank, engine room temp, humidity and baro, domestic battery, generator battery, )
..let the fun begin!
Title: Re: NMEA 2000 Shield
Post by: eMTea on Jul 04, 2018, 04:30 pm
My plan is to inject onto NMEA a bunch of PGNs that are displayable on MFD,
but for which i dont have NMEA capable sensors (eg fuel tank, water tank, black tank, engine room temp, humidity and baro, domestic battery, generator battery, )
..let the fun begin!
Interesting, but how would you display these values, does you MFD or chartplotter allow you to customize it to display all these fields?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 04, 2018, 06:25 pm
E.g. Garmin GMI 20 has definable pages for 4 values on each page. B&G vulcan has also configurable data values. So yes, MFDs should have them othervice they are not MFD - just SFD (Some Function Display).
Title: Re: NMEA 2000 Shield
Post by: eMTea on Jul 04, 2018, 08:06 pm
E.g. Garmin GMI 20 has definable pages for 4 values on each page. B&G vulcan has also configurable data values. So yes, MFDs should have them othervice they are not MFD - just SFD (Some Function Display).
That I understand, but humidity and engine room temp, are those actual values existing in the n2k protocol?
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Jul 05, 2018, 12:09 am
nmea protocol has a few PGNs relevant for "temperatures"
PGN 130310 environmental
PGN 130311 environmental
(cant remember which of above has "air temp" , "humidity" its assumed this is outside humidity,
these are the PGNs typically used by a weather station/wind instrument)
and
PGN130312 extended temperature
PGN 130316 extended temperature
across above, they support a number of different temperature types ("cabin", "engine room", "refrigerator"
"freezer", various "tanks", "air duct", "under bolts" ... and so on)

as timo says, it then becomes dependant on the display used (MFD, dedicated data display etc)
as to what PGNs it will support, and how it displays them (& any level of customisation ... eg renaming the way its displayed)

In my case Im interested in "engine" room data ..I dont have a weather station/wind sensor
so i will be using "humidity" to actually display the engine room humidity, and likewise "air temp"
for engine room temp - as my MFD (raymarine) doesnt support PGN instance for  "engine room temp"
(later on .. I might build a small dedicated display and use timos arduino libraries to display a bunch PGNs that are not supported by my MFD)
from what i can see - nmea protocol only supports one humidity instance.  but it certainly
supports multiple temp instances.
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Jul 05, 2018, 12:16 am
google the following
nmea technical bulletin PGN130316 feb 2015

.. it lists all the various source codes that corelate to the different temp types
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 05, 2018, 08:54 am
If you are going to use my library, you will find possible values also in N2kMessages.h in tN2kTempSource enum definition.

Note also that 130316 is rather new PGN and old MFDs does not support it. You may need to use obsolete 130312 for temperature.
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Jul 05, 2018, 11:30 am
thx and noted,
a further check on my (very new) raymarine axiom - with the very latest lighthouse sw,
shows that it doesnt support either!! 130312 or 130316 (well at least according to the manual - which
ive already found one other PGN omission ... )
so at present i will likely have to fudge "engine room temp" to "air temp" PGN instance/source.
.. and hope that raymarine will add the additional PGNs over time .. ...
... its really making me think twice about a dedicated display (your library with a teensy and an OLED display) of the various PGNs that
are not supported! (eg exhaust gas temps , engine room temps, ...) .. anothet "to do list project"
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 09, 2018, 07:02 am
It is very strange MFD, if it does not support 130312. And if it is new, it should read 130316, since 130312 and 130311 are obsolete. But maybe this is Raymarine logic.

How about 130311?

What do you mean with "air temp" PGN instance/source? PGN 130310, which is also obsolete.

Have you checked KBox: https://hackaday.io/project/11055-kbox
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Jul 09, 2018, 09:58 am
the (very latest - last month) Raymarine Lighthouse 3 sw lists support for only
PGN 130310 & 13011 ... 312, 316 not listed  .. and yes agree it should support the new ones .. but doesnt appear to ... Im trying to get some clarity from them .
seems they are struggling with the feature set in the new LH3 (android? based OS)

To fudge a engine room temp - i was going to encode this as "air temp" (because i dont have a
environmental sensor  on. my network)
... and hope that raymarine add support for 130316 in the future....

I looked at k-box - however my boat has multiple 24V battery banks ... and its analog inputs
are shown as "up to 23V ... way to low for a nominal 24V bank)
I also already have 2 NMEA0183 convertors on my 2k network,
likewise i have a autopilot with its own heading rate sensor.
..so im struggling with the value that k-box adds for me ?
 I do like the inertial unit for pitch/roll, and barometer. 
I dont see temp/humidity listed? which im also interested in.
so i will have another look at it ... perhaps its expandable ..
 
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Jul 10, 2018, 05:04 am
hi timo.
not sure where to put this question, its partly related to the arduino & nmea2k library,
but if I should put it elsewhere or start a new thread pls advise.

I want to capture a "log" from nmea2k data to be able to post process and then display
a selection of data  to be able to plot fuel economy vs a range or parameters that
typically impact consumption. (eg  eng RPM, eng load %, eng fuel rate, pitch and roll, true wind speed and direction,
fuel tank level, water tank level..)

using teensy listener/sender  - with actisense reader and EBL reader I can display n2k data,
and capture logs in "ËBL format"
but i need to get data into excel or similar to be able to do some post process computations and
then graph data. EBL reader doesnt have any options to save out to excel or other formats?

Ive had a look at "openskipper" - which i note can ingest the data from actisense listener
in real time..
however im struggling with understanding how/if it could achieve what im trying to do?

 is there a simpler way to get decoded nmea2k data from activelistener into "logged" excel format?
(i prefer excel because i need to write some formulas for computing average fuel rate, economy,
and then do some graphing) ... and I understand excel (but not xml . cs etc)

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 10, 2018, 07:02 am
I have same problem. I have logged everything for 2-3 years with OpenSkipper. In main window with right click you can start Track. Unfortunately this log format is OpenSkipper specific - timestamp+N2k and I have not yet wrote a parser for that. I am going do, but when? I use OpenSkipper for logging, since I have it anyway open for providing data as web server.

One option would be to make own logger.  Take a look in to the example DataDisplay2. You could clone that and format output to .csv and then just log terminal data. If you need quick temporary solution, this could be the fastest one.

Currently thread is OK, since it partially belongs to shield.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Jul 11, 2018, 04:07 pm
Hello!

I need to convert the RPM signal from gasoline to diesel.
The story:
I had last year a V8 gasoline engine in my boat but this year I have dropped that engine out and have put a 6 cylinder diesel engine.

Also, I bought a completely new set of instruments last year but for gasoline engines. (RPM)
I can choose on the RPM meter from 4 to 12 cylinder. With the V8 I had 8 pulses per RPM.
With the diesel engine, the puls is coming from the flywheel and give 1 puls per RPM like I know.
So now my plan is to convert the 1 puls up to 4 pulses per RPM so I get shown the correct RPM on the gasoline RPM meter.

Since Teensy or Arduino just can handle 3 V / 5 V max it have to go through a transistor as well I guess.

The same Teensy shell deliver the RPM sentence to the MFD as well I thought (EngineSpeed Rapid).

Can somebody help here with a code example for the pulse conversion?

Thank you!

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Jul 12, 2018, 06:22 am
I am not sure did I understood your problem. If you just want to measure some input frequency (RPM) check https://www.pjrc.com/teensy/td_libs_FreqCount.html
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 13, 2018, 03:30 pm
Hi Timo,

I have a question regarding SetN2kEngineDynamicParam. I am building a device to read the FuelRate based on impulses per ml by fuel flow.

If I want to send the result now do I have to send now the hole SetN2kEngineDynamicParam block or can I just update the FuelRate?

How does the code line looks like to just send the FuelRate then?

The other values are coming from a different device (or shell come from a different device in the future).

Another question:

I want to use some code to calculate the flow rate which uses an external interrupt. Will this affect the library for example during sending the messages? I could imagine that this affects the rapi data for example..

Regards,
Thomas
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 13, 2018, 08:48 pm
You just set other information to NA
    SetN2kEngineDynamicParam(N2kMsg,0,N2kDoubleNA,N2kDoubleNA,N2kDoubleNA,N2kDoubleNA,FuelRate,N2kDoubleNA);
NMEA2000.SendMsg(N2kMsg);

Interrupts should be short, so it should not effect too much to other routines. Anyway I prefer to use external or internal counters for calculations. I made my own fuel monitor with external counters with latches and even with that getting good results were tricky. You will also need dampers on fuel line. See e.g. http://www.floscan.com/html/blue/accessorydetail.php?aid=69
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 14, 2018, 05:50 pm
ok, thank you Timo.

regarding pulsation damper. I have a water absorber inside the fuel line. The sensor shall be mounted right after the tank and before the absorber. Do you think I still need this damper? The absorber holds approx half a liter of diesel and the fuel line is made of gummy with 12mm diameter.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 14, 2018, 08:45 pm
If your pump is pusation pump, you will need it. If it is rotation pump (very rare), it may work without.

It does not need to be those, but idea is important. They must be between engine and sensor on both input and return lines.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 17, 2018, 04:18 pm
Hello,

may a stupid question, but kind of datatype I have to use for FluidType in:
   
Code: [Select]
SetN2kFluidLevel(N2kMsg, Instance, FluidType, Level, Capacity);

I get the hole time whatever I tried the message error: invalid conversion from 'WHATEVER' to 'tN2kFluidType' [-fpermissive]
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 17, 2018, 05:40 pm
You must use tN2kFluidType type define in N2kMessages.h. E.g.

Code: [Select]
SetN2kFluidLevel(N2kMsg, Instance, N2kft_Water, Level, Capacity);

or

Code: [Select]
tN2kFluidType FluidType=N2kft_Water;
SetN2kFluidLevel(N2kMsg, Instance, FluidType, Level, Capacity);
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 19, 2018, 11:11 am
Hey Timo,

got it! I just forgot that. Had a break of some month.

Another question, RapidEngineData how often do this need to be send? Is once or twice a second enough? When I think about RPM, for example, it needs to be updated a lot to get a smooth result?
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 19, 2018, 12:32 pm
Hi,

I just got the sketch for fuel rate and fuel tank finished but can not test it.

Do anybody have a couple of minutes to look through if this would work? I don´t mean to fix everything or show every the best way. Since I am not that genius in arduino programming I would already be happy if that will work before I start to optimize everything.

EDIT
" I just found some things,I would need smoothing for the tank volume as thoose are moving a lot when the boat is rolling and so on!"

Thanks a lot!

Code: [Select]
// Get tankvolume (pin 20 Teensy3.2) and fuelrate (pin 19), calculate and send through NMEA2K CAN

#include <Arduino.h>
#include <NMEA2000.h>
#include <N2kMessages.h>
#include <NMEA2000_teensy.h>
tNMEA2000_teensy NMEA2000;

// *********************************************
// NMEA2K related setup
// *********************************************

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

// *********************************************
// Variables to setup function reading fuelrate
// *********************************************

volatile int pulsCountValue; // Storage for counted pulses through interupt function
unsigned int FuelRate; // Calculated litres/hour
unsigned char flowsensor = 19; // Sensor Input
unsigned long currentTime;
unsigned long startTime;
#define FuelRateUpdatePeriod 1000


// *********************************************
// Variables to setup function reading fuel tank level
// *********************************************

unsigned char tankVolumeSens = A20;
#define FuelLevelUpdatePeriod 1000

// *********************************************
// Variables to setup sending of NMEA2K message
// *********************************************


double Instance = 0;
double Level;
int Capacity;
tN2kFluidType FluidType = N2kft_Fuel;

void setup() {
  // Set Product information
  NMEA2000.SetProductInformation("00000010", // Manufacturer's Model serial code
                                 100, // Manufacturer's product code
                                 "Fuel Information System",  // Manufacturer's Model ID
                                 "1.1.0.22 (2016-12-31)",  // Manufacturer's Software version code
                                 "1.1.0.0 (2016-12-31)" // Manufacturer's Model version
                                );
  // Set device information
  NMEA2000.SetDeviceInformation(10, // Unique number. Use e.g. Serial number.
                                150, // Device function=Atmospheric. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                75, // Device class=External Environment. See codes on  http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                2046 // 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, 23);
  // NMEA2000.SetDebugMode(tNMEA2000::dm_Actisense); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega
  NMEA2000.EnableForward(false);
  NMEA2000.ExtendTransmitMessages(TransmitMessages);
  NMEA2000.Open();

  // Void Setup for Fuel Rate
  pinMode(flowsensor, INPUT_PULLDOWN);
  digitalWrite(flowsensor, LOW); // Optional Internal Pull-Up

  attachInterrupt(0, pulsCounter, RISING); // Setup Interrupt

  sei(); // Enable interrupts
  currentTime = millis();
  startTime = currentTime;

  Serial.begin(9600);

  // Setup for Fuel Rate END
}

void loop() {

  // *****************************************************************************
  // Call the looping functions
  // *****************************************************************************

  SendN2kFuelRate();
  SendN2kFuelLevel();
  NMEA2000.ParseMessages();
}



// *****************************************************************************
// Double replacement for standard map function
// *****************************************************************************

double dMap(double x, double in_min, double in_max, double out_min, double out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

// *****************************************************************************
// Interupt function. Count pulses from interupt.
// *****************************************************************************

void pulsCounter() {
  pulsCountValue++;
}

// *****************************************************************************
// Read and calculate fuelrate based on pulses from pin 19
// *****************************************************************************

double ReadFuelRate() {

  currentTime = millis();
  // Every 3 second, calculate and print litres/hour
  if (currentTime >= (startTime + 3000))
  {
    startTime = currentTime; // Updates startTime
   
    FuelRate = (pulsCountValue * 3.6); // (Pulse frequency x "3600/1000" 3.6 = flowrate in L/hour

    //    Serial.print(FuelRate, DEC); // Print litres/hour
    //    Serial.println(" L/hour");
  }
  return FuelRate;
}

// *****************************************************************************
// Read and map current fuel tank volume based on pin 20
// *****************************************************************************

double ReadTankVolume() {
  double Level= dMap(analogRead(tankVolumeSens), 60, 900, 0, 100);
  return Level;
}

// *****************************************************************************
// Send NMEA2K message for Fuel rate
// *****************************************************************************

void SendN2kFuelRate() {
  static unsigned long FuelRateUpdated = millis();
  tN2kMsg N2kMsg;

  if ( FuelRateUpdated + FuelRateUpdatePeriod < millis() ) {
    SetN2kEngineDynamicParam(N2kMsg, Instance, N2kDoubleNA, N2kDoubleNA, N2kDoubleNA, N2kDoubleNA, FuelRate, N2kDoubleNA);
    FuelRateUpdated = millis();
    NMEA2000.SendMsg(N2kMsg);
    pulsCountValue = 0;
  }
}

// *****************************************************************************
// Send NMEA2K message for fuel tank level
// *****************************************************************************

void SendN2kFuelLevel() {
  static unsigned long FuelLevelUpdated = millis();
  tN2kMsg N2kMsg;

   if ( FuelLevelUpdated + FuelLevelUpdatePeriod < millis() ) {
    SetN2kFluidLevel(N2kMsg, Instance, FluidType, Level, Capacity);
    FuelLevelUpdated = millis();
    NMEA2000.SendMsg(N2kMsg);
  }
}

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 19, 2018, 06:47 pm
NMEA2000 defination for RapidEngineData is 10 times/second.

If you are not sending WindSpeed PGN, you should not list it on TransmitMessages. If you are sending EngineDynamic parameters, you should list that on TransmitMessages.

Set the SetProductInformation and SetDeviceInformation right.

What kind of sensor (pulses/litre) you have and how much you expect to burn fuel in hour? As quick calculation your code accuracy can not be very good.

For analog read you can increase accuracy by increasing avaraging with analogReadAveraging(32); and/or putting readings to ring buffer and averaging that. Fuel level does not need to be very quick, so you could have e.g. 60 readings long ring buffer where you update reading every second. Then you have 1 minute averaging value.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 20, 2018, 01:26 pm
Hello Timo,

Thx.

The sensor for fuel rate is a G12 OF 201. I tested it out and it gives 7.13 ml/puls. I let 2 liters flow 20 times through the sensor and measured & calculated the average with result 7.13ml/puls.


If I am right then fuel rate is a rapid date, right? So it will be sent every 100 msec. I do not think it is a problem at full rate but if I average the value lets say for 2 or 3 seconds I would send values from the past? This is not a problem I know.
Other more important rapid data like rpm, in one-second huge changes can happen here. What is here a better solution then count the pulses and average them?

I have seen a couple of status "flags" in the n2kmessages.h like flagOverTemp, flagLowOilPress, flagLowOilLevel and so on. I have some sensors on that engine which are not connected anywhere like for example right under the RTC for the coolant temp. I think these are alert "switches" / sensors to give an overheat signal for example. If I am right with this sensor then those flags are for this unconnected sensors right? If not, they could be calculated and set when the temp is going over a fixed defined limit? Its just a thought, I do not know yet if mayAxiom have some functions regarding this flags.

Are you using this flags? I mean it is very cool to create a complete digital engine control panel for older engine for example.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 20, 2018, 02:28 pm
How much your engine is eating fuel/h?

So if you have 8 ml/pulse you will have 1000 / 8 pulse/l = 125 pulse/liter. If your engine takes 40 l/h, it means 5000 pulse/h = 1.39 pulse/s This means that you can not calculate pulses with 1 s period. Not even with 3 s - as you do in ReadFuelRate - giving you sometimes 3 pulses and sometime 4 pulses causing 33% changes. And by the way you newer call ReadFuelRate and do not update FuelRate variable. On idle engine takes so little fuel, that you can not measure it.

If the fuel stream is steady, you can get some results by measuring distance of each pulse in microseconds. But even that value you have average e.g. by using ring buffer.

Fuel rate is not on rapid PGN. It is on Engine Dynamic Parameters PGN, which you update once per second.

I have not used flags under engine dynamic parameters. Some MFD:s can show alarm according to them.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 21, 2018, 03:22 pm
Hi Timo,

of course, you are right if I think about this now! I also saw this type of calculation/measurement where the time between the pulses is base for the calculation. I couldn´t figure out how that person who wrote that code came on the value of 7.5 puls per liter per hour.

the other errors.. before I posted this code I had sent you a PM a couple of days before. May you didn´t saw that. I don´t want to spam the thread with my code full of failures because I am not able yet ( or maybe never) to get this correct done.

EDIT: I jus realized what you have mentointed that fuel rate is not rapid data. So the next part is not right.

/ wrong

Regarding SetProductInformation and SetDeviceInformation, I am sure I didn´t think the whole thing to the end before I started with this device(s). EngineRapid data like FuelRate and Fluid level are different classes and functions. So this will then by a multidevice, right?
If so I will remove the fuel rate and put that first into its own device and may later with into the main device for the engine where all rapid- & dynamic data shall be generated.

wrong /

I will try to correct all you mentioned. Can I send it to you by PM or shell I post it here again?
I am sure you have better things to do than teaching me all this and correct all I try to create. Unfortunately, I have no idea where to post or ask somewhere else since this is tight together with your nmea2k library.

Regards & thanks
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 23, 2018, 01:29 pm
Just found a good fitting flow sensor for an affordable price (about 100 €).

It is the GEMS FT-210 made of Polyamid which is gasoline and diesel nonreacting.

This sensor delivers 22.000 puls / liter and goes official according to the specs from 0.1L/min to 2.5L/min which are from 6L/hr to 150L/hr. But I guess if accuracy do not count as much under 6L/hr then it would deliver 367 puls/sec at 1L/hr.

This would be great for the flow meter application.

Here is the link to the manufacturer if somebody is interested: GEMS FT-210 0.1 to 2.5 L/min 22.000 puls/L (https://www.gemssensors.com/flow/electronic-flow-sensors/turbo-flow/ft-210-series-flow-sensor)

I think with a so high puls rate simple smoothing would be enough to update the flow rate once per 2-3 seconds?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 23, 2018, 03:35 pm
I will try to correct all you mentioned. Can I send it to you by PM or shell I post it here again?
I am sure you have better things to do than teaching me all this and correct all I try to create. Unfortunately, I have no idea where to post or ask somewhere else since this is tight together with your nmea2k library.

Regards & thanks
Sorry, I did not notice PM. I had marked it read somehow. Yes you can send me PM.

You do not need to use MultiDevice. The Class and Function are informative and does not effect for device functionality.

I can do some guiding with coding, but currently I have reasonably big project under coding.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 23, 2018, 03:46 pm
About other sensor. The problem with counting is syncronizating system. I used external counter chip, but actually still better may be just measure time between pulses. GEMS FT-210 provides maximum 150 * 22000 /3600 = 917 p/s, which is not much - 1 ms / p ans so could be measured by using us timer. There is also FreqCounter and FreqMeasure libraries for Teensy.

You still have not answered how much your engine will take fuel / hour. Also it is important that does it have only one fuel line or like I have 2 - one for in and one for return. So I need two sensors and need to calculate difference.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 23, 2018, 05:45 pm
About other sensor. The problem with counting is syncronizating system. I used external counter chip, but actually still better may be just measure time between pulses. GEMS FT-210 provides maximum 150 * 22000 /3600 = 917 p/s, which is not much - 1 ms / p ans so could be measured by using us timer. There is also FreqCounter and FreqMeasure libraries for Teensy.

You still have not answered how much your engine will take fuel / hour. Also it is important that does it have only one fuel line or like I have 2 - one for in and one for return. So I need two sensors and need to calculate difference.

I figured out now how this would work with using the time between the pulses instead. That`s why  I came to the conclusion that the flow sensor I have do not fit at all since it would need about 25 seconds to get a puls at a rate of 1L/hr.
I was thinking about to block all counting until it reaches about 4-5 L/hr, but this wouldn`t be effective since I wanted this sensor data because I would like to use the calculation functions of my MFD when it comes for example to if I would have enough fuel to come to the next waypoint and so on. So it wouldn`t make sense if I do not have the data down to the minimum of use of fuel from the engine.

However, I will start over again and take out the fuel tank level, for now, just to have more overview and it is better to get one by one working before I start combining everything. The new sensor should arrive may tomorrow so I can test a bit.

I also need to get the heading data out of a Bosch BNO055. This looks complicated for me so I even didn`t try it yet. I bought that sensor once to create a DIY automatic control for the trimtabs. I understood fast to drop that completely for a longer period. :-)
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 24, 2018, 05:40 pm
Engine RPM (EngineParameterRapid)

Will this work?
Based on pulsin()

To the function, I need to convert the input frequency from the engine (one pulse per rpm) to 4 pulses per RPM to be able to use may one year old RPM gauge (gasoline and now I have a diesel engine).

As well shall the data be send through NMEA2k.

The input frequency should be average by 30 readings.
Here is the code:

Code: [Select]
// Demo: NMEA2000 library. Calculate Engine RPM

#include <NMEA2000.h>
#include <N2kMessages.h>
#include <NMEA2000_teensy.h>
#include <FreqMeasure.h>

float frequency;
byte EngineInstance = 0;
byte rpmGaugeOut = 6;
#define RapidDataUpdatePeriod 167
byte freqDivider = 4;
volatile float freqOut;

tNMEA2000_teensy NMEA2000;
// List here messages your device will transmit.
const unsigned long TransmitMessages[] PROGMEM = {127488L, 0};

// *****************************************************************************
void setup() {
  // Set Product information
  NMEA2000.SetProductInformation("000001001", // Manufacturer's Model serial code
                                 101, // Manufacturer's product code
                                 "Engine RPM",  // Manufacturer's Model ID
                                 "1.0.0.0 (2018-08-24)",  // Manufacturer's Software version code
                                 "1.0.0.0 (2018-08-24)" // Manufacturer's Model version
                                );
  // Set device information
  NMEA2000.SetDeviceInformation(000001001, // Unique number. Use e.g. Serial number.
                                140, // Device function=Engine. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                50, // Device class=Engine. See codes on  http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
                                2046 // 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. Comment 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, 23);
  // NMEA2000.SetDebugMode(tNMEA2000::dm_Actisense); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega
  NMEA2000.EnableForward(false); // Comment this, if you want to see bus traffic on your serial.
  NMEA2000.ExtendTransmitMessages(TransmitMessages);
  NMEA2000.Open();

}

// *****************************************************************************
void loop() {
  NMEA2000.ParseMessages();
  SendN2kRapidData();
  FreqCount();
}

void FreqCount() {
  FreqMeasure.begin();
  double sum = 0;
  int count = 0;
  if (FreqMeasure.available()) {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 30) {
      frequency = FreqMeasure.countToFrequency(sum / count);
      freqOut = (frequency / freqDivider);
      sum = 0;
      count = 0;
    }
  }
}

void rpm() {
  unsigned long highTime = ((1000000 / freqOut) / 2); // calculate the time of high level in microseconds
  unsigned long currentTime = micros();
  if (currentTime - (highTime * 2) <= currentTime) {
    digitalWrite(rpmGaugeOut, HIGH);
  }
  else
    digitalWrite(rpmGaugeOut, LOW);
}
void SendN2kRapidData() {
  static unsigned long RapidDataUpdated = millis();
  tN2kMsg N2kMsg;

  if ( RapidDataUpdated + RapidDataUpdatePeriod < millis() ) {
    RapidDataUpdated = millis();
int int_frequency = (int)frequency;
    SetN2kEngineParamRapid(N2kMsg, EngineInstance, int_frequency, N2kDoubleNA, N2kDoubleNA);     //SetN2kEngineParamRapid(N2kMsg, EngineInstance, frequency, EngineBoostPressure, EngineTiltTrim);
    NMEA2000.SendMsg(N2kMsg);
  }
}
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 24, 2018, 06:19 pm
If I read it right, it does not work. On FreqCount() you have double sum; and int count; These are local and will be reset on every new call. Instead you can use
Code: [Select]
static double sum = 0;
 static int count = 0;

Then those will be static inside function. Better would be make own class for measure.

The average may work, but it restarts over after 30 measure. Now if you have max RPM 4000 and you get 4 p/r, you will get 4000 * 4 / 60 = 266 Hz. So you will get 26 p/ (1/10)s, which is RadidDataPeriod. For 1000 RPM you get only 8 p This means that your data is bit late, since you average over 30.

As I mentioned it could be better to make 30 value ring buffer and calculate average over those by every measure. With clever logic you can skip error values and if RPM changes quickly from 800 to 2500, you can reset average ring.

Do not convert frequency to int
Code: [Select]
int int_frequency = (int)frequency; SetN2kEngineParamRapid takes frequency as double in RPM. I think FreqMeasure give it as Hz, which you then need to multiply by 60 to get RPM.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 25, 2018, 10:27 am
If I read it right, it does not work. On FreqCount() you have double sum; and int count; These are local and will be reset on every new call. Instead you can use
Code: [Select]
static double sum = 0;
 static int count = 0;

Then those will be static inside function. Better would be make own class for measure.

The average may work, but it restarts over after 30 measure. Now if you have max RPM 4000 and you get 4 p/r, you will get 4000 * 4 / 60 = 266 Hz. So you will get 26 p/ (1/10)s, which is RadidDataPeriod. For 1000 RPM you get only 8 p This means that your data is bit late, since you average over 30.

As I mentioned it could be better to make 30 value ring buffer and calculate average over those by every measure. With clever logic you can skip error values and if RPM changes quickly from 800 to 2500, you can reset average ring.

Do not convert frequency to int
Code: [Select]
int int_frequency = (int)frequency;
 SetN2kEngineParamRapid takes frequency as double in RPM. I think FreqMeasure give it as Hz, which you then need to multiply by 60 to get RPM.
double sum & int count should be global according to the original example. I placed it wrong.
The conversion to int of frequency I did because there is float used for frequency and since floating point rpm is not used in nmea2k for rpm I thought it is better to convert it to int to et the floating point away. Good if not necessary.

About the ring buffer (circular buffer), yes, I did research on that for a couple of days even on youtube but could not find a good example which I could adapt to this I need. I think as well this would be the best solution, I just don`t know how?!

about the rapid data period, I just didn`t think so far and copied this from one of your examples thinking this is a static value and can not be changed.
Quote
Now if you have max RPM 4000 and you get 4 p/r, you will get 4000 * 4 / 60 = 266 Hz.
The 266 Hz is "just" the frequency I need to output to get the result shown on the external gauge.
So for the NMEA2K sending the 1p/RPM is relevant as the engine delivers 1p per RPM. So this will be then about 16,67 Hz. how many readings of the frequency shall I now take per second, at 600RPM (expected minimum) 10 times as 600rpm are 10 Hz?

I have found now a ring buffer library which I understand and can use for this project.

This is an overview of the period times and the frequency:

RPM Frequency PeriodTime
600 10,00 Hz 100000 µs
1000 16,67 Hz 60000 µs
2000 33,33 Hz 30000 µs
3000 50,00 Hz 20000 µs
4000 66,67 Hz 15000 µs
5000 83,33 Hz 12000 µs
6000 100,00 Hz 10000 µs


I will start over again, i stopped counting how often now! :-)

THX for all your time Timo!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 25, 2018, 03:13 pm
Since FreqCount is one function calculating frequency, it is best to keep variables as its own. So leave them inside function:
 static double sum = 0;
 static int count = 0;


Then I do not understand your meaning "So for the NMEA2K sending the 1p/RPM is relevant..". RPM is value for revolutions per minute. And NMEA 2000 library takes double for RPM. NMEA 2000 has internally 0.25 RPM accuracy. So you can provide double. If youconvert it int, then compiler will do internally new conversion from int to double anyway, since function parameter has been defined to be double. And you should not provide values in Hz. As function description on N2kMessages.h says: EngineSpeed           RPM (Revolutions Per Minute). So if you like to show 1200 RPM on MDF gauge, you have to provide value 1200.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 25, 2018, 06:21 pm
Since FreqCount is one function calculating frequency, it is best to keep variables as its own. So leave them inside function:
 static double sum = 0;
 static int count = 0;


Then I do not understand your meaning "So for the NMEA2K sending the 1p/RPM is relevant..". RPM is value for revolutions per minute. And NMEA 2000 library takes double for RPM. NMEA 2000 has internally 0.25 RPM accuracy. So you can provide double. If youconvert it int, then compiler will do internally new conversion from int to double anyway, since function parameter has been defined to be double. And you should not provide values in Hz. As function description on N2kMessages.h says: EngineSpeed           RPM (Revolutions Per Minute). So if you like to show 1200 RPM on MDF gauge, you have to provide value 1200.

Quote
Then I do not understand your meaning "So for the NMEA2K sending the 1p/RPM is relevant..". RPM is value for revolutions per minute. And NMEA 2000 library takes double for RPM. NMEA 2000 has internally 0.25 RPM accuracy.
I do multiply the rpm by 4 dou to the external analog gauge I have. That one needs 4 pulses per RPM. That`s why I said "for NMEA2K is 1p/RPM relevant", not the multiplied by 4 value.

I used now another Arduino UNO to simulate the pulses. It is generating a PWM between 10 Hz and 100 Hz.
I get values shown with the ring buffer, but not the right one. Also, there is a huge delay between the frequency change of the input and the result getting shown from this code with ring buffer.

Can this be due to the 50% cycle why the result is completely different from the input signal? I will test all that out practically now and hopefully come to a usable result. Ring Buffer (circular buffer library) I do understand now and could use it. Wasn`t that complicated after I tried it practically.
Title: Re: NMEA 2000 Shield
Post by: keith-i on Aug 26, 2018, 10:00 pm
Hi Timo

I would appreciate a little bit of guidance please.

I am trying to set up a single Teensy 3.2 (on an SK-Pang canbus breakout board) to read two different temperatures from my engine room and put the data onto the N2K newtork. One sensor is a onewire DS18B20, the other is a themocouple on a Max 31855. Individually I can get them both to compile and work, but I am struggling to combine them both into one piece of Arduino code. When compiling I get an error message at the start of void loop:
 
Quote
'SendN2kTemperature' was not declared in this scope
Here is my code:

Code: [Select]
// NMEA2000 Send temperature to the N2K bus using onewore and thermocouple.

#include <Arduino.h>
#include <NMEA2000_CAN.h>  // This will automatically choose right CAN library and create suitable NMEA2000 object
#include <N2kMessages.h>
#include <NMEA2000_teensy.h>
#include <SPI.h>
#include "Adafruit_MAX31855.h"
#include <OneWire.h>
#include <DallasTemperature.h>

// Create a thermocouple instance with hardware SPI on a given CS pin.
#define MAXCS   10
Adafruit_MAX31855 thermocouple(MAXCS);

// Create a one-wire connection on a given pin
#define ONE_WIRE_BUS 9  //Sets pin 9 for data
OneWire oneWire(ONE_WIRE_BUS);  //set up instance
DallasTemperature sensors(&oneWire);  //pass onewire ref to dallas

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

void setup() {
 
  //delay(5000);
  // Set Product information
  NMEA2000.SetProductInformation("000200", // Manufacturer's Model serial code
                                 100, // Manufacturer's product code
                                 "Arduino ER temp",  // Manufacturer's Model ID
                                 "1.1 (2018)",  // Manufacturer's Software version code
                                 "1.A (2018)" // Manufacturer's Model version
                                 );
  // Det device information
  NMEA2000.SetDeviceInformation(202020, // 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
                                2046 // 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.
 
  //NMEA2000.SetForwardOwnMessages(); //was in 2016 example but not 2018 so now commented out

  // If you also want to see all traffic on the bus use N2km_ListenAndNode instead of N2km_NodeOnly below
  NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly,22);
 
  //NMEA2000.SetDebugMode(tNMEA2000::dm_Actisense); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega
  NMEA2000.EnableForward(false); // Disable all forward messaging to USB (=Serial)
 
  NMEA2000.ExtendTransmitMessages(TransmitMessages);
  NMEA2000.Open();

  sensors.begin();   //Dallas/onewire command
}


void loop() {
  SendN2kTemperature();
  NMEA2000.ParseMessages();
}
 
double ReadDriveTemp() { //N2K command
  return CToKelvin(thermocouple.readCelsius());   //N2K command incorporating Max31855 temp(c)

double ReadEngRmTemp() { //N2K command
  return CToKelvin(sensors.getTempCByIndex(0));   //N2K command incorporating onewire sensors command
}

#define TempUpdatePeriod 3000

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

  if ( TempUpdated+TempUpdatePeriod<millis() ) {
    TempUpdated=millis();
    SetN2kTemperature(N2kMsg, 1, 1, N2kts_EngineRoomTemperature, ReadDriveTemp());
    NMEA2000.SendMsg(N2kMsg);
    SetN2kEnvironmentalParameters(N2kMsg, 1, N2kts_EngineRoomTemperature, ReadDriveTemp());
    NMEA2000.SendMsg(N2kMsg);
   
    //SetN2kTemperature(N2kMsg, 1, 2, N2kts_EngineRoomTemperature, ReadEngRmTemp());
    //NMEA2000.SendMsg(N2kMsg);
    SetN2kEnvironmentalParameters(N2kMsg, 1, N2kts_EngineRoomTemperature, ReadEngRmTemp());
    NMEA2000.SendMsg(N2kMsg);
    // Serial.print(millis()); Serial.println(", Temperature send ready");
       
  }
}


Presumably I also somehow need to create two instances for the engine room temps. Might this also be the cause of the compile error?
Thanks, Keith
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 27, 2018, 08:00 am
You have missing } on function ReadDriveTemp:
Code: [Select]
double ReadDriveTemp() { //N2K command
  return CToKelvin(thermocouple.readCelsius());   //N2K command incorporating Max31855 temp(c)
} // <--- this is missing

double ReadEngRmTemp() { //N2K command
...
Title: Re: NMEA 2000 Shield
Post by: keith-i on Aug 27, 2018, 02:09 pm
Thank you Timo. Sorry for asking such a basic question!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 27, 2018, 02:34 pm
Missing wrong positioned } or ; causes sometime very strange errors. This is example, that when everyhing seems right, you have to start comparing {} pairs.
Title: Re: NMEA 2000 Shield
Post by: keith-i on Aug 27, 2018, 08:00 pm
I'd like to understand whether I've got the loop part of my code correct. I've used the temperature example and tried to adjust it to suit my device; the difference being that my second temperature is not an 'outside' environmental parameter, it is another engine room temperature just from a different sensor.

What I don't quite understand is how the network will 'see' the two temperatures. Could you explain what the first and second lines of code below do.

Do I need to change the second parameter in the final line of code from a '1' to '2' to imply a second instance? Or how else will the MFD know to show two different temperatures?

Code: [Select]
SetN2kTemperature(N2kMsg, 1, 1, N2kts_EngineRoomTemperature, ReadDriveTemp());
    NMEA2000.SendMsg(N2kMsg);
   
    SetN2kEnvironmentalParameters(N2kMsg, 1, N2kts_EngineRoomTemperature, ReadDriveTemp());
    NMEA2000.SendMsg(N2kMsg);
   
    SetN2kEnvironmentalParameters(N2kMsg, 1, N2kts_EngineRoomTemperature, ReadEngRmTemp());
    NMEA2000.SendMsg(N2kMsg);


Thanks again.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 27, 2018, 08:52 pm
It can not. SetN2kEnvironmentalParameters = SetN2kPGN130311, which is obsolete PGN. Better is SetN2kTemperature = SetN2kPGN130312. It has instance parameter TempInstance, which you can set different. Unfortunately PGN 130312 is also obsolete. The newest one is SetN2kTemperatureExt = SetN2kPGN130316. Unfortunately that is supported only on new MFD:s, so you may anyway need to use SetN2kTemperature. In example I just send different PGNs for testing. In real solutions I use either SetN2kTemperature or SetN2kTemperatureExt depending od MFD support.

If your device sends several temperatures, it is important to have different instance number for each of them even they have different TempSource. So if you send 2 engine room temperatures and one cabing, you have to use
    SetN2kTemperature(N2kMsg, 1, 1, N2kts_EngineRoomTemperature, ReadDriveTemp());
    NMEA2000.SendMsg(N2kMsg);
   
    SetN2kTemperature(N2kMsg, 1, 2, N2kts_EngineRoomTemperature, ReadEngRmTemp());
    NMEA2000.SendMsg(N2kMsg);
   
    SetN2kTemperature(N2kMsg, 1, 3, N2kts_MainCabinTemperature, ReadCabinTemp());
    NMEA2000.SendMsg(N2kMsg);
Title: Re: NMEA 2000 Shield
Post by: keith-i on Aug 27, 2018, 11:38 pm
Brilliant, thanks so much for explaining. I think I'm starting to get the hang of it now.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 29, 2018, 01:27 pm
Hei Timo,

Damn Fuel rate...
I just realized that my engine has to fuel pipes one for delivery and a return line. If I really want to measure the fuel rate than I would need to subtract the returning fuel from the delivering value.

Getting expensive now since the new flow rate sensor costs already 100 €.

Have you been in this scenario before? What flow sensor are you using?

Regards!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Aug 29, 2018, 06:01 pm
I wrote you earlier that I have two sensors. And unfortunately good sensors are expensive. Mine costs about 100 € each. Also you may have same problem with pulsating diesel pump, which causes that dies flow is not static. I also mentioned that and to prevent that problem you will need dampers to both line - exmple link was somewhere.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 30, 2018, 11:19 am
I wrote you earlier that I have two sensors. And unfortunately good sensors are expensive. Mine costs about 100 € each. Also you may have same problem with pulsating diesel pump, which causes that dies flow is not static. I also mentioned that and to prevent that problem you will need dampers to both line - exmple link was somewhere.
Hey Timo,

I know that you wrote that and I am aware of this details. My question was which sensors you are using.
I just forgot that I have a return line. I am still not in that state to test the stuff inside my boat.

Regards..
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Aug 31, 2018, 02:57 pm
NMEA0183 -> NMEA2K & Teensy 3.2 & Linx GM gps module

I order to translate the 0183 messages of an GPS module I tried this library.

I tested the module with the Adafruit library on Serial3 (pin 7 & 8 on Teensy 3.2), I have uncommented to show in clear type and I uncommented NMEA200EnableForward(false).

The handlers are still like default   InitNMEA0183Handlers(&NMEA2000, &BoatData);
  NMEA0183_3.SetMsgHandler(HandleNMEA0183Msg);

the baudrate of the gps module is correct (9600) update every second.

I do see anything in the serial monitor.

What is missing to get the gps and heading data into NMEA2K?

Sorry if this is again a stupid question...
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 01, 2018, 08:09 am
I have tested that only with NMEA0183 from port 3 -> NMEA2000 bus converter. So as default it does not send anything to USB.

After Serial.begin(115200); you must have NMEA2000.SetForwardStream(&Serial); to define where forwarded messages will be send. Then do not uncomment NMEA200EnableForward(false); since that tells library not to forward anything to forward stream.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 01, 2018, 09:36 am
Ok I thought that forward(false) ignores that there is no BUS available. I`ll try.
Title: Re: NMEA 2000 Shield
Post by: jsholovitz on Sep 03, 2018, 03:40 pm
I have a question that I hope you can help with.

Let me first describe my hardware:


My overall setup is using the Arduino to receive messages from the N2K bus.

The results I'm seeing are not as expected. The following 3 screen captures all had about 5 minutes of running the application to collect data before each:

When I use the sketch ActisenseListener, I see all of the PGNs that I think should be there:

(https://photos.smugmug.com/Other/Misc-photos/i-WrS8SzN/0/aacd1c1e/O/Screen%201%20ActisenseListener.jpg)

When using the ActisenseListenerSender sketch, I see fewer PGNs - for example, the AIS Class A data is missing:
(https://photos.smugmug.com/Other/Misc-photos/i-36WbGjT/0/093cac59/O/Screen%202%20ActisenseListenerSender.jpg)

And when using the ArduinoGateway sketch, all of the AIS data is now missing:
(https://photos.smugmug.com/Other/Misc-photos/i-Q87Nrxj/0/702a151e/O/Screen%203%20ArduinoGateway.jpg)

Thoughts? Help, please!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 04, 2018, 06:46 am
No good ideas. They all have small differences. Message forwarding uses same method on all.
- ActisenseListener just listens and forward messages.
- ActisenseListenerSender also polls serial. This could somehow disturb, but should not.
- ArduinoGateway does same as ActisenseListenerSender, but also shows itself on the bus. After it has done address claiming, it does not send much to the bus. There will be only time to time requests from other devices.

With 5 min period you should see all messages anyway. Any slowdown caused by extra polling of other serial is random and should not effect with that long period.

Some questions:
- Which version of Actisense Reader you run the tests?
- Did you close and restart NMEA Reader between each test?
- Do you have other system like Teensy for making same test?
- Can you make same test by feeding Due bus with other device and with NMEA Simulator?
Title: Re: NMEA 2000 Shield
Post by: jsholovitz on Sep 04, 2018, 03:55 pm
Thanks, Timo

Here are a few responses:


Some questions:
- Which version of Actisense Reader you run the tests? I'm using 1.5.1.7. I did see the same situation when feeding the data from the Arduino directly to my Raspberry Pi into OpenPlotter / Signal K server.
- Did you close and restart NMEA Reader between each test? Yes
- Do you have other system like Teensy for making same test? No, I think that's my next step to make a Teensy device. Need to order many parts for that.
- Can you make same test by feeding Due bus with other device and with NMEA Simulator? As above


Any other thoughts? Thanks!
Title: Re: NMEA 2000 Shield
Post by: popeye_70 on Sep 09, 2018, 07:15 pm
Hi all,
anyone tried this actisenselistnersender to connect and program the Actisense EMU-1 interface? Like a true NGT-1 cable?
Thanks
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 10, 2018, 06:22 am
Actisense NGT-1 has special messages e.g. for configuring it. I think Actisense configuration tool may require right response from NGT-1 before it continues. ActisenseListenerSender transfers only NMEA 2000 messages in Actisense format and does not respond to any Actisense NGT-1 specifig messages. So it may be that it will not work.
Title: Re: NMEA 2000 Shield
Post by: pronaga on Sep 13, 2018, 12:42 pm
Hi Timo,

I am a beginner in Arduino programming!

I would like to send fuel rate in the nmea 2000 bus.
As a first step I modified your sketch" temperature monitor" to read the fuel rate with Actisense NMEA Reader, but  tells me error to the SetN2kEngineDynamicParam line "fuelRate was not declared in this scope"

This is the sketch. Can you help me! Thank you!

// Demo: NMEA2000 library. Send fuel rate data to the bus.

#include <Arduino.h>
#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={127489L,0};

void setup() {
 // Set Product information
 NMEA2000.SetProductInformation("00000002", // Manufacturer's Model serial code
                                100, // Manufacturer's product code
                                "Simple fuel rate  monitor",  // Manufacturer's Model ID
                                "1.1.0.22 (2016-12-31)",  // Manufacturer's Software version code
                                "1.1.0.0 (2016-12-31)" // Manufacturer's Model version
                                );
 // Set device information
 NMEA2000.SetDeviceInformation(1, // Unique number. Use e.g. Serial number.
                               160, // Device function=FLOW. 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
                               2046 // 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,23);
 NMEA2000.SetDebugMode(tNMEA2000::dm_Actisense); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega
 //NMEA2000.EnableForward(false);
 NMEA2000.ExtendTransmitMessages(TransmitMessages);
 NMEA2000.Open();
}


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

double ReadFuelRate() {
 return 30; // Read here the measured flowrate e.g. from analog input
}

#define FuelRateUpdatePeriod 1000

void SendN2kFuelRate() {
 static unsigned long FuelRateUpdated = millis();
 tN2kMsg N2kMsg;

 if ( FuelRateUpdated + FuelRateUpdatePeriod < millis() ) {
SetN2kEngineDynamicParam(N2kMsg,0,N2kDoubleNA,N2kDoubleNA,N2kDoubleNA,N2kDoubleNA,FuelRate,N2kDoubleNA);

NMEA2000.SendMsg(N2kMsg);
   FuelRateUpdated = millis();
   NMEA2000.SendMsg(N2kMsg);
    }
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 13, 2018, 06:12 pm
Hi,

Have you used some other languages than C++?

This is normal for undefined variables - in this case FuelRate. C++ is strict language and requires that everything you use must be defined. Note that it is also case sensitive. E.g. Visual Basic does not require that all variables should have been defined (e.g. with Option Explicit).

So instead using undefined FuelRate in call use
SetN2kEngineDynamicParam(N2kMsg,0,N2kDoubleNA,N2kDoubleNA,N2kDoubleNA,N2kDoubleNA,ReadFuelRate(),N2kDoubleNA);

Note also that you call NMEA2000.SendMsg(N2kMsg); unnecessarily twice at the end. It just sends same message twice with very short period, which is not good.

You have no chosen the easiest task. If you read previous posts, you should find some information what problems you will have with measuring fuel rate. Fuel rate reading may have a lot of noise and variation, which you should filter with averaging or with low pass filter.
Title: Re: NMEA 2000 Shield
Post by: pronaga on Sep 14, 2018, 08:27 am
thanks for the reply!
You are always friendly and helpful!
At the moment I just want to read the fixed value "30" on actisence reader!
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 14, 2018, 04:34 pm
Hello Timo,

just a short question regarding CANbus using Teensy 3.2. I need to use CANBus1 instead.
Can I force to use can0 by this?

#define CANbus Can1


The NMEA2000_teensy is written for teensy 3.1&3.2 right?!
I would like to use a teensy 3.5, will this work or is it necessary to make huge changes to the NMEA200_teensy?

Thank you!
Regards..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 14, 2018, 04:54 pm
Teensy 3.2 has only 1 CAN bus, so you can not use Can1. Only Teensy 3.6 has 2 CAN busses. Currently there is no definition on NMEA2000_CAN.h for selecting secondary CAN bus. You can use it anyway, if you force to use NMEA2000_teensy. So instead of having

#include <NMEA2000_CAN.h>

you use

#include <N2kMsg.h>
#include <NMEA2000.h>
#include <NMEA2000_teensy.h>

...

tNMEA2000 &NMEA2000=*(new tNMEA2000_teensy(4,1));


Library works fine with Teensy 3.2 ... 3.6

Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 14, 2018, 06:27 pm
Of course, you are right with that there is just one can bus... damn. It was I2C I was looking at.

regarding the #define CANbus Can1, this is defined in the NMEA2000_teensy.h file. At least there I found this part which has brought me to this idea.
I also thought that it is necessary to use the NMEA2000_teens.h instead of the NMEA2000_can so I used it all the time?!

But if the 3.5, which I have here as well, have the can bus at other pins or more than one canbus everything is fine.

I bought the 3.5 once to have the card slot already integrated since I wanted to add some engine and tour logging. But from this plans, I am still far away..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 14, 2018, 07:54 pm
I could not found any #define CANbus Can1 on any NMEA2000_teensy file. Where you have copied those files? I prefer to use files under my git to ensure compatibility.

You have to study how to change to alternate pins for CAN on Teensy 3.5. Again 3.5 has only one CAN and 3.6 has two can.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 15, 2018, 10:21 am
It is a part of the NMEA2000_teensy.cpp. There this is defined:
Code: [Select]
#if NMEA2000_TEENSY_VER == 1 
  CANbus = new FlexCAN(250000);
#else
 
#if NMEA2000_TEENSY_MAX_CAN_BUSSES == 2 && NMEA2000_TEENSY_VER>1
  if ( CANBusIndex>1 ) CANBusIndex=1;
  if ( CANBusIndex==0 ) {
    CANbus = &Can0;
  } else {
    CANbus = &Can1;
  }
#else
  (void)CANBusIndex; // just avoid warning
  CANbus = &Can0;
#endif

#endif
  DefTimeOut=_DefTimeOut;
}


This doesn`t say that it is changeable between can1 & can2 but I thought it could be a hint that it is possible. If I understand that right than it is about the 3.2 version.

I think this file is from your repo. I usually just use your files.

All this is because I wanted to use the freqMeasure library for rpm. There the input pin is fixed to pin 3.

The rpm thing is really annoying... One of the last thing I just do not get any working solution done.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 15, 2018, 06:15 pm
Regarding engine torque (PGN 127489 EngineTorque), this is part of engine dynamic parameters. Since this is calculated from EngineSpeed (PGN 127488 EngineSpeed) and the airflow into the engine, shouldn´t this be part of Engine parameters rapid (PGN 127488) instead of Engine parameters dynamic?

Just a thought..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 15, 2018, 06:21 pm
You select CAN bus on contructor second parameter - not with any define. And As I mentioned, only Teensy 3.6 has two CAN bus.

For RMP you could use FreqMeasureMulti library, which is on Teensy framework. See. https://github.com/PaulStoffregen/FreqMeasureMulti It supports pins 5, 6, 9, 10, 20, 21, 22, 23 for Teensy 3.1-3.6 as in readme.

For frequency you need to use lowpass filter with very high filtering, which depends of scaling. I have scaling 1/11 from my altenator W and I get reasonably steady readings with FilterWeight 0.005. Note that with too small FilterWeight RMP gets very slow.

I have not tested code below, but it should work if you fill other necessary code for ...

Code: [Select]

#include "FreqMeasureMulti.h"

class tFilteredRPM {
protected:
  double Frequency;
  double FilterWeight;
  double Scale;
  uint32_t Pin;
  bool Started;
  FreqMeasureMulti FreqMeasure;
public:
  tFilteredRPM(uint32_t _Pin, double _FilterWeight, double _Scale=1) :
    Frequency(-1), FilterWeight(_FilterWeight), Scale(_Scale), Pin(_Pin), Started(false) {}
    
  // Call this in loop as often as possible
  void Update() {
    if ( Started ) {
      if ( FreqMeasure.available() ) {
        if ( Frequency<0 ) { // Reset at first read
          Frequency=FreqMeasure.read();
        } else {
          Frequency = (FilterWeight * FreqMeasure.read() + (1 - FilterWeight) * Frequency );
        }
        while ( FreqMeasure.available() ) {
          Frequency = (FilterWeight * FreqMeasure.read() + (1 - FilterWeight) * Frequency );
        }
      }
    } else {
      FreqMeasure.begin(Pin);
      Started=true;
    }
  }

  // Call this to read current RPM
  double Read() const {
    double RPM=0;
    if ( Frequency>=0 ) RPM=FreqMeasureMulti::countToFrequency(Frequency)*60*Scale;
    return RPM;
  }
};

tFilteredRPM RPM(22,0.005,1.0/11.0);

void setup() {
...
}

#define RPMSendPeriod 100

void SendRPM() {
  static unsigned long NextRPMSendTime=millis()+RPMSendPeriod;
  if ( NextRPMSendTime<millis() {
    NextRPMSendTime+=RPMSendPeriod;
    ... RPM.Read()...
  }
}

void loop() {
  ...
  RPM.Update();
  SendRPM();
  ...
}
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 15, 2018, 06:24 pm
...shouldn´t this be part of Engine parameters rapid (PGN 127488) instead of Engine parameters dynamic?

Just a thought..
Do not think too much what NMEA organization has been desided. NMEA2000 content is their thoughts and not allways logic.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 17, 2018, 07:30 pm
Thank you Timo!

If I write that something is defined doesn't mean the command #define, this just to clarify.

I`ll try to get that code running. Some things from this sketch I have never seen before like this "public:" & "protected". But I will figure that out I guess! The filtering thing looks also like a new thing for me, special this with FilterWeight. Do you know a place where this method is described since I would like to now how this is working and in which cases I could uses this functionality.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 17, 2018, 07:50 pm
"public:" & "protected" belongs to classes. With classes you can define, which functions or properties are public so that they can be called outside from class. And which are just for internal or inherited use.

The filter method works with many noise data. I use it also for analog. FilterWeight depends of incoming data noice and speed. I use a bit different class and wrote that for example, but it does the main thing - low pass filtering.

See. e.g. https://kiritchatterjee.wordpress.com/2014/11/10/a-simple-digital-low-pass-filter-in-c/
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 19, 2018, 12:05 pm
"public:" & "protected" belongs to classes. With classes you can define, which functions or properties are public so that they can be called outside from class. And which are just for internal or inherited use.

The filter method works with many noise data. I use it also for analog. FilterWeight depends of incoming data noice and speed. I use a bit different class and wrote that for example, but it does the main thing - low pass filtering.

See. e.g. https://kiritchatterjee.wordpress.com/2014/11/10/a-simple-digital-low-pass-filter-in-c/
Very, very good! Thank you, this pushes me a lot forward! I have looked for months now for the different filtering types but haven´t seen this site yet.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 21, 2018, 01:18 pm
Schematic question regarding resistive sensor in automotive (delivering current instead).

Almost every engine I know has the sensors connected to ground on one side and the other side to the gauges. This gives an voltage divider ( + gauge -> sensor -> ground).

There are very many solutions out there how to connect this to the Arduino.
What is the best practice here if I don't want or can't measure each resistive working area of the sensors?

Another thing, I could stabilize the supply voltage to the sensors by putting an LDO in series to the power supply of the gauges since the supply voltage varies from 12 to 14,2 volt. This is a variation of approx 15% and if I think about the fuel level sensor 15% is a lot in my 300L tank.

What is the best practice for this both questions?
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Sep 21, 2018, 01:36 pm
i have a similar issue (albeit my engines/guages are 24V)
and whilst mine seems to be better regulated, there is still some variation in the "positive rail" of the guage - voltage divider - ground.

aside from your suggestion of using a regulated supply to the guages,
one idea I had was to use a second analog input on the arduino to read the "positive rail" voltage
(once again using a voltage divider) - however in this case the voltage divider is fixed, and the
rail voltage changes (a little) .. thus at any given time the arduino knows the actual positive rail voltage and you can then appropriately compensate this in your computation for
measuring the "unknown" voltage divider input.

hopefully my explanation is clear ..
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 21, 2018, 02:06 pm
i have a similar issue (albeit my engines/guages are 24V)
and whilst mine seems to be better regulated, there is still some variation in the "positive rail" of the guage - voltage divider - ground.

aside from your suggestion of using a regulated supply to the guages,
one idea I had was to use a second analog input on the arduino to read the "positive rail" voltage
(once again using a voltage divider) - however in this case the voltage divider is fixed, and the
rail voltage changes (a little) .. thus at any given time the arduino knows the actual positive rail voltage and you can then appropriately compensate this in your computation for
measuring the "unknown" voltage divider input.

hopefully my explanation is clear ..
Now based on your idea I remember that I anyway measure the system voltage! There I have then the reference of course!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 21, 2018, 03:10 pm
There are several errors in system.
- reference voltage
- noise from sensors to measuring system
- measuring system own noice

So I am bit afraid that if you measure system voltage as own input and then sensor value, you may have noice between measurements and you do not actually get exact measure time difference. If required accuracy is not high, it should give reasonable values.

If it is poosible, I would rather stabilize sensor voltage first. If engine own gauges does not have any differential correction, also them would be stabilized.

For resistive measurement I do not know good way, if you do not know the range of measured sensor. That would require some auto-range system. It is far more easier to measure somehow the range and use suitable constant current source or voltage source+divider resistor. E.g. for tank sensor 30-240 ohm I simply use 3.3 V regulator and 330 resistor. Then I will get range appr. 1.4 - 0.3 V to input.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 21, 2018, 03:31 pm
Hey Timo,

I had the plan to measure the system voltage, by that the charging voltage so I can display it as well.
Currently, I am reading and learning about Aref but I am not sure how that can help with the moving supply voltage for the sensors.
The thing is that the existing gauges should, of course, still be functional. So I thought I could grab the values from the gauges and use them with the Teensy. But I didn't think about that almost all sensor is grounded on one side. This is destroying my whole plan of course.

So if I see the oil pressure sensor for example connected to the gauge as voltage divider then I could grab the voltage supplied to the sensor and break it down with another voltage divider connected to the ground where the middle point connection should give the x - 3.3 V for the teensy.

Regarding using the measured system voltage to use as reference I meant that I could calculate the difference between current system voltage and the 12 V basic voltage of the batteries in %. In max it would be than ~17% (difference between 12 and 14,5 volt). So if the system voltage is currently 14.5 V I could subtract 17% from the measured value before I send it out to the NME2K bus.

This would not fix the problem with lost resolution but I think the resolution is still good enough without working with aref.

This all is just what I think what could work, I am not sure about this is the correct way or that it even would work!

Another thought I had was to use the teensy to power the gauges. By that, I get always shown the correct values on both, MFD and the gauges since the supply voltage is stabilized for the sensors.
This is an old Volvo Penta AQAD40B engine (1986), there are now intelligent sensors at all which correct themselves I guess.
El schema from engine attached.
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Sep 21, 2018, 04:17 pm
one thing to be careful of when using a "further voltage divider" to reduce the voltage from existing guage & sensor network.
the additional voltage divider across the sensor adds some additional resistance in the lower leg
of the "guage voltage divider".
so ideally you want to keep the overall resistance of the voltage divider high,
however there are practical limits given the input impedance of the arduino analog IO .
(i read somewhere that the voltage divider should not be higher than 10k (need to confirm this).

and hence with 10k across a typical tank guage sender unit, it does impact the reading a little.
i did some measurements on my guages (VDO fuel and water ... with resistive sender units.. eg 0-180ohm) and the additinal voltage divider adds a few % error ... not enough to detect
on the analog guage ... but if you plan to keep existing guage - you need to ensure
that you calibrate AFTER adding the extra voltage divider
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 21, 2018, 04:25 pm
one thing to be careful of when using a "further voltage divider" to reduce the voltage from existing guage & sensor network.
the additional voltage divider across the sensor adds some additional resistance in the lower leg
of the "guage voltage divider".
so ideally you want to keep the overall resistance of the voltage divider high,
however there are practical limits given the input impedance of the arduino analog IO .
(i read somewhere that the voltage divider should not be higher than 10k (need to confirm this).

and hence with 10k across a typical tank guage sender unit, it does impact the reading a little.
i did some measurements on my guages (VDO fuel and water ... with resistive sender units.. eg 0-180ohm) and the additinal voltage divider adds a few % error ... not enough to detect
on the analog guage ... but if you plan to keep existing guage - you need to ensure
that you calibrate AFTER adding the extra voltage divider
The tank sensor has about max 200 ohm (180 nominal) the others are in the same range. I have an overview from Faria where all this are written down. So if I use the dividers in KOhm area it should not be any problem or causing high error values. Thought to use 9.1K & 24K. This is a lot comparing to the 650 Ohm total the fuel sensor/gauge have. On the gauges, even they are high quality expensive once, there is nothing to adjust, unfortunately. BUT, If this really matter and an error is recognizable than a resistor in parallel to the gauge can compensate I guess.
Title: Re: NMEA 2000 Shield
Post by: sunnycoastgreg on Sep 21, 2018, 04:38 pm
i was chasing accuracy in fuel tank measurement (I have 2 large tanks that are coupled together)
with only one sender... and a few % is a LOT of litres in my case :)
however i quickly realised that the resistive sender unit appears to have quantisation (it doesnt appear to be
a continuous resistance?) .. so given all the errors (inc those mentioned by timo)
and also the effect of boat movement etc ... i realised that a 20 step readout
(ie showing fuel level in 5% increments was the best i could expect ... and realistically
the overall accuracy is probably worse than 5%)

remember that the additional voltage divider you add (is not across the 650ohm ... its across the
voltage output from the sender unit (the lower leg of the voltage divider formed by sender unit( 0-180)
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 21, 2018, 05:47 pm
i was chasing accuracy in fuel tank measurement (I have 2 large tanks that are coupled together)
with only one sender... and a few % is a LOT of litres in my case :)
however i quickly realised that the resistive sender unit appears to have quantisation (it doesnt appear to be
a continuous resistance?) .. so given all the errors (inc those mentioned by timo)
and also the effect of boat movement etc ... i realised that a 20 step readout
(ie showing fuel level in 5% increments was the best i could expect ... and realistically
the overall accuracy is probably worse than 5%)

remember that the additional voltage divider you add (is not across the 650ohm ... its across the
voltage output from the sender unit (the lower leg of the voltage divider formed by sender unit( 0-180)
It depends on what type of fuel level sens it is. The "old good" once where linear 100% resistive sensors. The newer type today is some kind of a pipe with metal or magnetic sensitive switches in series inside. In my case, I have 8 switching points where resistance is added or subtracted depending on position.

With 650 ohms the hole circuit is meant. If I go out from the 180 ohms of the sensor now the additional voltage divider in parallel do not affect the shown value of the gauge at all (180 ohms sensor to 33.1 KOhms voltage divider). If I calculated right this is an error in microAmp. Sensor and gauge together while the sensor have in 180-ohm max. This is values from the datasheet of the gauges/fabricant (Faria Beede).

The movement of the boat has to be compensated by smoothing the measurements.
But there are also other sensors for fuel available, "radar" based once. They are very expensive but deliver a more linear result. But I do not think this is worth the money.

I guess using the digital solution now is much more accurate than the gauges ever have been.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 23, 2018, 02:56 pm
Hey,

I thought to use the RTC of the Teensy 3.5 to count the Engine running seconds and save them to sd. I know there are a ton of threads regarding counting engine running hours, but this all looks so complicated.

As trigger to set the start point I thought to use the rpm (if >=300). How to save the elapsed seconds to sd or EEPROM I have figured out.

Another option I thought can be to use millis to count the seconds and save them to SD every 5 minutes by reading the last saved seconds and add them to the counted seconds and write it back to file.
5 minutes instead of 15 minutes interval I think makes sense since if the power is lost due to the stopped engine I lose too many minutes and the counted time gets to inaccurate.

I use the Teensy 3.5 for all the engine rapid and engine dynamic data (not tested yet live)
I am not sure how the writing to card process will affect the rest of the program. I hope it does not stop the whole process until save to sd is finished?

Any better Idea, does this makes sense?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 23, 2018, 08:07 pm
EEPROM has been guaranteed to work with 100000 write cycles. If you save rarely enough, it is not problem. With 5 s priod you will reach that less than week.

If you have battery on Teensy, you can use VBAT registers.
Code: [Select]
struct tNvRamData {
   uint32_t EngineRunTime;  // Seconds
};

#define NVRAM_BASE 0x4003E000

tNvRamData *pNvRamData=(tNvRamData *)(NVRAM_BASE);
...
  pNvRamData->EngineRunTime+=...;
...


tNvRamData has been defined as struct, so you can easily add there more data.

There are totally 32 VBAT registers, but I read somewhere that 0x4003E01C has been used by Teensy code, so there is 28 byte available. This means max. 7 uint32_t.

When you save to SD card, other than interrupts will be stopped.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 24, 2018, 09:27 am
Very good Timo, thx!

Yesterday I was checking the signal of RPM, that was really strange!
According to the documentation, the signal for rpm should come from an explicit sensor and not from the generator. But I got frequencies from 500 hz to over 1 khz ( see picture attached).
I am not sure, is this frequency normal if this signal comes from the generator?
The results are not hundred % correct.
RPM   Hz
1000   520
1100   560
1200   640
1300   690
1400   725
1500   800
2000   1080
2500   1350

See the picture of the oscilloscope at 1000 rpm attached.

So is that normal?
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 25, 2018, 10:29 am
Hey Timo,

I was testing the whole stuff yesterday in the boat. I can't see anything on the MFD at all?
Strange is that I can see all traffic coming from the MFD through the NMEAReader on the teensy.

Do you any hint what could cause that the display does not see the devices at all?

All traffic forwarding is enabled in the config, I tested with enabled serial output and without and forward(false) is commented out.

Regards..
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 25, 2018, 02:14 pm
What mode you have set to library? Should be N2km_ListenAndNode so that it would act as normal bus device.

Forwarding affects only for message forwarding to ForwardStream - normally USB. So even you have frowarding disabled bus communication works normally.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 25, 2018, 02:40 pm
All devices are set to N2km_ListenAndNode .
I checked also the documentation of the Axiom. The PGN's are supported. Engine Instance is set to 0. Can speed I tested the standard 250.000 up to 1.000.000, also lower than 250.000. Now I have all set back to 250.000 as I couldn't find out what the speed of the Axiom is (or if this is auto-sense).
This drives me crazy, all the work and now nothing is working. The device under itself can see each other. Will say the rudder position device can see the engine and visa vi. The strange thing is that I can see the GPS data and all other stuff coming from the axiom on the devices?!
Updated the Axiom also to latest Lighthouse as there where some bugs NMEA2k related in the past.
I remember when I have begun with all this I used an Arduino due, With that and the MCP 2562 I got them connected. I use now the SN65HVD234D with Teensy 3.2 & 3.5. FlexCan and all other libraries like NMEA2000 , NMEA2000_teensy, N2KMessages are included.
Do I have to set something Flexcan related?
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 25, 2018, 03:41 pm
I guess it must have something to do with the SN65HVD234D, even the default sketches like Battery monitor or message sender are shown on the display. But why can the self-made devices see each other then?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 25, 2018, 03:50 pm
NMEA2000 is fixed to 250 kb.

Use FlexCan only from my git and delete the one under Teensy libraries.

Can you receive bus data with same Teensy? If yes, then you have problem with tranceiver.

Why did you changed MCP2562? I have not had any problems with it. Have you connected pin 5 to 3.3V? How did you connect RS pin 8?
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Sep 25, 2018, 05:01 pm
I found out the problem..

It is the SN65HVD234D ! Just not working! I changed to the SN65 because it had some better values like more bandwith, lower power (not that this is prio) and it didn't needed 5V.

The SN65 worked perfectly all in lab, all devices could communicate and everything looked fine. It is a bt more expensive the SN65.

Now I have 16SN65 laying around here without any use.. What do you think what can be the reason, any idea?

The MCP2562 worked now immediately. Again thrown 2 days..
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Sep 30, 2018, 07:53 pm
Hi all,

Some questions to those who might know.

I was reading trough Timos NMEA0183ToN2k.ino. How it is defined where/ in which serial GPS receiver is connected?


Would this be ok receiver to get GPS data to Arduino to be transmitted to NMEA2000: https://www.sparkfun.com/products/13740 ?


If I had two of those would they make a GPS compass when installed 6 m apart from each others? Like in this example:
https://learn.sparkfun.com/tutorials/gps-differential-vector-pointer ?_ga=2.111597508.1910172968.1538324202-1706626596.1503061770

Is there a way to transmit roll and pitch rates in NMEA 2000?  Would it be benefical to use that data to compensate mast head movement in wind measurements? Or is wind data too filtered for that? I have roll and pitch rates on one arduino and have been thinking if I want to buy  wind instruments and make VMG and true wind calculations should those calculations be made at the same arduino where I have the sensor for autopilot.

Is rate of turn supported in Timos work?

What is the unit for speed in NMEA2000? m/s I suppose.






Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Sep 30, 2018, 09:30 pm
On line 67   NMEA0183_3.SetMessageStream(&Serial3);

Check N2kMessages.h SetN2kAttitude

N2kMessages.h should have in function description required unit. Normally they are SI.

If you provide wind data to the bus, it would be best that it would have all conpensations.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 01, 2018, 06:42 am
If I had two of those would they make a GPS compass when installed 6 m apart from each others? Like in this example:
https://learn.sparkfun.com/tutorials/gps-differential-vector-pointer ?_ga=2.111597508.1910172968.1538324202-1706626596.1503061770
I read a bit more about that GPS pointer. I can not say for sure how accurately that would work. With 20 cm error in position on 6 m base you would get about 2 deg. error.

The one problem is that you do not have control to synchronize those receivers. Also they send position data in 1 Hz, which is very slow for making any filtering in moving boat. Real GPS compasses has antennas directly connected to the device, so they can follow satellites fast enough to also filter calculated position information. I have GPS compass with 50 cm antenna separation, but there both antennas are directly connected to the compass unit. That provides <1 deg. accuracy all the time and it sends HDT information to other systems with 10 Hz.

If you would add accurate movement sensor to the system, you could get fast movement infomation from it. Then you could probably have some filtering on both GPS position to calculate better heading. But still the problem would be that when you get position information from GSP, it is allready 1 sec. late.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Oct 01, 2018, 02:05 pm
Hey Timo,

I have some trouble with temperatures. In this case with the coolant temperature.

I measure the value through a voltage divider in parallel to the existing analog gauge.

My Axiom can show Fahrenheit and Celsius. So far so good. I get a value shown on the display of -271 C and according to the messages.h Kelvin is to be sent right?

I could not find out yet what the correct form is, I tried some conversion functions you predefined and they worked fine but still, I can´t figure out what is wrong here.

How do I have to map the temp, is there any definition out there which tells me the temperature range?
What I mean is how do I map the 0-3.3 V. For example from -20 to 150 ?

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 01, 2018, 02:27 pm
That is simple linear conversion:

TempC = -20 + (x-0)*(150- -20)/(3.3-0); // , where x is your voltage.

For library function you have to provide values in Kelvin, so you use
...CToKelvin(TempC)...

Or better would be use SI in code inside and use conversion only for view values. Then your function would be:

TempK = 253.15 + (x-0)*(423.15-253.15)/(3.3-0);

Then you can just pass TempK to library function.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Oct 01, 2018, 04:49 pm
That is simple linear conversion:

TempC = -20 + (x-0)*(150- -20)/(3.3-0); // , where x is your voltage.

For library function you have to provide values in Kelvin, so you use
...CToKelvin(TempC)...

Or better would be use SI in code inside and use conversion only for view values. Then your function would be:

TempK = 253.15 + (x-0)*(423.15-253.15)/(3.3-0);

Then you can just pass TempK to library function.
That looks good so far, just one thing:
It results in a negative value. I get shown -21.7 C and just multiplying it by -1 doesn't work for any reason.

Can this be used for any kind of temp value like oiltemp ?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 01, 2018, 05:50 pm
What shows -21.7 and why it should be multiplied with -1?

If your x is positive, the function returns allways >=-20 C!

Linear scaling works for any kind of sensor, which has linear scale.  E.g. tank sensors have often non linear scale due to irregural tank shape. Then one has to split it several smaller ranges, where linear scaling gives reasonably good result.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Oct 01, 2018, 06:06 pm
What shows -21.7 and why it should be multiplied with -1?

If your x is positive, the function returns allways >=-20 C!

Linear scaling works for any kind of sensor, which has linear scale.  E.g. tank sensors have often non linear scale due to irregural tank shape. Then one has to split it several smaller ranges, where linear scaling gives reasonably good result.
The MFD showed a temp of -21.7 C. The voltage is currently 1.151 V on the analog in. But now the engine is almost warm (~55 C)
In code I use the following:
Code: [Select]
double EngineCoolantTemp = 253.15 + (analogRead(coolantTempPin)-0)*(423.15-253.15)/(3.3-0);


and pass the EngineCoolantTemp through return back. In SendN2kMessagesDynamic I call the function by EngineCoolantTempRead() inside EngineCoolantTempRead() with all the others which have todo with Engine parameter dynamic.

Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 01, 2018, 06:17 pm
analogRead(coolantTempPin) does not return voltage. It return integer value depending of your analog resesolution. So e.g. with 10 bit resolution it will return value 0 - 1023 and for 12 bit resolution 0 - 4095. The resolution depends of device you are using and in some devices you can control it with analogReadResolution() function.

Then you need to scale value from analogRead with range it is using. That depends of analog reference voltage. E.g. on Teensy you can select internal analog reference with analogReference(0) and then it will use 3.3 V ref. In that case you you convert 10 bit analog pin data to voltage with function analogRead(coolantTempPin)/1023*3.3

So check which resolution and reference you have to get right conversion to voltage.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Oct 01, 2018, 06:37 pm
analogRead(coolantTempPin) does not return voltage. It return integer value depending of your analog resesolution. So e.g. with 10 bit resolution it will return value 0 - 1023 and for 12 bit resolution 0 - 4095. The resolution depends of device you are using and in some devices you can control it with analogReadResolution() function.

Then you need to scale value from analogRead with range it is using. That depends of analog reference voltage. E.g. on Teensy you can select internal analog reference with analogReference(0) and then it will use 3.3 V ref. In that case you you convert 10 bit analog pin data to voltage with function analogRead(coolantTempPin)/1023*3.3

So check which resolution and reference you have to get the right conversion to voltage.
That was actually my initial question. How to map the 0-1023 to the coolant temp value. This you wrote here I know about (would be very difficult without i guess)

The point I need to know here is what to do with the 0-1023? Usually, there is a range it can be mapped to like I do with the oil pressure. There I use the custom map function (you showed me once I tried my luck with the rudder position) to 0 - 10000 pascals.

In the example of rudder position, the drive I have and the MFD Axiom shows -50 - 0 + 50 degrees. So I map here the 0-1023 like this rudderposition=(analogRead(rudderPositionPin), 49, 1023, -50, 50).

So in case of temperature, I don't know the range I can map it on. I thought there are somewhere definitions or standards which tells me what to use.
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Oct 01, 2018, 07:20 pm
Hi Timo,

Thanks for the prompt replies. Question of GPS compass has been discussed here:

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

So necessarily it does not work that way. Was not mentioned what kind of base was used.  Anyhow I want to have a GPS to the bus so I will get some receivers. This could be what I will buy:

 https://www.banggood.com/Radiolink-M8N-GPS-Module-UBX-M8030-for-Naze32-APM-CC3D-SP-F3-Naze32-Flip32-PX4-Flight-Controller-p-1051291.html?rmmds=search


It has freq. of 10 Hz.


I have rate of turn measured with a quite good gyro at autopilot. I could feed that to bus and use it on another Arduino to improve dynamics of filtered heading from calculations the same way that I did with roll and pitch calculated from accel signals.


Would it be all wrong if arduino would read GPS-position of the other sensor from bus and other would be connected to serial?
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 01, 2018, 07:34 pm
Please do not quote everything as it is, since it does not make sense, since same can be read on previous post.

Do you mean dMap function example I wrote on post #351? map is just a simple function for making linear scaling I wrote. Arduino map uses long values and dMap doubles.

Anyway in principle you 0-1023 maps finally to your temperature values -20 - 150 C. You can also use direct mapping, if you know that it is right: tempK=dMap(analogRead(coolantTempPin),0,1023,253.15,423.15);
This is naturally fastest way to calculate it, since you do mapping only once. But now, if your reference changes e.g. by providing more accurate external 2.5V reference, you have to remember that then 0-1023 values are within 0 - 2.5 V, which means that 1023 does not map to 423.15 K anymore. So if you know your sensor mapping in voltages and you make it as commonly usable function, you need two mapping.
Code: [Select]

...
const double VRef=3.3;
const double AnalogMax=1023;
...
double ReadAnalogVoltage(int pin) {
  return dMap(analogRead(pin),0,AnalogMax,0,VRef);
}
...
double SensorMxyzToKelvin(double Vin) {
  return dMap(Vin,0,3.3,253.15,423.15);
}
...
double ReadTemp(coolantTempPin) {
  return SensorMxyzToKelvin(ReadAnalogVoltage());
}
...


This makes your code a bit more abstract, understantable and movable, but also unfortunately also slower depending of you processor. Teensy works rather well with double, but Mega lags much.

There is no standards, since sensors has different output. But the mapping range depends of sensor and you may find it from the specifig sensor data sheets.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 01, 2018, 08:02 pm
HeikkiF,

Interesting GPS module. Have you found any data sheets? Does it take 3.3 V or 5 V in? What are cummunication pin levels - TTL? Pin order etc.

As in discussion points, you still will have unsynchronized errors in GPS. I think that can work on land as in laser pointer, since the position can be filtered a lot, when antennas are not moving.

Note also that using single GPS for heading does not give right result. GPS returns your moving direction and compass (GPS, solid state or what ever) returns your heading. Depending of conditions - specially on currents they may differ a lot. So you can not use single GPS for calibrating magnetometer data.

Note also that my example 20 cm error may be far too optimistic. It is possible that two different GPS has 1 meter or even more error in different directions. On the other hand I have not tested accuracy of those and specially two sensor around same position. You can only byu two, put them to e.g. 10 m away of each other, plot positions of them and analyze data is it usable. Simulate boat movements by moving them up and down, but keeping direction same. I am interested to hear results.

From bus you get maximum 1 Hz position, so I think that is unusable and late.
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Oct 01, 2018, 08:17 pm
Those GPS modules seem to be not so well documented.  If i buy I will try it with 3.3 V Vcc first.
http://radiolink.com.cn/doce/product-detail-115.html
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Oct 02, 2018, 03:51 pm
The max. freq. for position via bus being 1Hz is it because #define TimeUpdatePeriod 1000 or is there other limitations in NMEA2000? If not what kind of delays is there in data transmission via bus?  I quess one could delay the position coming straight from GPS if time info is delayed on the bus.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 02, 2018, 05:28 pm
Sorry small mistake. I was thinking about 1 Hz PGN129029/GNSS, but there is also 10 Hz PGN129025/LatLonRapid. But not all GPS provide PGN129025. And specially if you have old NMEA0183 GPS with converter, there is only 1 Hz PGN129029.

And if you are planning to put other GPS to the bus by yourself, then you can provide PGN129025 with 10 Hz and PGN129029 1 Hz to the bus.

PGN129025 is single frame higher priority message. One frame transfer takes about 400 us. Since bus is multimaster bus, there may be others sending data at same time and our frame transfer may be delayed. Lower source address has higher priority. So you can try to set your device source address to 0, but then depending of other devices on the bus higher priority devices may rise your source address during address claiming procedure. But in normal boat bus I would expect that extra delay would be very rare.

So if you sending lat/lon in 100 ms period, the transfer delay should be less than 1 ms, which is <1/100
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Oct 02, 2018, 08:16 pm
Is rate of turn rapid also? N2kMessages.h nor https://www.nmea.org/content/nmea_standards/messages_pgns.asp
 does not mention rapid. I have been thinking of trying this GPS compass thing on another Arduino than where autopilot is and where rate of turn is measured  already. It would be nice to have rate of turn via bus but 1 Hz feels slow.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 03, 2018, 06:22 am
I do not have NMEA 2000 documentation and if I would I could not say anything due to agreement. So all information has to be digged from public docs.

NMEA 2000 defines default rates and rate limits for PGNs. Certified systems follow these rates. If you make system for your own boat, you can use different rates. Normally fast packet messages has max. 1 Hz rate. Single frame packest are up to 200 Hz. There is also limits for min. rate. E.g. if you send temperature 130316 with 0.1 Hz, MFDs thinks that as lost data between transmits.

But anyway I digged default rates for 127250 10 Hz, 127257 1 Hz, 127251 10 Hz

So no problem to use 10 Hz for rate of turn. And as I mentioned for your own system you can use 20 Hz, if you like.
Title: Re: NMEA 2000 Shield
Post by: autopilotNOR on Oct 03, 2018, 11:54 am
Hey Timo,

regarding the Coolant temp in case of Raymarine Axiom. I have figured out that I have to map the sensor values from -20 to 150 C in Kelvin.

Code: [Select]
double EngineCoolantTemp = dMap(analogRead(coolantTempPin), coolantTempPin_Min, coolantTempPin_Max, 253, 423);
So this was showing the correct values in C on the MFD. I guess this is the case for all other temperaturs as well.

another thing regarding RPM. I could do this now with freqMulti library. Working good so far. To get the values back to 0 when the engine is not running I overwrite the RPM value with an if..else. If rpm available do measure every 500 ms and calculate and else is if rpm lower than 200 than set rpm to 0.

Working so far. But as soon as I try to push the values into a circular buffer I do get just strange stuff. So my question is how to smooth the RPM values?


Code: [Select]

double ReadEngineRpm() {
    if (freq1.available()) {
      sum1 = sum1 + freq1.read();
      count1 = count1 + 1;
    }

    if (timeout > 500) {
      if (count1 > 0) {
        EngineSpeed = (freq1.countToFrequency(sum1 / count1)*2);
      }

      sum1 = 0;
      count1 = 0;
      timeout = 0;
    }

    if (EngineSpeed >= 200)
    {
        EngineSpeed = EngineSpeed;
    }
    else
    {
        EngineSpeed = 0;
    }
        return EngineSpeed;

}


I am sure there are better ways to implement this right?
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Oct 03, 2018, 04:51 pm
https://www.navilock.de/produkte/G_62571/merkmale.html
https://www.navilock.de/produkte/S_62586/merkmale.html

A better documented GPS with TTL serial.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 04, 2018, 05:41 am
Did you foind any online shop for those?
Title: Re: NMEA 2000 Shield
Post by: Heikkif on Oct 04, 2018, 03:37 pm
No not really any web shops selling those Navilock receivers. Ebay had some. Ordered Radiolink ones as they were third the price and free shipping.
Title: Re: NMEA 2000 Shield
Post by: maxik on Oct 09, 2018, 01:43 pm
Hello Timo!
Thank you for your work!

A you trying your library with wi-fi and programms like https://play.google.com/store/apps/details?id=air.N2KViewMobile . I want to reading some parameters from nmea bus on my tablet.

autopilotNOR: about fuel sensor -- why you are not using capacitive sensor? You can easily make it from arduino nano and fiberglass plate.
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 09, 2018, 05:15 pm
NMEA 2000 protocol on CAN is standard. When data is sent over internet or WiFi, there are different solutions and formats. Some converts possible data to NMEA0183 (B&G), some packs it to NMEA0183 like including hex data (SeaSmart). I do not know the format Maretron uses. Note that also Maretron USB100 N2k-USB gateway uses different format than Actisense, which is supported on my library. So you can not even use N2k-USB gateway with e.g. Open Skipper on my NMEA Simulator.

There is SeaSmart convert on the library, so you can make device, which sends that and use other sw on phone. There is actually ESP32 example for that. Or with ESP32 you can make web server to show data as you like.
Title: Re: NMEA 2000 Shield
Post by: pagoda54 on Oct 09, 2018, 05:49 pm
Currently planning to put Barometric Pressure on N2K for my B&G plotter.
The boat device will be a Teensy 3.2 to minimise power needs.
I have tested Teensy with a simple one parameter PGN - and  Actisense Reader decodes the numbers OK.
In addition I checked the CAN side by feeding the Teensy CAN to another Mega 2560 with transceiver  running the Actisense listener  -that is received OK. So the NMEA2K CAN operates  OK.

However, trying various combinations of Mega/Teensy, there have been no occasions when the "fake" Manufacturer data is displayed by Actisense Reader  -at either end?

The actual data comes through , but none of the "Set Product" or "Set Device" info is shown.  I have stuck with the simplest one/two parameter examples.

What else (?) is needed to identify the source of this new info on the N2K network??
Or is there something missing in the Actisense Reader??

Thanks,  Graeme
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 09, 2018, 06:28 pm
What eample you have used for the start?
Do you use mode N2km_ListenAndNode on NMEA2000.SetMode(...)?
What do you mean with "fake" manufacturer?

On NMEA2000 there is problem that it defines just manufacturer code, which you can buy from NMEA organization for some big money and yearly costs. So there is no place, where you could tell manufacturer to be "Company ltd". This stupid limitation also means that if you have bought e.g. Garmin MFD 2 years ago, it would show for every new manufacturer registered after that as "unknown". Normally MFD:s and Actisense Reader will show serial numbers right. So if that information is not right, then there is some other problem.

Remember to drop Teensy sped down to 24 Mhz and you get it running with about 14 mA on 12 V. I have that with my temperature system.
Title: Re: NMEA 2000 Shield
Post by: pagoda54 on Oct 09, 2018, 10:38 pm
What eample you have used for the start?
Do you use mode N2km_ListenAndNode on NMEA2000.SetMode(...)?
What do you mean with "fake" manufacturer?

On NMEA2000 there is problem that it defines just manufacturer code, which you can buy from NMEA organization for some big money and yearly costs. So there is no place, where you could tell manufacturer to be "Company ltd". This stupid limitation also means that if you have bought e.g. Garmin MFD 2 years ago, it would show for every new manufacturer registered after that as "unknown". Normally MFD:s and Actisense Reader will show serial numbers right. So if that information is not right, then there is some other problem.

Remember to drop Teensy sped down to 24 Mhz and you get it running with about 14 mA on 12 V. I have that with my temperature system.
Many thanks for that - I'm using PGN 130312 temperature parameter sender  as the source "device" -with dummy fixed temperatures  . I have tried ListenAndNode and ListenOnly. 

The Acticense reader on the Mega2560 sees the data and interprets it correctly.

I was just puzzled why none of the SetProduct or SetDevice info showed up.


Actisense Reader is version 1.517- I am not aware of anything more up to date?

I have used the Actisense SW to program a genuine Actisense device (NGW-1)  before- to set up what PGNs it used.  The Actisense SW identifies PGN 192996 in it's hardware configuration list tab as "product information but that has never appeared in the Data View Tab.
While the Programming side of Actisense SW has nothing to do with Arduino/Teensy  the list of PGNs appears to be what it deals with. It can read new PGN lists from a newer device it appears. Update from hardware for RX/TX only works with Actisense devices I think.

Does Device/Product info need to be requested from a node? or is it exchanged on first handshaking?


thanks, Graeme
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 10, 2018, 07:06 am
Use N2km_ListenAndNode. Other modes are for special cases like ActisenseListener, which should not tell anything about being on the bus.

The problem is that if you use just TemperatureMonitor example and ActisenseListener on the bus, there is no device requesting Device/Product info. On start TemperatureMonitor will send ISO address claim PGN 60928), which contains device info. If you use NGT-1, that will make requests for all devices on the bus. Other solution is to use third device with example DeviceAnalyzer, but that requires at least Teensy, since it collects all information to th memory.
Title: Re: NMEA 2000 Shield
Post by: pagoda54 on Oct 10, 2018, 11:54 am
Use N2km_ListenAndNode. Other modes are for special cases like ActisenseListener, which should not tell anything about being on the bus.

The problem is that if you use just TemperatureMonitor example and ActisenseListener on the bus, there is no device requesting Device/Product info. On start TemperatureMonitor will send ISO address claim PGN 60928), which contains device info. If you use NGT-1, that will make requests for all devices on the bus. Other solution is to use third device with example DeviceAnalyzer, but that requires at least Teensy, since it collects all information to th memory.
OK,  I can probably do that, as I have another Mega2560 and transceiver card. I'll load up the Teensy with Device analyser and use the 2nd Mega to  transmit wind info. That way there should be some competition for bus addresses :-) and provoke some exchange of Device info that I can capture.

Thanks ,  Graeme
Title: Re: NMEA 2000 Shield
Post by: pagoda54 on Oct 15, 2018, 10:16 pm
Use N2km_ListenAndNode. Other modes are for special cases like ActisenseListener, which should not tell anything about being on the bus.

The problem is that if you use just TemperatureMonitor example and ActisenseListener on the bus, there is no device requesting Device/Product info. On start TemperatureMonitor will send ISO address claim PGN 60928), which contains device info. If you use NGT-1, that will make requests for all devices on the bus. Other solution is to use third device with example DeviceAnalyzer, but that requires at least Teensy, since it collects all information to th memory.
Success at last. Made a tabletop NME2000 network with 2 Megas and a Teensy.  Two Megas spitting out Temp and Wind example data, the Teensy reading Pressure and temperature from a BMP280 on I2C. They can all see each others data.
I have yet to connect to the boat network, but I think I'm in business.
The MFD is a B&G Vulcan. It can do time plots of data incoming. Does the SID value get used for determining the sequence of data or only identifying when data has the same nominal time stamp?
I suspect the latter.  Thanks for the help!
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 16, 2018, 06:22 am
As far as I know SID only tells that data has same time stamp even they data be delivered in different time. So e.g. if you have tempereature monitor monitoring several temperatures, you may read temperatures to memory at "same time" and then send them in different messages. So all messages can then have same SID. I do not know how well other devices use that information.
Title: Re: NMEA 2000 Shield
Post by: pagoda54 on Oct 16, 2018, 07:46 pm
If I find out , I'll post it here.

Your NMEA2000>NMEA0183 converter interests me.
Does it know anything about Autopilot PGNs?
I have a rather hybrid boat set up. Originally B&G H3000 fastnet network- which still works OK. I use a proprietary B&G device to communicate fastnet with N2K. (H5000 converter). That works well but is ONE WAY.  The autopilot function is still fastnet only. The H3000 cpu does have NMEA0183 inputs and B&G "think" it may accept NMEA 0183 steering commands. If I can get my B&G plotter N2K steering commands translated to NMEA2K then I could be in luck. Any clues would be appreciated. (no commercial purpose- own boat only)
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 17, 2018, 06:35 pm
Converter is an example and at the same time full working with current messages. I you know message formats to convert on both side, it is reasonably easy to add new messages by following current logic. I do not know NMEA0183 steering messages.
Title: Re: NMEA 2000 Shield
Post by: pagoda54 on Oct 20, 2018, 04:10 pm
OK,  success at the boat.  B&G Vulcan can see the data from the teensy.  There appears to be more than one source for 130311- environmental data. The other one has nulls for atmospheric pressure and humidity. My data has only nulls for humidity.  It doesn't seem to cause any problems.  There is another PGN -130845 which also provides some similar parameters. I couldn't find it among those in your lists? Have you come across it? 
The Vulcan appears as several devices. How much is software and how much actually separate nodes I can't tell.  Curious that it can be done in software as you have done
Title: Re: NMEA 2000 Shield
Post by: timolappalainen on Oct 20, 2018, 07:58 pm
There can be several sources for same PGN on the bus. This is normal specially for temperature. They can even send same instance and temperature source. In MFD you should be able to clue your data to the device "NAME", which is actually "device information". Due to address claiming you should not use on your own devices just device address. That is also reason for tDeviceList class.

Note that PNG 130311 and 130312 are deprecated and should be used except, if need them on old devices. Vulcan supports 130316 Extended temperature.

PGN 130845 is on proprietary area and content depends of manufacturer. It has been recorded e.g. on Simnet. You can find rather complete list of PGN contents on canboat project https://github.com/canboat/canboat/blob/master/analyzer/pgns.json . It has some descriptions for 130845, but does not mean that you see any of them.

I have also seen that Vulcan shows several devices - I think four. I do not know are they internally different hw or sw as I have multidevice support on my library. I either do not know could sw multidevice be certified.