Hi all
I am currently working on getting iTead GPS output display on an LCD. The code I currently have will display latitude and longitude and the time it took to acquire the signal. I am having trouble writing the commands to display date, time, number of satelites, ect.
Also, I would like to know if it is possible to use the latitude and longitude to calculate distance traveled?
Attached is the sketch I am using to display latitude and longitude, I obtained it form the link below and simply modified it a bit.
In this sketch I use TinyGPS but I am willing to use TinyGPS++ if a sketch already exists or it is easier.
I thank you in advance
// GPS Setup
#include "TinyGPS.h"
#include <SoftwareSerial.h>
// LCD Setup
#include <LiquidCrystal_I2C.h>
#include "Wire.h"
// GPS pin connections
int RXPin = 2; //conntec to tx pin of the gps
int TXPin = 3; //conntect to RX pin of the gps
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
// GPS object
TinyGPS gps;
// LCD object
LiquidCrystal_I2C
lcd(0x3F,20,4);
// Start
long startMillis;
long secondsToFirstLocation = 0;
void setup()
{
ss.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(6,0);
lcd.print("Welcome");
delay(1000);
startMillis = millis();
}
void loop()
{
bool newData = false;
unsigned long chars = 0;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (ss.available())
{
int c = ss.read();
++chars;
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
if (newData)
{
// we have a location fix so output the lat / long and time to acquire
if(secondsToFirstLocation == 0){
secondsToFirstLocation = (millis() - startMillis) / 1000;
}
lcd.clear(); // start with a blank screen
float flat, flon;
unsigned long age, date, time;
gps.f_get_position(&flat, &flon, &age);
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
lcd.print("Lat:");
lcd.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
lcd.setCursor(0,1);
lcd.print("Long:");
lcd.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
lcd.setCursor(0,2);
lcd.print("Acquire Time:");
lcd.print(secondsToFirstLocation);
lcd.print("s");
lcd.setCursor(0,3);
lcd.print("It is");
//lcd.print(gps.date, gps.time);
}
if (chars == 0){
// if you haven't got any chars then likely a wiring issue
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
lcd.print("No GPS: check wiring");
}
else if(secondsToFirstLocation == 0){
// if you have received some chars but not yet got a fix then indicate still searching and elapsed time
lcd.clear(); // start with a blank screen
long seconds = (millis() - startMillis) / 1000;
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
lcd.print("Searching ");
for(int i = 0; i < seconds % 4; ++i){
lcd.print(".");
}
lcd.setCursor(0,1);
lcd.print("Elapsed time:");
lcd.print(seconds);
lcd.print("s");
}
}