Go Down

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

timolappalainen

Have you checked DataDisplay2 example? There is function EngineDynamicParameters, which reads engine parameters.

kenobiben

Have you checked DataDisplay2 example? There is function EngineDynamicParameters, which reads engine parameters.
Thanks Timo, this is what I need

kenobiben

#962
Aug 31, 2020, 03:34 pm Last Edit: Aug 31, 2020, 03:44 pm by kenobiben
Hi timo, what do you think about this? any suggestion about line I can remove or add to listen rpm on rapid parameter and send on trip fuel consumption after calculate liter per hour, beacuse I'm not sure that I understood everything in the example...
Thanks

#include <Arduino.h>
//#include <Time.h>  //
#define N2k_CAN_INT_PIN 21
#define USE_MCP_CAN_CLOCK_SET 8
#include <NMEA2000_CAN.h>
#include <N2kMessages.h>
#include <N2kMessagesEnumToStr.h>


int rpm1;
int rpm2;
float lth1 = 0;
float lth2 = 0;
float lperhour1 = 0;
float lperhour2 = 0;



typedef struct {
 unsigned long PGN;
 void (*Handler)(const tN2kMsg &N2kMsg);
} tNMEA2000Handler;


void EngineRapid(const tN2kMsg &N2kMsg);
void TripFuelConsumption(const tN2kMsg &N2kMsg);


tNMEA2000Handler NMEA2000Handlers[]={
 {127488L,&EngineRapid},
 {127497L,&TripFuelConsumption},
 
 {0,0}
};

Stream *OutputStream;

void HandleNMEA2000Msg(const tN2kMsg &N2kMsg);

void setup() {

 
 Serial.begin(115200); delay(500);
 OutputStream=&Serial;
//   while (!Serial)
 
//  NMEA2000.SetN2kCANReceiveFrameBufSize(50);
 // 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.SetMode(tNMEA2000::N2km_NodeOnly, 22);
//  NMEA2000.SetN2kCANMsgBufSize(2);
 NMEA2000.Open();
 OutputStream->print("Running...");
}

//*****************************************************************************
template<typename T> void PrintLabelValWithConversionCheckUnDef(const char* label, T val, double (*ConvFunc)(double val)=0, bool AddLf=false ) {
 OutputStream->print(label);
 if (!N2kIsNA(val)) {
   if (ConvFunc) { OutputStream->print(ConvFunc(val)); } else { OutputStream->print(val); }
 } else OutputStream->print("not available");
 if (AddLf) OutputStream->println();
}


void EngineRapid(const tN2kMsg &N2kMsg) {
   unsigned char EngineInstance;
   double EngineSpeed;
   double EngineBoostPressure;
   int8_t EngineTiltTrim;
   
   (ParseN2kEngineParamRapid(N2kMsg,EngineInstance,EngineSpeed,EngineBoostPressure,EngineTiltTrim) ) ;
   if (EngineInstance=0) {rpm1=EngineSpeed;}
   if (EngineInstance=1) {rpm2=EngineSpeed;}
}

void TripFuelConsumption(const tN2kMsg &N2kMsg) {
   unsigned char EngineInstance;
   double TripFuelUsed;
   double FuelRateAverage;
   double FuelRateEconomy;
   double InstantaneousFuelEconomy;
}

//*****************************************************************************
//NMEA 2000 message handler
void HandleNMEA2000Msg(const tN2kMsg &N2kMsg) {
 int iHandler;
 
 // Find handler
 //OutputStream->print("In Main Handler: "); OutputStream->println(N2kMsg.PGN);
 for (iHandler=0; NMEA2000Handlers[iHandler].PGN!=0 && !(N2kMsg.PGN==NMEA2000Handlers[iHandler].PGN); iHandler++);
 
 if (NMEA2000Handlers[iHandler].PGN!=0) {
   NMEA2000Handlers[iHandler].Handler(N2kMsg);
 }
}
void loop() {

 NMEA2000.ParseMessages();
}
#define TempUpdatePeriod 500 //500ms delay

void SendN2kTemperature() {
 static unsigned long TempUpdated = millis();
 tN2kMsg N2kMsg;

 if ( TempUpdated + TempUpdatePeriod < millis() ) {
   TempUpdated = millis();

flowlt();
SetN2kPGN127497(N2kMsg,0,0,lperhour1,lperhour1,lperhour1);

   NMEA2000.SendMsg(N2kMsg);
   
SetN2kPGN127497(N2kMsg,1,0,lperhour1,lperhour1,lperhour1);
   NMEA2000.SendMsg(N2kMsg);
}
}

void flowlt() {
//flow port
if (rpm1 <=200) {lth1=0;}
if (rpm1 >=500) {lth1=5;}

lperhour1=lth1;

//flow starboard
if (rpm2 <=200) {lth2=0;}
if (rpm2 >=500) {lth2=5;}
lperhour2=lth2;
return; }

timolappalainen

I did not got your point:
- you are catching 127497L to function TripFuelConsumption, where you do nothing
- you have function SendN2kTemperature, which you do not call anywhere.

How did you thought to calculate consumption? If you get 127497L from bus, that should already contain current consumption.

kenobiben

I did not got your point:
- you are catching 127497L to function TripFuelConsumption, where you do nothing
- you have function SendN2kTemperature, which you do not call anywhere.

How did you thought to calculate consumption? If you get 127497L from bus, that should already contain current consumption.
I catch the rpm of engine, because my engine is old one and didn't send fuel consumption,thenI calculate by a lut the consumption corresponding to rpm (see void flowlt).
SendN2Ktemp is just a 500ms delay beetwen 2 nmea2000 messages.
I resume: I read 127488, extract rpm for engine instance 0 & 1, calc liter per hour, send 127497 with consumption calculate before

skyjumper

#965
Sep 02, 2020, 11:51 pm Last Edit: Sep 02, 2020, 11:58 pm by skyjumper
Hi Timo, I'm having what I think is an address claim problem. This problem was reported by a friend of mine and I have been able to reproduce it.

My ESP32 based device works very well using your library on a N2K bus. The bus also has a Garmin plotter, a Garmin GNX120 display and a few other things and everything works well. But when I add a Garmin VHF210, I have a problem.

When I start the system without the VHF210, everything comes up and works. When I turn the VHF210 on, it apparently can not get on to the N2K bus. It will not appear in the device list on the plotter and it will not see position data from the plotter. As soon as I remove my device from the bus, the VHF210 appears on the plotter device list and it also gets position info from the plotter.

If I then restart me device, it will receive PGNs, but as soon as it sends one the VHF210 again disappears from the device list.

The VHF has no antenna, so its not receiving any AIS data that it's putting on to the bus. 

My device is running as NodeOnly and I have tried various combinations of DeviceInformation. I'm wondering if you can offer any suggestions on how I might track this down?

Thank you...

timolappalainen

I do not believe it is address calim problem. ESP32 with my library has been used on commercial tested devices and I expect I would heard problems from those.

On address claiming devices decides their addresses and once that has been done, they should keep it next time. So it happens only if you have address collision. You can simply avoid address claiming, if you first connect all other devices to the bus and list with some system what addresses exists. Then you put your device address other than any of those. Or just blindly set you device address to e.g. 80 - in small systems addresses are normally <30.

This kind of problems can be caused by:
- Wrong cable termination. Too many or too few termination resitors. Must be exactly 2 one on each end of main bus. Each stup length should not exceed 6 m.
- False or broken tranceiver.
- Program filling the bus. If you e.g. have loop sending data to the bus, but you logic fails and it will send data on every loop, bus will come to nearly 100 % load.

skyjumper

#967
Sep 03, 2020, 11:57 pm Last Edit: Sep 04, 2020, 12:50 am by skyjumper
This kind of problems can be caused by:
- Wrong cable termination. Too many or too few termination resitors. Must be exactly 2 one on each end of main bus. Each stup length should not exceed 6 m.
- False or broken tranceiver.
- Program filling the bus. If you e.g. have loop sending data to the bus, but you logic fails and it will send data on every loop, bus will come to nearly 100 % load.
Thanks very much Timo. I agree the problem is with my code.

UPDATE: Actually the same issue happens with the Message Sender example

My N2K network is very small and the termination is good. I used your device analyzer to inventory the bus and I tried several different IDs which are clear. This happens on two different systems, with two different Garmin VHF radios. I modified my device to not send any PGNs after startup, still the problem persists. I'll see if Can King reveals anything interesting. This just seems to happen with Garmin VHF radios. If I learn anything I'll let you know, thanks again.
 

timolappalainen

What hw you use? Do you have alternate device to test?

skyjumper

What hw you use? Do you have alternate device to test?
My board uses an ESP32 with a analog Devices isolated CAN transceiver (ADM3052BRWZ). My boards are all ESP-32 but I'm going to try one with a different transceiver. If it still fails I'll find a non-ESP-32 board to try it with. I'll report back, thanks Timo.

floron

Hello, quick question if i may. After reading a lot of these pages i couldn't find an explanation on how i can actually simulate NMEA 2000 traffic in order to test my board. I built a small integrated board with a ESP32 and CAN chip embedded and all the electronics to allow power up from a boat/car and CAN L and CAN H ports. Problem is,  i don't have a boat close to me so i cannot test my code and check if messages go through, can anyone help or do you have a clue on how i can simulate the nmea 2000 network on the can l can h ports? Would a signal generator do it?

seamaster

#971
Oct 09, 2020, 12:34 pm Last Edit: Oct 09, 2020, 12:37 pm by seamaster
You can use 2 boards with CAN and setup one to transmit and the other one to receive NMEA2000 messages. Or you can use"of the shelf" NMEA2000 simulator that could be purchased here:
https://acrossoceansystems.com/index.php/nmea2000-nmea0183-simulator/
it is "boat in a box" what I mean is that this simulator can simulate almost anything that is possible to find on a vessel in real life. I use it every day!
Cheers!

floron

Hello Seamaster, thanks for your tip. I made 5 boards so i think i can designate one to send NMEA messages to my guinea pig.

Thanks for your purchasing recommendations too.

landsea

I am a complete novice in arduino and electronics, but with a lot of vocation to know. After reading the almost a thousand posts from "NMEA 2000 Shield", reviewing a hundred documents etc. The only thing that I have clear is that:
- Timo's dedication and generosity have no limits.
- Timo's work is impressive.
- And Timo's patience wouldn't know how to describe it!
But I think that this whole project has a big mistake: the organization of the information.
I think it is very interesting to present the project in a structured and graphic way, so that more people can learn about it and develop it. Many resolve their doubts but do not publish their progress or their conclusions.
I think dividing the project into two main trunks, hardware and software, would be very interesting. But with complete solutions, so that initiates can be sure that their system works 100% and come to understand it. Then you can do research.


Has anyone published a complete diagram of something as simple as a teensy 3.6, 4.0 or 4.1-based hardware and software that can print on a screen what it receives directly from the N2K and transmit values to the n2k, for example from a gps?
Has anyone posted a 100% functional solution for a N2K simulator? and explain what is required and why? This would help many to try to know this system.
it is a reflection.
Thanks for reading me. :)

landsea

Without counting on all the information that Timo has published.https://github.com/ttlappalainen

Go Up