Skip to content

GPS Test

GpsTest.ino connects to the optional GPS module and prints location and time data it provides via USB Serial. If there is Serial output, it should work. The module can take several minutes to get a good connection and locate you.
You might have to go outside for it to work.

GpsTest.ino
#define GPS_RX 43
#define GPS_TX 44
#define GPS_BAUD 9600
#include <TinyGPSPlus.h>
#include <HardwareSerial.h>
TinyGPSPlus gps;
HardwareSerial GPSSerial(1);
void setup() {
Serial.begin(115200);
while(!Serial) delay(100);
Serial.println("STARTED!");
GPSSerial.begin(GPS_BAUD, SERIAL_8N1, GPS_TX, GPS_RX);
}
void displayInfo() {
//Serial.println("==========");
Serial.print(F("Location: "));
if (gps.location.isValid()) {
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
} else {
Serial.print(F("INVALID"));
}
Serial.print(F(" Date/Time: "));
if (gps.date.isValid()) {
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
} else {
Serial.print(F("INVALID"));
}
Serial.print(F(" "));
if (gps.time.isValid()) {
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
} else {
Serial.print(F("INVALID"));
}
Serial.println();
//Serial.println("==========");
}
void loop() {
while (GPSSerial.available() > 0) {
char c = GPSSerial.read();
//Serial.print(c);
if (gps.encode(c)) displayInfo();
}
}