GPS input makes no sense.

GPS input makes no sense.

I’ve hooked up a LS20033 gps receveiver to an Arduino UNO. Datasheet sensor:

VCC and VBackup to 3.3V
Ground to ground
TX (Data output, TTL Level) to Digital 2.
The code Ive used:

#include <SoftwareSerial.h>

SoftwareSerial GPS = SoftwareSerial (2,3);

void setup()
{
  GPS.begin(9600);
  Serial.begin(9600); 
}

void loop()
{
  Serial.write(GPS.read());
}

Everything seems te be working, but if I open the serial monitor, this comes out of the GPS:

H;Ì!%1YÎ3Ä¥	p!Îs?¡?¸?@ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ   ±KÌ?RBB¥ ¥)1ä
H;Ì!%1YÎ3Ä¥	p!Îs?¡?¸?@ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ   ?KÌ?R@B¥ ¥)1ä
H;Ì%%1YÎ3Ä¥	p!Îs?¡?¸?@ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ   ?KÌ?R@B¥ ¥)1ä
H;Ì%%1YÎ3Ä¥	p!Îs?¡?¸?@ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ   ?KÌ?R@B¥ ¥)1ä
H;?!¥1YÎ3Ä¥	p!Îs?¡?¸?@ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ   ?KÌ?R@B¥ ¥)1ä
H;?!¥1YÎ3Ä¥	p!Îs?¡?¸?@ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ   ?KÌ?R@B¥ ¥)1ä
H;?!¥1YÎ3Ä¥	p!Îs?¡?¸?@ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ   ?KÌ?R@B¥ ¥)1ä
H;?!¥1YÎ3Ä¥	p!Îs?¡?¸?@ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ   ±KÌ?RBB¥ ¥)1ä
H;?!¥1YÎ3Ä¥	p!Îs?¡?¸?@ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ   ±KÌ?RBB¥ ¥)1ä
(and so on)

Looks like ive decode it wrong, it should look like this:

$GPGLL,2503.6319,N,12136.0099,E,053740.000,A,A*52
$GPGLL,2503.6319,N,12136.0099,E,053740.000,A,A*52
$GPGLL,2503.6319,N,12136.0099,E,053740.000,A,A*52
$GPGLL,2503.6319,N,12136.0099,E,053740.000,A,A*52

Somebody got a clue what I should do?

You should wait for a character to become available before reading it.

Hi Awol,

Thank you for your reply. Maybe I should have mentioned that I don’t have any experience yet with Arduino. (However I have experience programming in other languages and PIC micro controllers)

I've changed the code to:

void loop()
{
  
  if (GPS.available() > 0) {
     Serial.write(GPS.read());
  }
}

The output looks different now, but it still doesn’t make sense to me:

H3Ü5%1YÎs?¥	p!Îs?¡?º?A   KÌ?R@B¥ ¥)1ä
H3Ü5%1YÎs?¥	p!Îs?¡?º?A   KÌ?R@B¥ ¥)1ä
H3?1%1YÎs?¥	p!Îs?¡?º?A   KÌ?R@B¥ ¥)1ä
H3?1%1YÎs?¥	p!Îs?¡?¸?@   KÌ?RBB¥ ¥)1ä
H3?1¥1YÎs?¥	p!Îs?¡?º?A   KÌ?RBB¥ ¥)1ä

What have I done wrong?

Also:

void loop()
{
  
  if (GPS.available()) {
     int inByte = GPS.read() ;
     Serial.write(inByte);
  }

}

gives no sense information:

?%¡(Q?ÏR?¡?¥<0PÇá?1X94?øä¤¡©0åã <0J8Ì;ÎB??!)?ä
?%¡(Q?ÏR?¡?¥<0PÇá?1?X94??䐤¡)1åã <0J8Ì;ÎB??!)?ä

I'd try doubling/halving your bit rate from the GPS, then I'd try an inversion.

Actually, I'd dig out my scope and figure what's wrong, but I'm guessing that's not an option for you.

I have no Scope :frowning:

Ive changed every possible boud rate with no luck. Then I tried to invert the byte with the folowing code:

void loop()
{  

    if (GPS.available())  {
    int incoming = GPS.read();
    byte inverted = incoming ^ 0xFF;
    Serial.write(inverted);
  }
}

Still scrambled output :frowning:

Okay, the problem is not the GPS module, Ive another one (same type), same garbage.

YESSSS!!!!!! FINALLY!

Ive compiled and uploaded a program that autodetects the boudrate, and used that boudrate to communicate with the module. Apperantly I've missed the 38400! Shame on me, you where right AWOL!

The used code to detect the GPS boudrate:

/*
 First stab at a auto baud rate detection function. This uses the pulseIn command
 to determine what speed an unknown serial link is running at. Detects and sets the standard baud
 rates supported by the Arduino IDE serial monitor. Uses character "U" as a test character

 I'm sure characters with multiple zero bits in a row may fake out proper detection. If data is
 garbled in the serial monitor then the auto baud rate function failed.

 This is just a demo sketch to show concept. After uploading the sketch, open the serial monitor
 and pick a random baud rate and then start sending U characters. The monitor will print out
 what baud rate it detected. It will default to 9600 baud if found a bit
 width too long for a standard rate used by the serial monitor. Not that as written, this is a
 'blocking' function that will wait forever if no character are being sent.

 Note that while the serial monitor has a 300 baud option, the Arduino hardware serial library
 does not seem to support that baud rate, at least for version 22, in my testing.

 By "retrolefty" 1/22/11
 */

int recPin = 2;  //the pin receiving the serial input data
long baudRate;   // global in case useful elsewhere in a sketch

void setup()
 {
  pinMode(recPin, INPUT);      // make sure serial in is a input pin
  digitalWrite (recPin, HIGH); // pull up enabled just for noise protection
  
   // Function finds a standard baudrate of either
                               // 1200,2400,4800,9600,14400,19200,28800,38400,57600,115200
                               // by having sending circuit send "U" characters.
                               // Returns 0 if none or under 1200 baud  
  Serial.begin(9600);

 }

void loop()
 {
  baudRate = detRate(recPin); 
  Serial.println();
  Serial.print("Detected baudrate at ");
  Serial.println(baudRate);
 }

long detRate(int recpin)  // function to return valid received baud rate
                          // Note that the serial monitor has no 600 baud option and 300 baud
                          // doesn't seem to work with version 22 hardware serial library
  {
  long baud, rate = 10000, x;
  for (int i = 0; i < 10; i++) {
      x = pulseIn(recpin,LOW);   // measure the next zero bit width
      rate = x < rate ? x : rate;
  }
  
  if (rate < 12)
      baud = 115200;
      else if (rate < 20)
      baud = 57600;
      else if (rate < 29)
      baud = 38400;
      else if (rate < 40)
      baud = 28800;
      else if (rate < 60)
      baud = 19200;
      else if (rate < 80)
      baud = 14400;
      else if (rate < 150)
      baud = 9600;
      else if (rate < 300)
      baud = 4800;
      else if (rate < 600)
      baud = 2400;
      else if (rate < 1200)
      baud = 1200;
      else
      baud = 0;  
   return baud;
  }