#include // need this library #include #include #include #include // library 1.2.1 // Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity LiquidCrystal_I2C lcd(0x25, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); int b = 0; TinyGPSPlus gps; SoftwareSerial mojSerial(2, 7); void setup() { Serial.begin(9600); mojSerial.begin(9600); lcd.begin(16,2); lcd.backlight(); } void loop() { while (mojSerial.available()) if (gps.encode(mojSerial.read())) displayInfo(); if (millis() > 5000 && gps.charsProcessed() < 10) { Serial.println("No GPS detected"); lcd.clear(); lcd.setCursor(0, 0); lcd.print("No GPS detected"); while(true); } } void displayInfo() { if (gps.time.isUpdated()){ if (gps.time.second() == b) return; // PRINT VALUES EVERY 1 SEC if (gps.location.isValid()) { // TO MONITOR Serial.print("Latitude: "); Serial.println(gps.location.lat(), 6); Serial.print("Longitude: "); Serial.println(gps.location.lng(), 6); Serial.print("Altitude: "); Serial.println(gps.altitude.meters()); // TO LCD lcd.clear(); lcd.setCursor(0, 0); lcd.print("la:"); lcd.setCursor(3, 0); lcd.print(gps.location.lat(),2); lcd.setCursor(8, 0); lcd.print("lo:"); lcd.setCursor(11, 0); lcd.print(gps.location.lng(),2); } else { Serial.println("Location: Not Available"); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Location: N/A"); } Serial.print("Date: "); if (gps.date.isValid()) { Serial.print(gps.date.month()); Serial.print("/"); Serial.print(gps.date.day()); Serial.print("/"); Serial.println(gps.date.year()); } else { Serial.println("Not Available"); } Serial.print("Time: "); if (gps.time.isValid()) { //lcd.clear(); lcd.setCursor(0, 1); lcd.print("Time:"); lcd.setCursor(5, 1); if ((gps.time.hour() + 2) < 10) {Serial.print(F("0")); lcd.print("0");} Serial.print(gps.time.hour() + 2); Serial.print(":"); lcd.print((gps.time.hour() + 2)); lcd.setCursor(7, 1); lcd.print(":"); lcd.setCursor(8, 1); if (gps.time.minute() < 10){Serial.print(F("0")); lcd.print("0");} Serial.print(gps.time.minute()); Serial.print(":"); lcd.print(gps.time.minute()); lcd.setCursor(10, 1); lcd.print(":"); lcd.setCursor(11, 1); if (gps.time.second() < 10){Serial.print(F("0")); lcd.print("0");} Serial.print(gps.time.second()); Serial.print("."); b = gps.time.second(); lcd.print(gps.time.second()); if (gps.time.centisecond() < 10) Serial.print(F("0")); Serial.println(gps.time.centisecond()); } else { Serial.println("Not Available"); lcd.clear(); lcd.setCursor(1, 0); lcd.print("Time: N/A"); } Serial.println(); Serial.println(); } }