Code: Select all
#include <HardwareSerial.h>
#include <TinyGPSPlus.h>
HardwareSerial GPSSerial (2);
TinyGPSPlus gps;
void setup()
{
Serial.begin(9600);
GPSSerial.begin ( 9600, SERIAL_8N1, 16, 17 ); // begin GPS hardware serial
}
void loop()
{
Serial.begin(9600);
// This sketch displays information every time a new sentence is correctly encoded.
while (GPSSerial.available() > 0)
if (gps.encode(GPSSerial.read()))
displayInfo();
if (millis() > 10000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
}
void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 9);
Serial.print(F(","));
Serial.print(gps.location.lng(), 9);
}
else
{
Serial.print(F("INVALID"));
}
}
CC