2

I have written this little snippet of code to interface with EM408 GPS.

#include <SoftwareSerial.h>
SoftwareSerial GPS = SoftwareSerial(2,3); //rx,tx
void setup()
{
 GPS.begin(4800);
 Serial.begin(9600);
}
void loop()
{
 //Serial.print(GPS.read(), BYTE);
 Serial.write(byte(GPS.read())); //as of Arduino 1.0
}

Hardware side i have these connections:
ENABLE: 3.3V
Vcc : 3.3V
Ground: Ground
Rx, Tx correctly connected to arduino and correctly initialized with SoftwareSerial

However, the values i get are just junk data

ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

I get these without ending... I experimenting with changing the baud rate, still the same thing goes on. Any ideas?

EDIT:
I used to get random junk data before with the EM406 gps module, but i solved it by casting everything to BYTE. I have tried both approaches here, but the results are the same...

asked May 19, 2014 at 18:36
6
  • what about Serial.write((byte)(GPS.read()));? Commented May 19, 2014 at 18:37
  • just the same result.... Commented May 19, 2014 at 18:39
  • related: electronics.stackexchange.com/questions/110699/… Commented May 19, 2014 at 18:48
  • 1
    The datasheet indicates that the communications port is "TTL Levels", which usually means that the data is inverted relative to normal RS-232 levels. If you are connecting to a true RS-232 port on the Arduino, you will need to invert the signals to/from the GPS module. Commented May 19, 2014 at 18:54
  • What Arduino model do you use? Commented May 20, 2014 at 5:04

1 Answer 1

2

The problem you get is that read() does not wait for a byte to be available, it just returns -1 if there is no byte available; converted as an unsigned byte that becomes 255.

In ISO-8859-1, which I guess is the encoding that your serial monitor is using, 255 translates to ÿ, so this is exactly what you observe.

Fixing this problem is straightforward, just check that a byte is available on SoftwareSerial before reading it:

void loop()
{
 if (GPS.available()) {
 Serial.write(byte(GPS.read())); //as of Arduino 1.0
 }
}
answered May 19, 2014 at 19:15
3
  • Thanks, but when i use this method, i receive nothing at all, with all baud rates combination and independent of time passed... Commented May 19, 2014 at 19:42
  • If you receive nothing, that may come from your wiring: voltage level, crossed connections, short-circuit... Commented May 19, 2014 at 19:59
  • 1
    Note that in your current code, you don't receive either, as I have explained, if ÿ is the only thing you get, it means your GPS stream never receives anything... Commented May 19, 2014 at 20:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.