TinyGPS's encode() not returning true

Hi guys,

this is my first post. I'll make sure to do it right. :slight_smile:

I am using an EM406A GPS module, a Sparkfun GPS shield and an Arduino UNO setup. And just to see if it can run the simplest example, I ran the code:

void setup()
{
  Serial.begin(4800);
}
void loop()
{
  byte a;
  if ( Serial.available() > 0 )
  {
    a = Serial.read();
    Serial.write(a);
  }
}

And the output was as follows:

$GPGGA,115228.000,3543.9110,N,14005.2443,E,1,08,1.3,133.2,M,39.3,M,,000058
$GPGSA,A,3,07,08,01,32,19,20,09,03,,,,,2.5,1.3,2.2
38
$GPRMC,115228.000,A,3543.9110,N,14005.2443,E,0.43,235.05,140514,,,A69
$GPGGA,115229.000,3543.9104,N,14005.2441,E,1,08,1.3,135.7,M,39.3,M,,0000
5D
$GPGSA,A,3,07,08,01,32,19,20,09,03,,,,,2.5,1.3,2.238
$GPGSV,3,1,12,01,78,295,27,11,68,025,,32,45,115,20,28,41,314,17
7C
$GPGSV,3,2,12,19,38,074,17,20,35,170,32,08,30,251,31,03,29,095,1571
$GPGSV,3,3,12,09,24,262,31,07,19,223,32,27,11,093,,17,08,288,7F
$GPRMC,115229.000,A,3543.9104,N,14005.2441,E,0.35,220.25,140514,,,A
68
$GPGGA,115230.000,3543.9098,N,14005.2439,E,1,08,1.3,138.4,M,39.3,M,,0000
50
$GPGSA,A,3,07,08,01,32,19,20,09,03,,,,,2.5,1.3,2.238
$GPRMC,115230.000,A,3543.9098,N,14005.2439,E,0.22,206.71,140514,,,A
68
$GPGGA,115231.000,3543.9092,N,14005.2436,E,1,08,1.3,140.8,M,39.3,M,,000057
$GPGSA,A,3,07,08,01,32,19,20,09,03,,,,,2.5,1.3,2.2
38
$GPRMC,115231.000,A,3543.9092,N,14005.2436,E,0.29,1.67,140514,,,A65
$GPGGA,115232.000,3543.9086,N,14005.2431,E,1,08,1.3,143.3,M,39.3,M,,0000
5E
$GPGSA,A,3,07,08,01,32,19,20,09,03,,,,,2.5,1.3,2.238
$GPRMC,115232.000,A,3543.9086,N,14005.2431,E,0.98,240.42,140514,,,A
6E
$GPGGA,115233.000,3543.9079,N,14005.2425,E,1,08,1.3,146.0,M,39.3,M,,00005C
$GPGSA,A,3,07,08,01,32,19,20,09,03,,,,,2.5,1.3,2.2
38
$GPRMC,115233.000,A,3543.9079,N,14005.2425,E,1.39,235.73,140514,,,A60
$GPGGA,115234.000,3543.9073,N,14005.2421,E,1,08,1.3,148.3,M,39.3,M,,0000
58
$GPGSA,A,3,07,08,01,32,19,20,09,03,,,,,2.5,1.3,2.238
$GPGSV,3,1,12,01,78,295,27,11,68,025,,32,45,115,19,28,41,314,19
78
$GPGSV,3,2,12,19,38,074,16,20,35,170,32,08,30,251,26,03,29,095,15*76
$GPGSV,3,3,12,09,24,262,31,07,19,223,26,27,11,093,,17,08,288,7A
$GPRMC,115234.000,A,3543.9073,N,14005.2421,E,0.78,226.72,140514,,,A
6E

And if you look at the $GPRMC lines, you will see the letter A, indicating that A is for active and data is valid, V for void and data is not valid. So the data is valid and ready for processing.

I used the following code in order to print the Latitudes and Longitudes on the Serial Monitor:

#include <TinyGPS.h>

TinyGPS gps;

void getgps(TinyGPS &gps);

void setup()
{
  Serial.begin(4800);
}

void getgps(TinyGPS &gps)
{
  // Define the variables that will be used
  float latitude, longitude;
  // Then call this function
  gps.f_get_position(&latitude, &longitude);
  Serial.print("Lat: ");
  Serial.println(latitude, 5);
  Serial.print("Long: ");
  Serial.println(longitude, 5);
}

void loop()
{
  byte a;
  if ( Serial.available() > 0 ) // if there is data coming into the serial line
  {
    a = Serial.read(); // get the byte of data
    if(gps.encode(a)) // if there is valid GPS data...
    {
      getgps(gps); // then grab the data and display it
    }
    else
    {
      Serial.println("encode(a) doesn't return true");
    }
  }
}

Once I ran the code above, due to the encode function not returning true at all, the getgps() function can never be called. I took the hardware outside with a laptop to an area where there was a clear view of the sky and still it just doesn't work.

Any ideas as to why the encode function won't return true?

Thanks.

LOL...never mind guys. I had the wrong values for the RX and TX pin values in the code. How embarassing.