TinyGPS doent encode my data

Hey guys. I use an EM408 gps module.

I tried code to see if i can talk to it and i succesfully receive serial data from it.

The problem is when i use gps.encode function. For some reason, for me this doesnt return true
For example, this is my code:

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


#define GPS_RX_PIN 2
#define GPS_TX_PIN 3

TinyGPS gps;
SoftwareSerial ss(GPS_RX_PIN, GPS_TX_PIN);

void setup()
{
  Serial.begin(9600);
  ss.begin(4800); 
  }
  
void loop()
{
  while (ss.available())
  {
    char c = byte(ss.read());
    // Here i tried Serial.write(c); and i succesully saw the NMEA data in my serial monitor
    if (gps.encode(c))
    {
      long lat, lon;
     unsigned long fix_age;
    gps.get_position(&lat, &lon, &fix_age);
    if (fix_age == TinyGPS::GPS_INVALID_AGE )
      Serial.println("No fix ever detected!");
    else if (fix_age > 2000)
      Serial.println("Data is getting STALE!");
    else
      Serial.println("Latitude and longitude valid!");
      
      Serial.print("Lat: "); 
      Serial.print(lat);
      Serial.print(" Lon: "); 
      Serial.println(lon);
      
    }
    else Serial.println("Not encoded data!");
  }
}

With this code i constantly receive “No data!” string.

Why gps.encode(c) doesnt return true?

Hi nikolakos

int c = byte(ss.read());

Try changing this to:

char c = ss.read();

Regards

Ray

Wow, such an obvious mistake…

But still i get “Not encoded data!” reply, which means gps.encode didnt return true…

According to the em408 data sheet the RX PIN affects the gps output:

This is the main receive channel for receiving software commands to the engine board from SiRfDemo software or from user-written software. (NOTE: When not in use this pin must be kept “HIGH” for operation. From Vcc connect a 470 Ohm resistor in series with a 3.2v Zener diode to Ground. Then, connect the Rx input to Zener’s cathode to pull the input “HIGH”.)

The only other thing off the top of my head is the baud rate, but the default is 4800, so unless you changed it, it should still be 4800.

Hope you get it figured out.

Baud rate is fine and the thing with the RX pin is totally irrelevant. I am having the gps RX pin on the air and there is no problem at all, because as u can see in my code, there is a comment.... When i checked on my serial monitor to see if i get data, i do get NMEA data from gps.

The problem is when i use gps.encode, it returns false...

Could you copy and paste some of the NMEA data you see from the Serial.write statement?

I guess you will have to comment out (temporarily) the "Not encoded data" print statement, otherwise that will appear after each character received.

Have you tried the example sketches for the TinyGPS library?

Yes, i have tried the example code and yet again i have problems with gps.encode Here is what i got when i tried Serial.Write(c);

$GPGGA,223039.380,,,,,0,00,,,M,0.0,M,,0000*54
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,223039.380,V,,,,,,,050614,,*2B
$GPGGA,223040.383,,,,,0,00,,,M,0.0,M,,0000*59
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,223040.383,V,,,,,,,050614,,*26
$GPGGA,223041.375,,,,,0,00,,,M,0.0,M,,0000*51
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,223041.375,V,,,,,,,050614,,*2E
$GPGGA,223042.375,,,,,0,00,,,M,0.0,M,,0000*52
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,3,1,12,20,00,000,,10,00,000,,31,00,000,,27,00,000,*7C
$GPGSV,3,2,12,19,00,000,,07,00,000,,04,00,000,,24,00,000,*76
$GPGSV,3,3,12,16,00,000,,28,00,000,,26,00,000,,29,00,000,*78
$GPRMC,223042.375,V,,,,,,,050614,,*2D
$GPGGA,223043.379,,,,,0,00,,,M,0.0,M,,0000*5F
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,223043.379,V,,,,,,,050614,,*20
$GPGGA,223044.379,,,,,0,00,,,M,0.0,M,,0000*58
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,223044.379,V,,,,,,,050614,,*27
$GPGGA,223045.378,,,,,0,00,,,M,0.0,M,,0000*58
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,223045.378,V,,,,,,,050614,,*27

Valid NMEA data. Why doesnt gps.encode(c) doesnt return true is beyond me....

I guess you will have to comment out (temporarily) the "Not encoded data" print statement, otherwise that will appear after each character received.

I have put that line only for debbuging purposes. If i remove it i get nothing at all on my serial monitor...

GPS data has a checksum after the * on those NEMA lines. If that checksum isn't correct, then what might look like a valid NEMA line isn't.

But looking at the output, I doubt the checksum is the problem.

The $GPGSV is missing the SNR information, nulls usually indicate the GPS isn't tracking. The $GPGGA lines indicate no fix on any satellite. Otherwise you'd see a time, long, lat and a GPS fix. There's way too much missing information from the GPS module to do anything with.

Maybe the GPS needs a clear line of sight to the sky to pick up a signal if you're using it indoors.

Ok here are the updates!

First of all, thanks for the reply! You were right, no LOS with satellites, but since i was getting data from gps module, and i know nothing about NMEA, i was erroneously assuming i'm ok.

So now i have another problem...

Look at my output:

No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
No data!
Latitude and longitude valid!
Lat: 32758239
 Lon: 15637489
No data!
No data!
No data!
No data!
No data!
No data!
No data!

And i continue getting No data! forever afterwards! I checked the raw serial data i get from my gps and they are ok and continuous!!

  1. Why is that? Why do i only get valid gps data only one time? If you see my code, that means that gps.encode() always return false except one time. Any clues why is that?
  2. If i find no solution i will have to modify the code so whenever i get valid gps data, they are assigned to variables
  3. Look at my longitude/latidude data. Is this a valid format?

Thanks a ton!

EDIT: Actually, after several tests, the above outcome is the best... Most times i get "No data!" forever!... So once again, i have problem with gps.encode() function not returning true for some reason

Okay so you actually got a lock on a satellite. Once. You got that GPS module inside a metal box that blocks all the incoming signals?... :D

Could be the GPS needs an external antenna?

Without seeing the GPS output, which you say is fine, but if it's not working, indicates it's not fine. Here's the list of NEMA messages. Compare those against what you see coming from the GPS. If you see too many commas without values, you're still not getting a valid fix on a sat.

http://aprs.gids.nl/nmea/

BTW: when you power up these GPS units it can take up to a minute for them to find and lock on a sat signal. So don't get in a hurry right off the bat.