ttlappalainen / NMEA0183

Library for handling NMEA0183 messages
76 stars 48 forks source link

Basic Issue #55

Open alikhan968 opened 11 months ago

alikhan968 commented 11 months ago

Hi, You did a great job. I have very basic questions if you can answer plz. I have Arduino UNO and MEGA. Can it work on both boards? I simply want to print the data of a compass to serial monitor. I am using this shield https://projecthub.arduino.cc/hwhardsoft/how-to-use-nmea-0183-with-arduino-49055a

I am using printNMEA example, It is giving me this header issue no such file or director. #include If i comment it then everything fine. 2nd, i believe this example are based on hardware serial port 3 of mega. I tried but no data show up. I need 4800 baud rate to receive data. Thanks

ttlappalainen commented 11 months ago

Example simply reads NMEA0183 data from one port (Serial3) and writes to main port. It works with any device having at least main port and one extra serial port. It may also work by using software serial port. NMEA0183 port is defined on line: NMEA0183.Begin(&Serial3,3, 9600); If you want to user Serial1 with 4800 for NMEA0183 data, you just need to change line above to: NMEA0183.Begin(&Serial1,3, 4800); On command above 2nd parameter (3) is SourceID, which is needed to separate messages from different ports, in case sw handles several NMEA0183 ports.

As mentioned on NMEA0183.h, Begin(...) is actually obsolete and you should instead use Open(). Unfortunately this has not been updated to example. With Open() setup would be:

void setup() {
  Serial.begin(9600);
  Serial1.begin(4800);
  NMEA0183.SetMessageStream(&Serial1,3);
  NMEA0183.Open();
}
alikhan968 commented 11 months ago

Hi @ttlappalainen Thanks for your reply. I did the same but unfortunately, i couldn't get any data on the serial. I checked the shield output pin that is connected with RX pin of arduino through oscilloscope It is giving signal I commented 1st header that is StandardCplusplus. Can it be an issue?>

ttlappalainen commented 11 months ago

Are you feeding RS232 or RS422? In RS232 signal levels changes +- around ground so you need some tranceiver chip. If you feed RS422, you need also tranceiver chip like MAX3488.

alikhan968 commented 11 months ago

I am feeding compass signal to this shield. https://www.hwhardsoft.de/english/projects/rs485-arduino/ Then connecting this shield with serial port of the arduino. I can see the light blinking on this shield and i also checked the signal on oscilloscope at serial point and it gives waveform that's seems fine. But i don't see any blinking LED on Arduino while receiving data. i tried hardware serial port of Arduino MEGA. This is shield settings that i did image This is compass connections that i did image

ttlappalainen commented 11 months ago

Why you are taking 12-24 TD_A and TD_B to shield. Shouldn't you use NMEA0183 TD_A/TD_B? The shield must be configured as RS422 so that there is separate TX/RX. If it is configured RS485, it uses same wires for TX/RX.

ttlappalainen commented 11 months ago

Also check that A/B has not been mixed. I have met devices using A/B marking, but actually they has to be crossed to tranceiver.

alikhan968 commented 11 months ago

Why you are taking 12-24 TD_A and TD_B to shield. Shouldn't you use NMEA0183 TD_A/TD_B? The shield must be configured as RS422 so that there is separate TX/RX. If it is configured RS485, it uses same wires for TX/RX.

They both are same. Why i am using 12V side because i connected a connector that is also powering the compass. I also tried RS422 but nothing. Can you tell me how i can setup serial port so i can test on Arduino UNO because if select Serialport0 in code and UNO then it gives error.

ttlappalainen commented 11 months ago

I tested the old code and it worked fine with proper hw.

I also updated and tested PrintNMEA.ino. You can uncomment line: // #define USE_SOFTWARE_SERIAL 1 and define Rx/Tx pins on lines:

#define NMEA0183_RX_PIN 0
#define NMEA0183_TX_PIN 1

Then code works also with Arduino Uno.

If you still do not get anything out, you need to check your hw, wireing, baudrate you use on serial monitor, baudrate your device uses etc.

alikhan968 commented 10 months ago

Hi, I bought a new shield RS232 to TTL. It also not showing any data., I also changed the NMEA 0183 device from Compass to a pilot. If i see data on a software using RS232 on computer then it shows data at 4800 baud rate I don't understand what step i am missing that i can't get data on serial monitor. image I am using pin 2 and 5 on DB9 connector. Let me know if i need to test something on scope or meter. Thanks

ttlappalainen commented 10 months ago

You may have:

alikhan968 commented 10 months ago

1:Wrong pins on host side I checked it and even reversed it multiple times to see but the shield that i have contains two LEDs RX TX. When i connect in proper way then it blinks and it indicates that data is receiving on shield. 2:Different baud rates I checked the baud rate on computer and it is 4800. I even setup serial monitor and software serial baud rate same to avoid any confusion but no luck 3:Broken board serial inputs It is shield directly install on arduino. I also used different Arduino boards. All shows same 4:Loose connection Unfortunately not

Now what i noticed that if i display serial port data without parsing then it shows garbage data on serial monitor continues. It seems like something to do with Parsing. Did you use these codes with actual boat devices because there might be something that is different in actual marine product protocols than Arduino based devices.

Thanks for all your cooperation

ttlappalainen commented 10 months ago

As I wrote: "I tested the old code and it worked fine with proper hw."

Garbage sound like different baud rate definition. Check also that baudrate on your serial monitor matches with Serial.begin(9600);

alikhan968 commented 10 months ago

This is if i connect NMEA output directly with the COM port of the computer. image Now I am using RS232 to TTL(Also have RS422 to TTL) and this is what i made connection. image This is the code, that i am using `

include

include

include

// Uncomment below to use SoftwareSerial for NMEA0183 port instead of hw. This works e.g., with Arduino Uno

define USE_SOFTWARE_SERIAL 1

// If you use SoftwareSerial, define NMEA0183 port Rx/Tx pins below

define NMEA0183_RX_PIN 2

define NMEA0183_TX_PIN 3

if defined(USE_SOFTWARE_SERIAL)

include

SoftwareSerial NMEA0183Port(NMEA0183_RX_PIN, NMEA0183_TX_PIN, false);

else

HardwareSerial &NMEA0183Port=Serial1;

endif

tNMEA0183Msg NMEA0183Msg; tNMEA0183 NMEA0183;

void setup() { Serial.begin(9600); NMEA0183Port.begin(4800); NMEA0183.SetMessageStream(&NMEA0183Port,3);

if defined(USE_SOFTWARE_SERIAL)

Serial.println("Open SoftwareSerial for NMEA0183 port");

else

Serial.println("Open HardwareSerial for NMEA0183 port");

endif

NMEA0183.Open(); }

void loop() { tNMEA0183Msg NMEA0183Msg;

while (NMEA0183.GetMessage(NMEA0183Msg)) { Serial.print(NMEA0183Msg.Sender()); Serial.print(NMEA0183Msg.MessageCode()); Serial.print(" "); for (int i=0; i < NMEA0183Msg.FieldCount(); i++) { Serial.print(NMEA0183Msg.Field(i)); if ( i<NMEA0183Msg.FieldCount()-1 ) Serial.print(" "); } Serial.print("\n"); } }`

alikhan968 commented 10 months ago

Now if i use RS422 to TTL shield, the connection are like that. image `

include

SoftwareSerial myserial(2,3);

void setup() { Serial.begin( 38400/, SERIAL_8N1 default /); // Serial Monitor, 1.0Mbps myserial.begin(4800); // Serial1.begin( 4800, SERIAL_8N1 / default /); // UBLOX GPS Module

while(!Serial); }

void loop() {

char character;

while(myserial.available() /&& sentence_status != SentenceStatus::completed/) { character = myserial.read(); Serial.println(character);

}
} ` If i use above code then i see on the serial monitor continues this data. image If i use your example code, nothing display on serial monitor.

ttlappalainen commented 10 months ago

In your second picture you are feeding data to pin 3, but on code definition that is define as tx pin instead of rx pin.

Also on NMEA0183 code Serial baud rate has been set to 9600. On you working example you have 38400. So which baudrate you use on serial monitor 38400 or 9600? If you use 38400, you have to also have Serial.begin(38400);

alikhan968 commented 10 months ago

Yes, Arduino TX will be module RX and vice versa. So in the 2nd picture, PIN 3 should connect with RX of the module. Correct? I used both baud rate according to the respective code. For my example, I used 38400 and for your code, i used 9600. Sorry for the confusion.

alikhan968 commented 10 months ago

image

alikhan968 commented 10 months ago

Sorry, you were right. I shuffled pins and start getting serial non garbage data now. I try you example and see how it works.

alikhan968 commented 10 months ago

Yes it worked. Thanks a lot. It's so weird that i was making that simple mistake. Thanks again

ttlappalainen commented 10 months ago

My original list: you need to check your hw, wireing, baudrate you use on serial monitor, baudrate your device uses etc.

alikhan968 commented 10 months ago

I actually found the reason. It is wrong printing on module board.

Littlechay commented 10 months ago

Wrong printing? Are you sure? You are effectively creating one DTE/DCE imagine all your modules in one box which then has a serial interface. Tx and Rx refer to that external interface not to inter module connections. Get Outlook for Android

alikhan968 commented 10 months ago

Yes i am sure. the printing is supposed to be for this board but not for external wiring. If it says RX then TX external wire should connect with this pin. This is the standard. For example FTDI board. image

Littlechay commented 10 months ago

No; you misunderstand. It depends on whether the device is DTE or DCE. On the example you posted above of the module with the DB9 connector on the Tx and Rx refer to the direction on the DB9 not the in/out direction on the side facing the MCU. The in/out direction will be opposite to your logic, in this case. I attach a quick drawing to help explain.. But TLDR Rx connects to Rx and Tx to Tx.


From: alikhan968 @.> Sent: Thursday, 11 January 2024 9:59 am To: ttlappalainen/NMEA0183 @.> Cc: Littlechay @.>; Comment @.> Subject: Re: [ttlappalainen/NMEA0183] Basic Issue (Issue #55)

Yes i am sure. the printing is supposed to be for this board but not for external wiring. If it says RX then TX external wire should connect with this pin. This is the standard. For example FTDI board. image.png (view on web)https://github.com/ttlappalainen/NMEA0183/assets/81488667/ef8b3550-eaad-40e0-b55f-16c853b2e0ed

— Reply to this email directly, view it on GitHubhttps://github.com/ttlappalainen/NMEA0183/issues/55#issuecomment-1885722021, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFHSMUCPASFXBK24665WEIDYN36LJAVCNFSM6AAAAABAWSTMXKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBVG4ZDEMBSGE. You are receiving this because you commented.Message ID: @.***>

alikhan968 commented 10 months ago

Got it. Thanks a lot for all this valuable information. It helped me a lot.Thanks to both of you guys.