Go Down

Topic: NMEA 2000 Shield (Read 404167 times) previous topic - next topic

sarman1964

Hi Timo,
Thanks for your prompt reply.

I have 129284 in device transmit PGN list :
const unsigned long TransmitMessages[] PROGMEM = {129284L, // Navigation                                      
                                                  0   };           

And activate it in setup with :
NMEA2000.ExtendTransmitMessages(TransmitMessages);

                    
                                                                                              

keirono

Hello Timo,

I'm just beginning but I won't be asking any questions about circuit boards or connections, more a principle really as I want to learn this myself with a few pointers!

I am trying to create a WiFi Gateway that outputs YDG02 and/or Actisense via TCP/UDP to broadcast to Navionics and SailGrib on a tablet and I wondered if there was an easy way. I'm using the wonderful ESP32 example with the Seasmart function and I am assuming I need to create the same function by reverse engineering the Actisense/Yacht Devices decoding built into the NMEA library, Canboat and SignalK?

Or, am I missing the obvious and outputting the RAW CAN message using a similar clienttobuf routine would be sufficient after it has completed being received?

I appreciate your patience.

timolappalainen

Client in inherited from stream so you should be able to simply do N2kMsg.SendInActisenseFormat(client); Or after you have opened connection you can just do 
NMEA2000.SetForwardStream(client);
NMEA2000.EnableForward(true);

keirono

Thanks Timo,

I've been programming C++ for about two weeks and only because I found your NMEA library and decided it would be fun and you've done all the heavy lifting that I could never manage for a few years I think. I have no idea how to use streams yet.

Is the client you are referring to TCP connection Linked List client that the Seasmart example uses or something more obvious, I'm uncertain how to get the data out onto Port 2000 for example. The stream examples are all Serial based.


metox

Hi Timo!
I have difficulties to run the DataDisplay2 example on my Teensy 4.1 (IDE 1.8.13 Teensyduino 1.53)

The code is modified as:
Code: [Select]
//#include <Arduino.h>
//#include <Time.h>  //
// #define N2k_CAN_INT_PIN 21
#include <NMEA2000.h>
#include <NMEA2000_Teensyx.h>
// #include <NMEA2000_CAN.h>
#include <N2kMessages.h>
#include <N2kMessagesEnumToStr.h>

tNMEA2000_Teensyx NMEA2000;


All I see on the Serial Monitor is:
Code: [Select]
CAN device ready
Running ...



Any other modifications necessary?

Rgds,
Göran


timolappalainen

It should work with default include
#include <NMEA2000_CAN.h> 
without any modification.


Anyway you may have rx/tx connected wrong or tranceiver problem.

timolappalainen



I do not know what happened for my response in morning.

Copy example NMEA2000ToWiFiAsSeaSmart to NMEA2000ToWiFiAsActisense. Then comment line

Code: [Select]
NMEA2000.AttachMsgHandler(&tN2kDataToNMEA0183); // NMEA 2000 -> NMEA 0183 conversion

in function InitNMEA2000, if you do not need NMEA2000 to NMEA0183 conversion.


Then in function HandleNMEA2000Msg replace lines

Code: [Select]
  if ( !SendSeaSmart ) return;
  
  char buf[MAX_NMEA2000_MESSAGE_SEASMART_SIZE];
  if ( N2kToSeasmart(N2kMsg,millis(),buf,MAX_NMEA2000_MESSAGE_SEASMART_SIZE)==0 ) return;
  SendBufToClients(buf);


with

Code: [Select]
  for (auto it=clients.begin() ;it!=clients.end(); it++) {
    if ( (*it)!=NULL && (*it)->connected() ) {
      N2kMsg.SendInActisenseFormat((*it).get());
    }
  }


It is not perfect if you have multiple clients, since it creates message again for each client. I should create function for converting data to buffer in Actisense, then it could be just sent to each client.

keirono

Thank you Timo, I can spend the time getting better now and I'll write the data to buffer conversion, your code is structured and easy enough to understand. It's just my lack of C++ skills at the moment, give me old school 68000 Amiga or ST assembly and I'd be much happier!

My plan is to write an anchor watch system running on one ESP32 for some comfort during the night on the hook and I also though about doing a MOB watchdog as the Ocean Signal alarms in our lifejackets send out the safety AIS and MOB PGN messages. I just need to add the PGN's from the Can Boat code, but I got a little confused as the data from the MMSI onwards doesn't seem to be on a byte boundary in the Can Boat code. Still, one step at a time

Thank you for all your hard work and dedication to answering the messages on this thread, you definitely go above and beyond. 


metox

It should work with default include
#include <NMEA2000_CAN.h>
without any modification.


Anyway you may have rx/tx connected wrong or tranceiver problem.
Hi again Timo!

I still have problems running the DataDisplay2 example, but also the TemperatureMonitor fails.

TemperatureMonitor
It starts OK, but after a while errors appears. May this is nothing to worry about...
See "TemperatureMonitor.txt"

DataDisplay2
I am using the example taken from your latest update (2021-02-06) of NMEA2000-master, without any modifications. The output is given in "DataDisplay2.txt".
The protocol analyzer shows nothing on all three CAN controllers. (See "Screenshot from 2021-02-07 13-49-57.png").

I also have photos of my breadboard, but unfortunately they are too large to be included.
The pins I use are:
pin 23 (rx) pin 22 (tx) CAN 1
pin 0 (rx) pin 1 (tx) CAN 2
pin 30 (rx) pin 31 (tx) CAN 3.

Which CAN controller is the output to be expected?
How do you change this, if needed.

Finally, is the documentation given below obsolete, ie have you integrated into the NMAE2000-master?

Code: [Select]
Library is under tests. I prefer to start to use it also for Teensy 3.1/3.2/3.5/3.6 for
non critical devices in testing purposes so that possible errors will be catched. Final
goal is to use this as default library for all Teensy boards.

See https://github.com/ttlappalainen/NMEA2000.


## Usage


    #include <NMEA2000.h>
    #include <N2kMessages.h>
    #include <NMEA2000_Teensyx.h>

    tNMEA2000_Teensyx NMEA2000;

    void setup() {
      NMEA2000.Open();
    }

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

See the [NMEA2000/Examples](https://github.com/ttlappalainen/NMEA2000/tree/master/Examples) for more examples. They are all compatible with this library.

Regards,
Göran








timolappalainen

When I did latest update, I tested both DataDisplay2 and MessageSender with Teensy 4.0 and ESP32. As default it uses CAN1 for Teensy 4.0. Also tested that compilation succeeds Arduino Mega and Arduino DUE.

In my test board I have MCP2562 tranceiver and connection is simple:
pin 1 -> Teensy pin 22 (Tx)
pin 2 -> Gnd
pin 3 -> 5V
pin 4 -> Teensy pin 23 (Rx)
pin 5 -> 3.3V
pin 8 -> Gnd

DataDisplay2 has been running without modifications for about 5 hours. Also MessageSender runs without any modification.

The library is under tests, since I do not know any certified device done with it. There is no reports of failure.

And you should be worried about error "PGN xxxxxx send failed". It means that CAN controller could not communicate with bus and it does not actually send anything. You get error delayed, since first "succeeded" frames has been buffered. When buffer gets full, you get error.

Please:
- check your connection to tranceiver
- check you have at least 1 120 ohm termination resistor on bus. Bus works with one on short test conditions and final bus must have 2 termination resistors on longest end on the bus
- check your connection to tranceiver. Yes do it again.

If you want to change port for Teensy 4.0 for, you define
#define NMEA2000_TEENSYX_CAN_BUS tNMEA2000_Teensyx::CAN2
#include <NMEA2000_CAN.h>

metox

#1030
Feb 09, 2021, 12:27 pm Last Edit: Feb 09, 2021, 12:31 pm by metox
Hi Timo!
I am getting some progress, but not there yet...

After our last conversation I have:


Result
With a protocol analyser (attached) I can verify that:
  • Data is sent from the 'MessageSender' chip.
  • Converted to CAN protocol.
  • Data is received to the 'DataDisplay2' chip.


The white and brown channels are the CAN-bus, the yellow sender chip and red receiver ditto.
Despite this, the same error messages are displayed as before.

Observations
  • There is approximately a 6ms delay between the sent bytes (re-transmissions?)
  • The Tx-LED and the Rx-LED are both permanently turned on, which make sense as the data transmission
    only goes in one direction.


Currently I don't know how to proceed.

Any ideas?

Rgds,
Göran



timolappalainen

Do you mean that you have connected linked tranceivers to CAN bus? Those are TTL to RS485 converters and meaned for bus RS485 physical layer. CAN bus is CAN bus and requires e.g. unisolated MCP2562 tranceiver or isolated ISO1050 tranceiver chip. 

pulkkla

Hello,

I'm trying to establish N2k communication between two Arduinos. I'm using relatively new Arduino Nano Every boards equipped with MCP2515 modules including TJA1050 transceivers. These boards have 48KB flash memory, capable of storing the NMEA2000 libraries. For testing I'm using Timo's examples (MessageSender and DataDisplay2) although I had to drop bunch of PGNs to fit the programs into the boards. Modules are connected directly to each other and terminated with 120Ω resistors.

Sender seems to be functioning properly as I'm able to receive data using a Raspberry Pi with CAN hat, and I'm also able to observe the proper data in Signal K server on the RPi. The problem seems to be the Arduino listening the bus, it just reports "CAN device ready" in serial and nothing else. I've configured SendFrameBufSize to 20 on the sender since first I wasn't able to send anything with larger buffer. All CS and interrupt pins are correct on both boards, MCP CAN clock configuration is set to "8". I've also tried decreasing buffer size on the receiver (SetN2kCANMsgBufSize(2)) but nothing seems to have any desired effects.

Any suggestions what should I try next?
Lari Pulkkinen

timolappalainen

With small buffer sizes it should receive at least single package messages. After open, which prints "CAN device ready" it should also print "Running...". If it does not, maybe there is not enough memory and it just gets stuck. Try without interrupt definition. If interrupt is not connected right, it does not work at all with definition.

And last succestion is to go to Teensy or ESP32, which has at least enough memory.

metox

Do you mean that you have connected linked tranceivers to CAN bus? Those are TTL to RS485 converters and meaned for bus RS485 physical layer. CAN bus is CAN bus and requires e.g. unisolated MCP2562 tranceiver or isolated ISO1050 tranceiver chip.
My vocabulary may be less precise, but look at the picture and it will be clear what I mean.
The analyzer is connected to A+ and B-, TXD pin on one side and RXD pin on the other.

Go Up