Arduino Uno and Ublox GPS Neo-6m getting weird characters

Hi,

I’ve been trying to extract the latitude and longitutde from the gps.
I do get the values but at the end i’m getting weird characters.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

TinyGPSPlus gps;

SoftwareSerial ss(10, 11);

void setup()
{
Serial.begin(115200);
ss.begin(9600);
//Serial.println(“GPS Start”);

}

void loop()
{
while (ss.available() > 0 )
{
if(gps.encode(ss.read()))
{
displayInfo();
}
}

/* if (gps.location.isUpdated())
{
/*Serial.println(“Latitude: “);
Serial.println(gps.location.lat(),6);
Serial.println(“Longtitude: “);
Serial.println(gps.location.lng(),6);
Serial.println(””);
Serial.println(””);
} */

}

void displayInfo()
{
Serial.print(F(“Location: “));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(”,”));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F(“INVALID”));
}

Serial.print(F(" Date/Time: “));
if (gps.date.isValid())
{
Serial.print(gps.date.month());
Serial.print(F(”/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else
{
Serial.print(F(“INVALID”));
}

Serial.print(F(" “));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F(“0”));
Serial.print(gps.time.hour());
Serial.print(F(”:"));
if (gps.time.minute() < 10) Serial.print(F(“0”));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F(“0”));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F(“0”));
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F(“INVALID”));
}

Serial.println();
}

Capture.PNG

When you check ss.available > 0 you test to see that at least one character is there to read. The whole sentence may not have arrived yet. You only know that the one character is there. When you call ss.read and nothing is there to read you get a -1 which prints as that funny y looking thing.

Instead, read the data into a char array and wait until you have the whole thing before you try to decode it.

Image embedded for our convenience:

608bb5f06f4e0c89e4fcee639c346756b12a7445.png

Technique described here.

  1. Please modify your post (under the More… button in the lower right) and put [code] at the beginning of the sketch, and [/code] at the end of the sketch,
...so it shows up

  inside this code window.
  1. Instead of attaching an image, you can just select the text in the Serial Monitor window, copy it (control-C), and then paste it into your post (control-V). Put it inside code tags, too. There’s a </> button that will insert tags for you. Also, if you select the code portion first, pressing that button will put tags around the code portion.

  2. What Arduino are you using?

  3. What pins are connected?

Regarding the data, it looks like there is corruption on the serial line. Those “ÿ” are value 255, so that looks like noise to me. Is anything connected to pins 0 or 1?

Cheers,
/dev

When you check ss.available > 0 you test to see that at least one character is there to read. The whole sentence may not have arrived yet. You only know that the one character is there. When you call ss.read and nothing is there to read you get a -1 which prints as that funny y looking thing.

That part is ok. ss.available() returns a signed integer, so zero when nothing is available, it returns -1, which should exit the loop.

Besides, the weird data is on printing (sending to Serial), not reading from ss.

Instead, read the data into a char array and wait until you have the whole thing before you try to decode it.

Actually, that's a very inefficient way to decode. It uses way more RAM, and the characters get copied and processed multiple times. :stuck_out_tongue: I have compared the processing speed and RAM usage of the two techniques. The Adafruit_GPS library waits for the whole thing, and has the worst numbers. All other libraries, including NeoGPS, decode the characters as they arrive. NeoGPS is the smallest and fastest. :slight_smile:

@janver, you could try the diagnostic program in my NeoGPS library, but I currently suspect a wiring issue. If you decide to try it, be sure to follow the Installation Instructions. The NeoGPS files should be copied to your sketch directory, not a Libraries subdirectory. NMEA.ino is a good example to start with. NMEAloc.ino is very close to your current sketch.

Cheers,
/dev

That part is ok. ss.available() returns a signed integer, so when nothing is available, it returns -1, which should exit the loop.

Please explain how.

int SoftwareSerial::available()
{
  if (!isListening())
    return 0;

  return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF;
}

The modulo function returns a number between 0 and _SS_MAX_RX_BUFF-1. The other possible return path does not return -1, either.

PaulS:
Please explain how [serial.available() returns -1]

Doh! I was thinking of read(), fixed above. The loop is ok, though.

Thanks,
/dev