Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Issue #55

Open
alikhan968 opened this issue Dec 15, 2023 · 25 comments
Open

Basic Issue #55

alikhan968 opened this issue Dec 15, 2023 · 25 comments

Comments

@alikhan968
Copy link

alikhan968 commented Dec 15, 2023

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 <StandardCplusplus.h>
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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

alikhan968 commented Dec 17, 2023

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

You may have:

  • Wrong pins on host side
  • Different baud rates
  • Broken board serial inputs
  • Loose connection
  • etc.

@alikhan968
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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 <NMEA0183.h>
#include <NMEA0183Msg.h>
#include <NMEA0183Messages.h>

// 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.h>

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
Copy link
Author

Now if i use RS422 to TTL shield, the connection are like that.
image
`
#include <SoftwareSerial.h>
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
Copy link
Owner

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
Copy link
Author

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
Copy link
Author

image

@alikhan968
Copy link
Author

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
Copy link
Author

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

@ttlappalainen
Copy link
Owner

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

@alikhan968
Copy link
Author

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

@Littlechay
Copy link

Littlechay commented Jan 10, 2024 via email

@alikhan968
Copy link
Author

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
Copy link

Littlechay commented Jan 11, 2024 via email

@alikhan968
Copy link
Author

alikhan968 commented Jan 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants