#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); //int la = gps.location.lat() 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(4, 0); lcd.print(gps.location.lat(),6); lcd.setCursor(0, 1); lcd.print("LO:"); lcd.setCursor(4, 1); lcd.print(gps.location.lng(),6); } else { Serial.println("Location: Not Available"); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Location: N/A"); } // TO MONITOR 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.println(); Serial.println(); } }