Go Down

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

timolappalainen

As you can see - without "U" after PGN number. Can it cause this odd behavior?
That does not have effect. UL means that numeric constant is unsigned long type. It is also my mistake on library code that all PGNs should be marked UL instead of L. That does not have effect, since value is less than long int range.

But your problem is strange. You could try to change
#define EngineDataUpdatePeriod 500
Which is right default period. I have seen Garmin skipping e.g. temp data, if one send it with too long period.

autopilotNOR

Hi Timo,

I found time to create y external GNSS device to upgrade the internal one from the Axiom which looses the fix very often due to limited view to the satelites.

It is a LINX GM GPS/Glonas and so on devices which should be very good. However, I made the circuit board and tested the communication first by using the serial passthrough example. with that sketch I see the output of the serial monitor from the GPS at serial3 (Teensy 3.2).

If this finally works I would like to add the BNO055 as a Compass and heading sensor.

Now I programmed the NMEA0183to2000 and activated enabled forward false as well show actisense format in clear text.
I also adjusted the baud rate to 9600 which my gps devices is using.

The result is that nothing shows up on the serial monitor.

Shouldn't the serial monitor show the data send to the bus even the bus isn't connected since "Forward false" is set. Any idea what I am doing wrong or what I have forgotten?

THX!

skyjumper

#782
Sep 16, 2019, 10:22 am Last Edit: Sep 16, 2019, 10:36 am by skyjumper
Hi All, I'm having some trouble with Timo's library. I have created programs that can send N2K data and others that can receive N2K data, but so far I have been unable to create a program that can do both.

Here is the code in my setup() function:

Code: [Select]
 
  // Reserve enough buffer for sending all messages.
  NMEA2000.SetN2kCANSendFrameBufSize(250);
 
  // Set Product information
  NMEA2000.SetProductInformation("00000001", // Manufacturer's Model serial code
                                 100, // Manufacturer's product code
                                 "MY-TEST",  // Manufacturer's Model ID
                                 "1.0.0.0 (2019-09-13)",  // Manufacturer's Software version code
                                 "1.0.0.0 (2019-09-13)" // Manufacturer's Model version
                                 );
                                 
  // Set device information
  NMEA2000.SetDeviceInformation(12345, // Unique number. Use e.g. Serial number.
                                132,
                                25,
                                2046
                               );

   NMEA2000.SetForwardStream(&Serial);  // PC output on due programming port
  // NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text. Leave uncommented for default Actisense format.
  // NMEA2000.SetForwardOwnMessages();



  /* NOTE - I have tried all three of these modes, even though reading the comment and looking
                 at the library source indicates that ListenAndNode is the correct choice.

                 For two of them, I am unable to receive data and
                 I get a true return from NMEA2000.SendMsg(n2kMsg); and there is no indication that
                 any data from source 23 was published on the bus. I'm watching the bus with Can King.
   
                 With "ListenAndSend" I am able to receive data but still nothing is published on the bus.

                 If I leave all three commented out I can receive correctly.

  */ 

  // If you also want to see all traffic on the bus use N2km_ListenAndNode instead of N2km_NodeOnly below
  //NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode, 23);
  //NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly, 23);
  //NMEA2000.SetMode(tNMEA2000::N2km_ListenAndSend, 23);



  // Uncomment this next line to dump bus traffic to serial
  //NMEA2000.SetDebugMode(tNMEA2000::dm_ClearText); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega
  NMEA2000.SetDebugMode(tNMEA2000::dm_None); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega

 
  // Set false below, if you do not want to see messages parsed to HEX withing library
  NMEA2000.EnableForward(false);
 
  NMEA2000.SetMsgHandler(HandleNMEA2000Msg);
  NMEA2000.Open();


Here is some code I am using to create the PGN and send it. Note that its a proprietary, destination global, fast-packet PGN. I have used this same code to send data in another application that is send only and it worked correctly:


Code: [Select]
bool sendN2kData(float d)
{
  tN2kMsg n2kMsg;

  n2kMsg.SetPGN(126720L); // Proprietary, destination global, fast-packet PGN
  n2kMsg.Priority=7;

  // definer tag
  uint16_t definerTag = 0xE598;
  n2kMsg.Add2ByteUInt(definerTag);

     
  Serial.println("\r\n*** SENDING ***");
  return NMEA2000.SendMsg(n2kMsg);

}




I'm out of ideas, so any help offered will be greatly appreciated. Thanks!

timolappalainen

For any normal bus devices use mode N2km_NodeOnly or N2km_ListenAndNode. N2km_ListenAndNode has extra feature for simple data forwarding to forward stream so that you do not need to write handler function and print message data e.g. text or actisense format. Other modes are for special cases like being invisible on bus.

Both mentioned modes can read and sent messages. For handling received messages you need to call
NMEA2000.SetMsgHandler(HandleNMEA2000Msg);

and write HandleNMEA2000Msg handler function as in e.g. in example DataDisplay.ino. Note that example uses default mode, which makes it invisible on bus, but you can still send messages to bus as normally with NMEA2000.SendMsg(). That is not prefered, since normally MFD:s requires devices are registered right on the bus.

So in conclusion, if you take e.g. TemperatureMonitor as base and add NMEA2000.SetMsgHandler(HandleNMEA2000Msg); to it, you have rigth device for listen and sent. Note that  as in TemperatureMonitor we define messages we are going to transmit with
Code: [Select]
const unsigned long TransmitMessages[] PROGMEM={130310L,130311L,130312L,0};
...
NMEA2000.ExtendTransmitMessages(TransmitMessages);

You have to do the same for messages you are going to receive:
Code: [Select]
const unsigned long ReceiveMessages[] PROGMEM={127505UL,0};
...
NMEA2000.ExtendReceiveMessages(ReceiveMessages);

Note also that if you are going to send or receive proprietary fast packet messages, you have to tell system those otherwise library handles them as single framed messages:
Code: [Select]
const unsigned long ExtraFastPacketMessages[] PROGMEM={126720L,0};
...
NMEA2000.ExtendFastPacketMessages(ExtraFastPacketMessages);


Take also care that you use board with enough memory. Arduino Mega can handle small systems, but also runs easily out of memory. You will see it, when it does not run at all.

timolappalainen

Shouldn't the serial monitor show the data send to the bus even the bus isn't connected since "Forward false" is set. Any idea what I am doing wrong or what I have forgotten?

THX!
If you set forward false, it does not forward anything. EnableForward and SetForwardOwnMessages are actually default so it should be enough to set forward stream.

Small fix. There is no Actisense format in clear text. It is either binary Actisense format or clear text, which shows data in hex. Use Actisense format, you you want to read data with Actisense Reader or OpenSkipper.

pkeiramo

You could try to change
#define EngineDataUpdatePeriod 500
Which is right default period. I have seen Garmin skipping e.g. temp data, if one send it with too long period.
I tried with 500 ms update period. Still no luck.

I noticed that it comes 1 or 2 TX errors every time I turn ESP32 on. I don't know reason for that.

timolappalainen

Tx error comes on ESP32 CAN initialization time. I am investicating that and will update library, if I find solution. This is fatal for me, since ESP32 devices will not pass NMEA2000 certifications test due to those errors.

skyjumper

#787
Sep 16, 2019, 08:28 pm Last Edit: Sep 16, 2019, 09:44 pm by skyjumper
Thanks very much Timo...

Both mentioned modes can read and sent messages. For handling received messages you need to call
NMEA2000.SetMsgHandler(HandleNMEA2000Msg);

and write HandleNMEA2000Msg handler function as in e.g. in example DataDisplay.ino. Note that example uses default mode, which makes it invisible on bus, but you can still send messages to bus as normally with NMEA2000.SendMsg(). That is not prefered, since normally MFD:s requires devices are registered right on the bus.
My code actually does have the handler and works well in receiving messages and parsing messages.

I also made the recommended changes as far as listing the PGNs to be sent and received as you described. That didn't help.

I then pulled up the temperature monitor example as you said. It compiled nd uploaded just fine, but it also does not publish any data on the bus. This is the unmodified example.

My hardware is an EPS32-Wrover module. I do have another app that can publish data, including fast-packet data, on the bus. I'll compare the two to see what's happening. But do you know of any reason the temp monitor example would not publish data? I tried both the mode types you mentioned.

Thanks again!

UPDATE - I just read the above messages about ESP32, perhaps my issue is related? If I can help debug or anything I'm happy to assist.

Also, I'm able to run the Temp Monitor example on my Teensy 3.6 and it works fine on that board.

timolappalainen

Do you have right Tx/Rx pin definitions for your ESP32 module. TemperatureMonitor example works for 100% sure on ESP32, if your hw is OK and you have right pin definitions for your module.

skyjumper

#789
Sep 17, 2019, 03:25 pm Last Edit: Sep 17, 2019, 06:02 pm by skyjumper
Do you have right Tx/Rx pin definitions for your ESP32 module. TemperatureMonitor example works for 100% sure on ESP32, if your hw is OK and you have right pin definitions for your module.
This had not occurred to me, since it reads data fine. I suppose the TX pin could be wrong, I'll check thanks.

UPDATE - Ug, that was the problem. The RX pin was correct, the TX pin was wrong. The apps I wrote that send were on the Teensy. Thanks again Timo, I'm sorry I wasted your time.

Rossp

Hi Timo thanks again for all your great work.
Thanks to you my esp8266 D1mini works well with the mcp2515 can interface and now testing your n2k to nmea0183 over wifi with esp32 with mcp2562 which works very well for TCP. In the example I don't see any specifics for TCP protocol and I was wanting to change it to UDP protocol for various Android apps, what would I need to change to achieve UDP instead of TCP ?

timolappalainen

This had not occurred to me, since it reads data fine. I suppose the TX pin could be wrong, I'll check thanks.
Also remember that MCP2562 has pin 8 STBY pin and has to connect to ground.

timolappalainen

In the example I don't see any specifics for TCP protocol and I was wanting to change it to UDP protocol for various Android apps, what would I need to change to achieve UDP instead of TCP ?
This is not part of NMEA2000 library and I do not have just now time to make sample. Just google ESP32 wifi UDP and try to find examples.

pkeiramo

#793
Sep 19, 2019, 01:40 pm Last Edit: Sep 19, 2019, 02:01 pm by pkeiramo
Tx error comes on ESP32 CAN initialization time. I am investicating that and will update library, if I find solution. This is fatal for me, since ESP32 devices will not pass NMEA2000 certifications test due to those errors.
I thought that maybe it would solve this if I update my Triton T41 software, if it was some problem with it. However I found out that I already have the latest version. So no help from there with this ESP32 problem of mine :(

pkeiramo

Can CAN transceiver have something to do with this problem? I am now using SN65HVD230 because ESP32 does not have 5V easily available and MCP2562 needs 5V voltage.

Go Up