Problem in getting GPS data

Hello,

I am using a GPS module (SKylab SKM53) with Arduino UNO to get location data. This is the code I use to read gps data

/*
This Sketch will run with the SkyNav SKM53 GPS 
 RXD Arduino Pin 3
 TXD Arduino Pin 2
 RST Leave Open 
 NC Leave Open
 GND Ground
 VCC +5
 Make sure you download and save to your Arduino/Libraries folder TinyGPS.h
 and NewSoftSerial.h files.
*/

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

unsigned long fix_age;

SoftwareSerial GPS(2,3);
TinyGPS gps;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
long lat, lon;
float LAT, LON;

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

void loop(){
  long lat, lon;
  unsigned long fix_age, time, date, speed, course;
  unsigned long chars;
  unsigned short sentences, failed_checksum;

  // retrieves +/- lat/long in 100000ths of a degree
  gps.get_position(&lat, &lon, &fix_age);

  getGPS();
  Serial.print("Latitude : ");
  Serial.print(LAT/100000,7);
  Serial.print(" :: Longitude : ");
  Serial.println(LON/100000,7);
  
   }

void getGPS(){
  bool newdata = false;
  unsigned long start = millis();
  // Every 1 seconds we print an update
  while (millis() - start < 1000)
  {
    if (feedgps ()){
      newdata = true;
    }
   
  }
  if (newdata)
  {
    gpsdump(gps);
  }
}

bool feedgps(){
  while (GPS.available())
  {
    if (gps.encode(GPS.read()))
      return true;
  }
  return 0;
}

void gpsdump(TinyGPS &gps)
{
  //byte month, day, hour, minute, second, hundredths;
  gps.get_position(&lat, &lon);
  LAT = lat;
  LON = lon;
  {
    feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
  }
}

Unfortunately, the gps.encode() function never returns true even though the module is sending proper NMEA data like this:

$GPGGA,002349.038,8960.0000,N,00000.0000,E,0,0,,137.0,M,13.0,M,,44
$GPGSA,A,1,,,,,,,,,,,,,,,1E
$GPGSV,1,1,00
79
$GPRMC,002349.038,V,8960.0000,N,00000.0000,E,0.00,0.00,060180,,,N
79

As a result, the lattitude and longitude displayed is always ZERO. Please help...

That getGPS() function looks pretty hokey. There is data available, or there isn't. Waiting one second, in the hopes that some shows up, is silly.

getGPS() should be deleted. The call to it should call feedgps() instead. Then, add a test for whatever interval you want, and call gpsdump() when that interval has elapsed.

Thanks. I made the changes you suggested but its still not working. Here's the new code :

/*
This Sketch will run with the SkyNav SKM53 GPS 
 RXD Arduino Pin 3
 TXD Arduino Pin 2
 RST Leave Open 
 NC Leave Open
 GND Ground
 VCC +5
 Make sure you download and save to your Arduino/Libraries folder TinyGPS.h
 and NewSoftSerial.h files.
*/

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

unsigned long fix_age;

SoftwareSerial GPS(2,3);
TinyGPS gps;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
long lat, lon;
float LAT, LON;

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

void loop(){
  long lat, lon;
  unsigned long fix_age, time, date, speed, course;
  unsigned long chars;
  unsigned short sentences, failed_checksum;

  // retrieves +/- lat/long in 100000ths of a degree
  gps.get_position(&lat, &lon, &fix_age);

  bool newdata= false;
  unsigned long start = millis();
  // Every 1 seconds we print an update
  while (millis() - start < 1000)
  {
    if(feedgps())
      newdata = true;
  }
  
  if(newdata)
    gpsdump(gps);
  Serial.print("Latitude : ");
  Serial.print(LAT/100000,7);
  Serial.print(" :: Longitude : ");
  Serial.println(LON/100000,7);
  
}

bool feedgps(){
  while (GPS.available())
  {
    if (gps.encode(GPS.read()))
      return true;
  }
  return 0;
}

void gpsdump(TinyGPS &gps)
{
  //byte month, day, hour, minute, second, hundredths;
  gps.get_position(&lat, &lon);
  LAT = lat;
  LON = lon;
  {
    feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
  }
}

I also modified the feedgps() function to print the GPS data. It prints NMEA strings on the serial monitor but the gps.encode() function never returns true.

feedgps() function:

bool feedgps(){
  while (GPS.available())
  {
    char c = GPS.read();
    Serial.print(c);
    if (gps.encode(c))
      return true;
  }
  return 0;
}

Serial Monitor:

$GPGGA,232851.245,8960.0000,N,00000.0000,E,0,0,,137.0,M,13.0,M,,4F
$GPGSA,A,1,,,,,,,,,,,,,,,1E
$GPGSV,1,1,00
79
$GPRMC,232851.245,V,8960.0000,N,00000.0000,E,0.00,0.00,200413,,,N
79
Latitude : 0.0000000 :: Longitude : 0.0000000

How do I make it work? Any alternatives? also tried the sample code that comes with TinyGPS library but same problem :frowning:

  // Every 1 seconds we print an update
  while (millis() - start < 1000)
  {
    if(feedgps())
      newdata = true;
  }

What this comment says and what the code does are two completely different things.

Get rid of every bit of the timing stuff until you reliably get data from the GPS. The GPS only sends out data periodically.

long lat, lon;
float LAT, LON;

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

void loop(){
  long lat, lon;

The number of times where local and global variables of the same name are a good idea can be counted on one hand of a double amputee. Knock it off.