SkyLab GPS programing problem


I have GPS programing question.

I am using the SkyLab GPS, UNO, Arduino 1.0, Serial pins 2 and 3

So far this is a rather impressive GPS for under $30 on ebay

Skylab GPS info here.


I copied the following code from another website and updated some of the code (changed NewSoftSerial to SoftwareSerial for example) but I can only get the latitude and longitude to run correctly. The Time section (here greyed out with /* and */ ) does not compile. I get this line highlighted

year = date % 100;

and the message

‘year’ was not declared in this scope

and similar messages for ‘month’, ‘day’, ‘hour’ etc

Is there a list of error codes somewhere that helps decipher these error messages ?

or can anyone help on this

#include <SoftwareSerial.h>

#include <TinyGPS.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(){
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);
// time in hh:mm:ss, date in dd/mm/yy
/*gps.get_datetime(&date, &time, &fix_age);
year = date % 100;
month = (date / 100) % 100;
day = date / 10000;
hour = time / 1000000;
minute = (time / 10000) % 100;
second = (time / 100) % 100;
Serial.print(“Date: “);
Serial.print(year); Serial.print(”/”);
Serial.print(month); Serial.print("/");
Serial.print(" :: Time: “);
Serial.print(hour); Serial.print(”:");
Serial.print(minute); Serial.print(":");
Serial.print("Latitude : “);
Serial.print(” :: Longitude : ");
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)
bool feedgps(){
while (GPS.available())
if (gps.encode(
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

'year' was not declared in this scope

If you separate the phrase "was not declared" from "in this scope", does it help you understand that you have NOT declared year as a variable anywhere?


Thank you, Paul

I changed this line

unsigned long chars;

to this

unsigned long chars, year, month, day, hour, minute , second;

And it works -- I am not sure if that is the best way to do this however

but I am pretty happy at this point

Thank you


It is within one second of cell phone time

this makes me smile

Think about the range of values that those variables need to hold. year - could be anything, but will probably be less than 5000 for quite a while, unless a new calendar is invented month - 1 to 12, unless... day - 1 to 31, unless... hour - 0 to 24, unless... minute - 0 to 60, unless... second - 0 to 60, unless...

The likelihood of a new calendar is pretty slim, and probably would require other changes, anyway.

So, do you really need an unsigned long to hold those values? Ints would take up half as much space.

While it might not matter in this sketch, it is a good habit to develop to properly size variables.