06 - Project: Decoding Using TinyGPS

## Lab: Decoding NMEA Data with TinyGPS++ Parse raw NMEA sentences into usable data using the TinyGPS++ library. **Background:** NMEA (National Marine Electronics Association) is a text-based protocol for GPS data (e.g., $GPGGA for position, $GPRMC for recommended minimum data). TinyGPS++ is an object-oriented parser. **Installation:** In UNO R3 IDE Library Manager, search "TinyGPSPlus by Mikal Hart" and install. ![](https://cdn.shopify.com/s/files/1/0331/9994/7908/files/tinnygpsplus_78f8f5c0-da40-4d85-9b7b-3059c5fe24dc.png?v=1754007306) **Required Hardware:** Same as UNO R3 serial experiment. **Wiring:** Same as before. **Code:** ```cpp #include #include #include #define RX 2 #define TX 3 #define GPS_BAUD 9600 SoftwareSerial ss(RX, TX); TinyGPSPlus gps; // Create TinyGPSPlus object void setup() { Serial.begin(9600); ss.begin(GPS_BAUD); } void loop() { while (ss.available() > 0) { char gpsData = ss.read(); if (gps.encode(gpsData)) { displayInfo(); } } } void displayInfo() { if (gps.location.isValid()) { Serial.print("Location: "); Serial.print(gps.location.lat(), 6); Serial.print(", "); Serial.println(gps.location.lng(), 6); } if (gps.date.isValid()) { Serial.print("Date: "); Serial.print(gps.date.month()); Serial.print("/"); Serial.print(gps.date.day()); Serial.print("/"); Serial.println(gps.date.year()); } if (gps.time.isValid()) { Serial.print("Time: "); Serial.print(gps.time.hour()); Serial.print(":"); Serial.print(gps.time.minute()); Serial.print(":"); Serial.print(gps.time.second()); Serial.print("."); Serial.println(gps.time.centisecond()); } } ``` **Code Explanation:** - `gps.encode(gpsData)`: Accumulates characters; returns true on complete sentence. - Validation: `isValid()` checks data integrity. - Extraction: `lat()`, `lng()`, `hour()`, etc., retrieve parsed values. **Results:** Serial Monitor shows latitude/longitude, date, time (UTC). Convert to local time by adding offset (e.g., +11 for Sydney). ![](https://cdn.shopify.com/s/files/1/0331/9994/7908/files/tinygps-output.png?v=1754007310) ![](https://cdn.shopify.com/s/files/1/0331/9994/7908/files/google-map_1.png?v=1754007315) **Tips:** Paste coordinates into Google Maps for verification. **Related Information:** NMEA sentences can be customized; for advanced parsing, explore MicropyGPS for Python alternatives.