Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TinyGPS++/TinyGPS++.h>
- static const uint32_t GPSBaud = 4800;
- TinyGPSPlus gps;
- void setup()
- {
- Serial.begin(9600);
- Serial1.begin(GPSBaud);
- }
- void displayInfo()
- {
- 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.day());
- Serial.print(F("."));
- Serial.print(gps.date.month());
- Serial.print(F("."));
- Serial.print(gps.date.year());
- Serial.print(F("."));
- }
- 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();
- }
- void loop()
- {
- while (Serial1.available() > 0)
- {
- if (gps.encode(Serial1.read()))
- {
- displayInfo();
- }
- }
- if (millis() > 5000 && gps.charsProcessed() < 10)
- {
- Serial.println(F("No GPS detected: check wiring."));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement