#include #include #include #include #include #define RXPIN 8 #define TXPIN 7 SoftwareSerial nss(RXPIN, TXPIN); TinyGPS gps; LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); void latlon2locator(float lat, float lon, String &loc){ int v; String locator = ""; lat += 90; lon += 180; locator += (char) ('A' + floor(lon / 20)); locator += (char) ('A' + floor(lat / 10)); lon = fmod(lon,20); if (lon < 0) lon += 20; lat = fmod(lat,10); if (lat < 0) lat += 10; locator += (char) ('0' + floor(lon / 2)); locator += (char) ('0' + floor(lat / 1)); lon = fmod(lon ,2); if (lon < 0) lon += 2; lat = fmod(lat, 1); if (lat < 0) lat += 1; locator += (char) ('A' + floor(lon * 12)); locator += (char) ('A' + floor(lat * 24)); loc = locator; } void setup(){ Serial.begin(9600); nss.begin(4800); lcd.begin(20,4); } void loop() { while (nss.available()) { int c = nss.read(); if (gps.encode(c)) { unsigned long speed, course; int year; byte month, day, hour, minute, second, hundredths; unsigned long fix_age; unsigned long chars; unsigned short sentences, failed_checksum; String loc = ""; String callsign = "AA0O"; float flat, flon; gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &fix_age); if(second == 0){ lcd.clear(); } int cur = 2; if(day > 9){ cur--; } if(month > 9){ cur--; } lcd.setCursor(cur,0); lcd.print(month); lcd.print("/"); lcd.print(day); lcd.print("/"); lcd.print(year); lcd.print(" "); if(hour < 10){ lcd.print("0"); } lcd.print(hour); lcd.print(":"); if(minute < 10){ lcd.print("0"); } lcd.print(minute); lcd.print(":"); if(second < 10){ lcd.print("0"); } lcd.print(second); lcd.setCursor(5,1); lcd.print("Call: "); lcd.print(callsign); // returns +/- latitude/longitude in degrees gps.f_get_position(&flat, &flon, &fix_age); lcd.setCursor(7,2); latlon2locator(flat,flon,loc); lcd.print(loc); lcd.setCursor(4,3); lcd.print(flat); lcd.print(","); lcd.print(flon); } } }