Skip to content

Instantly share code, notes, and snippets.

@zerog2k
Created April 23, 2016 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerog2k/3ac7723c9387d847683258ba4baeaafc to your computer and use it in GitHub Desktop.
Save zerog2k/3ac7723c9387d847683258ba4baeaafc to your computer and use it in GitHub Desktop.
arduino sketch for tinygps lib with lcd shield. Adapted from http://www.dfrobot.com/wiki/index.php?title=GPS_Module_With_Enclosure_%28SKU:TEL0094%29
// adapted from http://www.dfrobot.com/wiki/index.php?title=GPS_Module_With_Enclosure_%28SKU:TEL0094%29
//
#include <TinyGPS.h>
#include <LiquidCrystal.h>
TinyGPS gps;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //LCD driver pins
int led = 13;
float lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;
//int year;
//byte month, day, hour, minute, second, hundredths;
void LAT(){ //Latitude state
lcd.setCursor(0,0); // set the LCD cursor position
lcd.print("LAT:");
lcd.print(lat, 4);
lcd.print(" ");
printf("LAT: %f\n", lat);
Serial.println(lat, 4);
}
void LON(){ //Longitude state
lcd.setCursor(0,1); // set the LCD cursor position
lcd.print("LON:");
lcd.print(lon, 4);
lcd.print(" ");
printf("LON: %f\n", lon);
Serial.println(lon, 4);
}
void setup()
{
Serial.begin(9600); //Set the GPS baud rate.
pinMode(led, OUTPUT);
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0); // set the LCD cursor position
lcd.print("GPS test"); // print a simple message on the LCD
delay(2000);
}
void loop()
{
while (Serial.available())
{
digitalWrite(led, HIGH);
char buf;
while (Serial.readBytesUntil('\n',&buf, 1) > 0) {
gps.encode(buf);
}
}
digitalWrite(led, LOW);
gps.f_get_position(&lat, &lon, &fix_age); // retrieves +/- lat/long in 100000ths of a degree
gps.get_datetime(&date, &time, &fix_age); // time in hhmmsscc, date in ddmmyy
//gps.crack_datetime(&year, &month, &day, //Date/time cracking
//&hour, &minute, &second, &hundredths, &fix_age);
LAT();
LON();
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment