### Dynamic Initialization with begin() for TinyGPSCustom Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Use `begin()` to dynamically initialize TinyGPSCustom objects, which is useful for arrays of custom extractors. This example shows how to track satellite information from GPGSV sentences. ```cpp #include #include static const int RXPin = 4, TXPin = 3; TinyGPSPlus gps; SoftwareSerial ss(RXPin, TXPin); // Track up to 4 satellites per GSV sentence TinyGPSCustom satNumber[4]; TinyGPSCustom elevation[4]; TinyGPSCustom azimuth[4]; TinyGPSCustom snr[4]; void setup() { Serial.begin(115200); ss.begin(4800); // Initialize arrays dynamically using begin() // GPGSV sentence fields: 4,5,6,7 / 8,9,10,11 / 12,13,14,15 / 16,17,18,19 for (int i = 0; i < 4; i++) { satNumber[i].begin(gps, "GPGSV", 4 + 4 * i); // Sat PRN at 4,8,12,16 elevation[i].begin(gps, "GPGSV", 5 + 4 * i); // Elevation at 5,9,13,17 azimuth[i].begin(gps, "GPGSV", 6 + 4 * i); // Azimuth at 6,10,14,18 snr[i].begin(gps, "GPGSV", 7 + 4 * i); // SNR at 7,11,15,19 } } void loop() { while (ss.available() > 0) { gps.encode(ss.read()); // Print satellite info when updated for (int i = 0; i < 4; i++) { if (satNumber[i].isUpdated() && strlen(satNumber[i].value()) > 0) { Serial.print("Sat #"); Serial.print(satNumber[i].value()); Serial.print(" El:"); Serial.print(elevation[i].value()); Serial.print(" Az:"); Serial.print(azimuth[i].value()); Serial.print(" SNR:"); Serial.println(snr[i].value()); } } } } ``` -------------------------------- ### Monitor NMEA Parser Performance with Statistics Methods Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Track NMEA parsing statistics including character count, successful sentences, and checksum failures. This example prints statistics every 5 seconds. ```cpp #include #include TinyGPSPlus gps; SoftwareSerial ss(4, 3); void setup() { Serial.begin(115200); ss.begin(4800); Serial.print("TinyGPSPlus version: "); Serial.println(TinyGPSPlus::libraryVersion()); // Output: 1.1.0 } void loop() { while (ss.available() > 0) gps.encode(ss.read()); // Print statistics every 5 seconds static unsigned long lastPrint = 0; if (millis() - lastPrint > 5000) { lastPrint = millis(); Serial.print("Chars processed: "); Serial.println(gps.charsProcessed()); Serial.print("Sentences with fix: "); Serial.println(gps.sentencesWithFix()); Serial.print("Checksum passed: "); Serial.println(gps.passedChecksum()); Serial.print("Checksum failed: "); Serial.println(gps.failedChecksum()); // Calculate error rate unsigned long total = gps.passedChecksum() + gps.failedChecksum(); if (total > 0) { float errorRate = 100.0 * gps.failedChecksum() / total; Serial.print("Error rate: "); Serial.print(errorRate, 2); Serial.println("%"); } } } ``` -------------------------------- ### Access GPS Course/Heading with TinyGPS++ Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Demonstrates how to get the GPS course or heading in degrees and convert it to a cardinal direction (e.g., N, ENE, SW). Requires a valid RMC sentence with course data. ```cpp #include TinyGPSPlus gps; // RMC sentence with course of 65.02 degrees const char *gpsStream = "$GPRMC,045200.000,A,3014.3820,N,09748.9514,W,36.88,65.02,030913,,,A*77\r\n"; void setup() { Serial.begin(115200); while (*gpsStream) gps.encode(*gpsStream++); if (gps.course.isValid()) { Serial.print("Course (degrees): "); Serial.println(gps.course.deg(), 2); // Output: 65.02 // Convert to cardinal direction Serial.print("Direction: "); Serial.println(TinyGPSPlus::cardinal(gps.course.deg())); // Output: ENE } } void loop() {} ``` -------------------------------- ### Access Satellite Count with TinyGPS++ Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Demonstrates how to get the number of satellites currently being used for the GPS fix. This information is typically found in GGA sentences. ```cpp #include TinyGPSPlus gps; // GGA sentence with 9 satellites const char *gpsStream = "$GPGGA,045104.000,3014.1985,N,09749.2873,W,1,09,1.2,211.6,M,-22.5,M,,0000*62\r\n"; void setup() { Serial.begin(115200); while (*gpsStream) gps.encode(*gpsStream++); if (gps.satellites.isValid()) { Serial.print("Satellites in use: "); Serial.println(gps.satellites.value()); // Output: 9 } } void loop() {} ``` -------------------------------- ### Access GPS Altitude with TinyGPS++ Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Provides examples for retrieving GPS altitude in meters, feet, kilometers, and miles. This functionality relies on valid GGA sentences containing altitude information. ```cpp #include TinyGPSPlus gps; // GGA sentence with altitude of 211.6 meters const char *gpsStream = "$GPGGA,045104.000,3014.1985,N,09749.2873,W,1,09,1.2,211.6,M,-22.5,M,,0000*62\r\n"; void setup() { Serial.begin(115200); while (*gpsStream) gps.encode(*gpsStream++); if (gps.altitude.isValid()) { Serial.print("Altitude (m): "); Serial.println(gps.altitude.meters(), 2); // Output: 211.60 Serial.print("Altitude (ft): "); Serial.println(gps.altitude.feet(), 2); // Output: 694.23 Serial.print("Altitude (km): "); Serial.println(gps.altitude.kilometers(), 4); // Output: 0.2116 Serial.print("Altitude (mi): "); Serial.println(gps.altitude.miles(), 4); // Output: 0.1315 } } void loop() {} ``` -------------------------------- ### Alternative Character Input using Stream Operator Source: https://context7.com/mikalhart/tinygpsplus/llms.txt The stream insertion operator provides an alternative to `encode()` for feeding characters to the parser. This example demonstrates feeding a single NMEA sentence. ```cpp #include TinyGPSPlus gps; const char *gpsStream = "$GPRMC,045103.000,A,3014.1984,N,09749.2872,W,0.67,161.46,030913,,,A*7C\r\n"; void setup() { Serial.begin(115200); // Feed data using stream operator const char *p = gpsStream; while (*p) { gps << *p++; // Equivalent to gps.encode(*p++) } if (gps.location.isValid()) { Serial.print("Lat: "); Serial.println(gps.location.lat(), 6); } } void loop() {} ``` -------------------------------- ### courseTo() - Calculate Bearing to Destination Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Static method to calculate the initial bearing in degrees from one coordinate to another. ```APIDOC ## courseTo() - Calculate Bearing to Destination ### Description Static method that calculates the initial bearing in degrees from one coordinate to another (North=0, East=90, South=180, West=270). ### Method `TinyGPSPlus::courseTo(lat1, lon1, lat2, lon2)` ### Endpoint N/A (Library function) ### Parameters - **lat1** (double) - Latitude of the starting point. - **lon1** (double) - Longitude of the starting point. - **lat2** (double) - Latitude of the destination point. - **lon2** (double) - Longitude of the destination point. ### Request Example ```cpp #include TinyGPSPlus gps; void setup() { Serial.begin(115200); // Current position double myLat = 30.2367, myLon = -97.8215; // Destination double destLat = 30.2672, destLon = -97.7431; // Austin downtown // Calculate bearing double bearing = TinyGPSPlus::courseTo(myLat, myLon, destLat, destLon); Serial.print("Bearing to destination: "); Serial.print(bearing, 2); Serial.println(" degrees"); // Convert to cardinal direction Serial.print("Head "); Serial.println(TinyGPSPlus::cardinal(bearing)); // e.g., "NE" } void loop() {} ``` ### Response #### Success Response (200) - **courseTo()** (double) - The initial bearing in degrees from the first point to the second point. #### Response Example ``` Bearing to destination: 45.67 degrees Head NE ``` ``` -------------------------------- ### Calculate Bearing to Destination Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Use the static TinyGPSPlus::courseTo() method to calculate the initial bearing in degrees from one coordinate to another. North is 0 degrees. Requires the TinyGPS++ library. ```cpp #include TinyGPSPlus gps; void setup() { Serial.begin(115200); // Current position double myLat = 30.2367, myLon = -97.8215; // Destination double destLat = 30.2672, destLon = -97.7431; // Austin downtown // Calculate bearing double bearing = TinyGPSPlus::courseTo(myLat, myLon, destLat, destLon); Serial.print("Bearing to destination: "); Serial.print(bearing, 2); Serial.println(" degrees"); // Convert to cardinal direction Serial.print("Head "); Serial.println(TinyGPSPlus::cardinal(bearing)); // e.g., "NE" } void loop() {} ``` -------------------------------- ### Access GPS Time with TinyGPS++ Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Demonstrates how to extract and format UTC time components (hour, minute, second, centisecond) from GPS data. Ensure the GPS module is providing valid time information. ```cpp #include TinyGPSPlus gps; const char *gpsStream = "$GPGGA,045104.000,3014.1985,N,09749.2873,W,1,09,1.2,211.6,M,-22.5,M,,0000*62\r\n"; void setup() { Serial.begin(115200); while (*gpsStream) gps.encode(*gpsStream++); if (gps.time.isValid()) { // Get individual time components (UTC) Serial.print("Hour: "); Serial.println(gps.time.hour()); // Output: 4 Serial.print("Minute: "); Serial.println(gps.time.minute()); // Output: 51 Serial.print("Second: "); Serial.println(gps.time.second()); // Output: 4 Serial.print("Centisecond: "); Serial.println(gps.time.centisecond()); // Output: 0 // Formatted time with leading zeros char timeStr[13]; sprintf(timeStr, "%02d:%02d:%02d.%02d", gps.time.hour(), gps.time.minute(), gps.time.second(), gps.time.centisecond()); Serial.println(timeStr); // Output: 04:51:04.00 } } void loop() {} ``` -------------------------------- ### cardinal() - Convert Degrees to Cardinal Direction Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Static method to convert a heading in degrees to a 16-point compass cardinal direction string. ```APIDOC ## cardinal() - Convert Degrees to Cardinal Direction ### Description Static method that converts a heading in degrees to a 16-point compass cardinal direction string. ### Method `TinyGPSPlus::cardinal(degrees)` ### Endpoint N/A (Library function) ### Parameters - **degrees** (double) - The heading in degrees (0-360). ### Request Example ```cpp #include void setup() { Serial.begin(115200); // All 16 cardinal directions double headings[] = {0, 22.5, 45, 67.5, 90, 112.5, 135, 157.5, 180, 202.5, 225, 247.5, 270, 292.5, 315, 337.5}; for (int i = 0; i < 16; i++) { Serial.print(headings[i], 1); Serial.print(" deg = "); Serial.println(TinyGPSPlus::cardinal(headings[i])); } // Output: N, NNE, NE, ENE, E, ESE, SE, SSE, S, SSW, SW, WSW, W, WNW, NW, NNW } void loop() {} ``` ### Response #### Success Response (200) - **cardinal()** (string) - The 16-point compass cardinal direction string (e.g., N, NNE, NE, etc.). #### Response Example ``` 0.0 deg = N 22.5 deg = NNE 45.0 deg = NE ... 337.5 deg = NNW ``` ``` -------------------------------- ### Access GPS Speed with TinyGPS++ Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Shows how to retrieve and display GPS speed in various units: knots, mph, meters per second, and kilometers per hour. Requires a valid RMC sentence with speed data. ```cpp #include TinyGPSPlus gps; // RMC sentence with speed of 36.88 knots const char *gpsStream = "$GPRMC,045200.000,A,3014.3820,N,09748.9514,W,36.88,65.02,030913,,,A*77\r\n"; void setup() { Serial.begin(115200); while (*gpsStream) gps.encode(*gpsStream++); if (gps.speed.isValid()) { Serial.print("Speed (knots): "); Serial.println(gps.speed.knots(), 2); // Output: 36.88 Serial.print("Speed (mph): "); Serial.println(gps.speed.mph(), 2); // Output: 42.44 Serial.print("Speed (m/s): "); Serial.println(gps.speed.mps(), 2); // Output: 18.97 Serial.print("Speed (km/h): "); Serial.println(gps.speed.kmph(), 2); // Output: 68.31 } } void loop() {} ``` -------------------------------- ### Convert Degrees to Cardinal Direction Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Use the static TinyGPSPlus::cardinal() method to convert a heading in degrees to a 16-point compass cardinal direction string. Requires the TinyGPS++ library. ```cpp #include void setup() { Serial.begin(115200); // All 16 cardinal directions double headings[] = {0, 22.5, 45, 67.5, 90, 112.5, 135, 157.5, 180, 202.5, 225, 247.5, 270, 292.5, 315, 337.5}; for (int i = 0; i < 16; i++) { Serial.print(headings[i], 1); Serial.print(" deg = "); Serial.println(TinyGPSPlus::cardinal(headings[i])); } // Output: N, NNE, NE, ENE, E, ESE, SE, SSE, S, SSW, SW, WSW, W, WNW, NW, NNW } void loop() {} ``` -------------------------------- ### TinyGPSCustom - Extract Custom NMEA Fields Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Allows extraction of arbitrary fields from any NMEA sentence, including proprietary ones. ```APIDOC ## TinyGPSCustom - Extract Custom NMEA Fields ### Description The TinyGPSCustom class allows extraction of arbitrary fields from any NMEA sentence, including proprietary sentences. Define which sentence and field number to extract. ### Method `TinyGPSCustom(TinyGPSPlus &gps, const char *sentence, int field)` ### Endpoint N/A (Library class) ### Parameters - **gps** (TinyGPSPlus &) - Reference to the TinyGPSPlus object. - **sentence** (const char *) - The NMEA sentence identifier (e.g., "GPGSA"). - **field** (int) - The 1-indexed field number within the sentence to extract. ### Request Example ```cpp #include #include static const int RXPin = 4, TXPin = 3; static const uint32_t GPSBaud = 4800; TinyGPSPlus gps; SoftwareSerial ss(RXPin, TXPin); // Extract PDOP, HDOP, VDOP from $GPGSA sentence // Field numbers are 1-indexed from the sentence name TinyGPSCustom pdop(gps, "GPGSA", 15); // Position DOP TinyGPSCustom hdopCustom(gps, "GPGSA", 16); // Horizontal DOP TinyGPSCustom vdop(gps, "GPGSA", 17); // Vertical DOP void setup() { Serial.begin(115200); ss.begin(GPSBaud); Serial.println("Custom NMEA field extraction demo"); } void loop() { while (ss.available() > 0) gps.encode(ss.read()); // Check if any custom field was updated if (pdop.isUpdated() || hdopCustom.isUpdated() || vdop.isUpdated()) { Serial.print("PDOP="); Serial.print(pdop.value()); // Returns string value Serial.print(" HDOP="); Serial.print(hdopCustom.value()); Serial.print(" VDOP="); Serial.println(vdop.value()); // Check validity and age if (pdop.isValid()) { Serial.print("PDOP age: "); Serial.print(pdop.age()); Serial.println(" ms"); } } } ``` ### Response #### Success Response (200) - **value()** (string) - Returns the extracted field value as a string. - **isUpdated()** (bool) - Returns true if the field has been updated since the last check. - **isValid()** (bool) - Returns true if the extracted value is valid. - **age()** (unsigned long) - Returns the age of the data in milliseconds. #### Response Example ``` PDOP=1.2 HDOP=1.0 VDOP=0.8 PDOP age: 500 ms ``` ``` -------------------------------- ### distanceBetween() - Calculate Distance Between Two Points Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Static method to calculate the great-circle distance in meters between two coordinate pairs. ```APIDOC ## distanceBetween() - Calculate Distance Between Two Points ### Description Static method that calculates the great-circle distance in meters between two coordinate pairs using the Earth's mean radius. ### Method `TinyGPSPlus::distanceBetween(lat1, lon1, lat2, lon2)` ### Endpoint N/A (Library function) ### Parameters - **lat1** (double) - Latitude of the first point. - **lon1** (double) - Longitude of the first point. - **lat2** (double) - Latitude of the second point. - **lon2** (double) - Longitude of the second point. ### Request Example ```cpp #include TinyGPSPlus gps; void setup() { Serial.begin(115200); // Define two locations double lat1 = 40.7128, lon1 = -74.0060; // New York City double lat2 = 51.5074, lon2 = -0.1278; // London // Calculate distance in meters double distMeters = TinyGPSPlus::distanceBetween(lat1, lon1, lat2, lon2); Serial.print("NYC to London: "); Serial.print(distMeters / 1000.0, 2); Serial.println(" km"); // Output: ~5570 km // Practical example: distance to a destination double myLat = 30.2367, myLon = -97.8215; double destLat = 30.2672, destLon = -97.7431; // Austin downtown double distToAustin = TinyGPSPlus::distanceBetween(myLat, myLon, destLat, destLon); Serial.print("Distance to Austin downtown: "); Serial.print(distToAustin, 0); Serial.println(" meters"); // Output: ~8500 meters } void loop() {} ``` ### Response #### Success Response (200) - **distanceBetween()** (double) - The great-circle distance in meters between the two points. #### Response Example ``` NYC to London: 5570.23 km Distance to Austin downtown: 8500 meters ``` ``` -------------------------------- ### Access GPS Coordinates with location Source: https://context7.com/mikalhart/tinygpsplus/llms.txt The location object provides latitude and longitude in decimal degrees. Always check isValid() before accessing data to ensure a valid GPS fix. ```cpp #include TinyGPSPlus gps; // Sample NMEA data for testing without hardware const char *gpsStream = "$GPRMC,045103.000,A,3014.1984,N,09749.2872,W,0.67,161.46,030913,,,A*7C\r\n" "$GPGGA,045104.000,3014.1985,N,09749.2873,W,1,09,1.2,211.6,M,-22.5,M,,0000*62\r\n"; void setup() { Serial.begin(115200); // Process the test data while (*gpsStream) gps.encode(*gpsStream++); // Check if location is valid before using if (gps.location.isValid()) { // Get coordinates as double (decimal degrees) Serial.print("Latitude: "); Serial.println(gps.location.lat(), 6); // Output: 30.236640 Serial.print("Longitude: "); Serial.println(gps.location.lng(), 6); // Output: -97.821453 // Get raw data for high precision Serial.print("Raw Lat Degrees: "); Serial.println(gps.location.rawLat().deg); // Output: 30 Serial.print("Raw Lat Billionths: "); Serial.println(gps.location.rawLat().billionths); // Check data freshness (milliseconds since last update) Serial.print("Location age: "); Serial.print(gps.location.age()); Serial.println(" ms"); // Check if data was updated since last read if (gps.location.isUpdated()) { Serial.println("New location data available!"); } // Fix quality: Invalid, GPS, DGPS, PPS, RTK, FloatRTK, Estimated, Manual, Simulated Serial.print("Fix Quality: "); Serial.println((char)gps.location.FixQuality()); } else { Serial.println("Location: INVALID"); } } void loop() {} ``` -------------------------------- ### Extract Custom NMEA Fields Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Use the TinyGPSCustom class to extract arbitrary fields from NMEA sentences, including proprietary ones. Define the sentence and field number. Requires TinyGPS++ and SoftwareSerial libraries. ```cpp #include #include static const int RXPin = 4, TXPin = 3; static const uint32_t GPSBaud = 4800; TinyGPSPlus gps; SoftwareSerial ss(RXPin, TXPin); // Extract PDOP, HDOP, VDOP from $GPGSA sentence // Field numbers are 1-indexed from the sentence name TinyGPSCustom pdop(gps, "GPGSA", 15); // Position DOP TinyGPSCustom hdopCustom(gps, "GPGSA", 16); // Horizontal DOP TinyGPSCustom vdop(gps, "GPGSA", 17); // Vertical DOP void setup() { Serial.begin(115200); ss.begin(GPSBaud); Serial.println("Custom NMEA field extraction demo"); } void loop() { while (ss.available() > 0) gps.encode(ss.read()); // Check if any custom field was updated if (pdop.isUpdated() || hdopCustom.isUpdated() || vdop.isUpdated()) { Serial.print("PDOP="); Serial.print(pdop.value()); // Returns string value Serial.print(" HDOP="); Serial.print(hdopCustom.value()); Serial.print(" VDOP="); Serial.println(vdop.value()); // Check validity and age if (pdop.isValid()) { Serial.print("PDOP age: "); Serial.print(pdop.age()); Serial.println(" ms"); } } } ``` -------------------------------- ### Calculate Distance Between Two Points Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Use the static TinyGPSPlus::distanceBetween() method to calculate the great-circle distance in meters between two coordinate pairs. Requires the TinyGPS++ library. ```cpp #include TinyGPSPlus gps; void setup() { Serial.begin(115200); // Define two locations double lat1 = 40.7128, lon1 = -74.0060; // New York City double lat2 = 51.5074, lon2 = -0.1278; // London // Calculate distance in meters double distMeters = TinyGPSPlus::distanceBetween(lat1, lon1, lat2, lon2); Serial.print("NYC to London: "); Serial.print(distMeters / 1000.0, 2); Serial.println(" km"); // Output: ~5570 km // Practical example: distance to a destination double myLat = 30.2367, myLon = -97.8215; double destLat = 30.2672, destLon = -97.7431; // Austin downtown double distToAustin = TinyGPSPlus::distanceBetween(myLat, myLon, destLat, destLon); Serial.print("Distance to Austin downtown: "); Serial.print(distToAustin, 0); Serial.println(" meters"); // Output: ~8500 meters } void loop() {} ``` -------------------------------- ### Process NMEA Characters with encode() Source: https://context7.com/mikalhart/tinygpsplus/llms.txt The encode() method processes incoming NMEA characters one at a time. It returns true when a complete, valid sentence has been successfully parsed. ```cpp #include #include static const int RXPin = 4, TXPin = 3; static const uint32_t GPSBaud = 4800; TinyGPSPlus gps; SoftwareSerial ss(RXPin, TXPin); void setup() { Serial.begin(115200); ss.begin(GPSBaud); } void loop() { // Feed characters from GPS to the parser while (ss.available() > 0) { char c = ss.read(); // encode() returns true when a valid sentence is complete if (gps.encode(c)) { Serial.println("Valid NMEA sentence received!"); } } // Detect no GPS data if (millis() > 5000 && gps.charsProcessed() < 10) { Serial.println("No GPS detected: check wiring."); } } ``` -------------------------------- ### Access HDOP - GPS Fix Quality Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Access the HDOP value from a GGA sentence to determine GPS fix quality. Lower values indicate better quality. Requires the TinyGPS++ library. ```cpp #include TinyGPSPlus gps; // GGA sentence with HDOP of 1.2 const char *gpsStream = "$GPGGA,045104.000,3014.1985,N,09749.2873,W,1,09,1.2,211.6,M,-22.5,M,,0000*62\r\n"; void setup() { Serial.begin(115200); while (*gpsStream) gps.encode(*gpsStream++); if (gps.hdop.isValid()) { Serial.print("HDOP: "); Serial.println(gps.hdop.hdop(), 2); // Output: 1.20 // Interpret HDOP value double hdopVal = gps.hdop.hdop(); if (hdopVal < 1.0) Serial.println("Fix quality: Excellent"); else if (hdopVal < 2.0) Serial.println("Fix quality: Good"); else if (hdopVal < 5.0) Serial.println("Fix quality: Moderate"); else Serial.println("Fix quality: Poor"); } } void loop() {} ``` -------------------------------- ### Access GPS Date with date Source: https://context7.com/mikalhart/tinygpsplus/llms.txt The date object extracts year, month, and day from RMC sentences. Use isValid() to verify the data before processing. ```cpp #include TinyGPSPlus gps; const char *gpsStream = "$GPRMC,045103.000,A,3014.1984,N,09749.2872,W,0.67,161.46,030913,,,A*7C\r\n"; void setup() { Serial.begin(115200); while (*gpsStream) gps.encode(*gpsStream++); if (gps.date.isValid()) { // Get individual date components Serial.print("Year: "); Serial.println(gps.date.year()); // Output: 2013 Serial.print("Month: "); Serial.println(gps.date.month()); // Output: 9 Serial.print("Day: "); Serial.println(gps.date.day()); // Output: 3 // Get raw value (DDMMYY format) Serial.print("Raw date value: "); Serial.println(gps.date.value()); // Output: 30913 // Formatted output char dateStr[11]; sprintf(dateStr, "%02d/%02d/%04d", gps.date.month(), gps.date.day(), gps.date.year()); Serial.println(dateStr); // Output: 09/03/2013 } } void loop() {} ``` -------------------------------- ### date - Access GPS Date Source: https://context7.com/mikalhart/tinygpsplus/llms.txt The date object provides access to year, month, and day information extracted from NMEA RMC sentences. ```APIDOC ## date Object ### Description Provides access to date components extracted from GPS sentences. ### Methods - **isValid()** (bool) - Returns true if the date data is valid. - **year()** (uint16_t) - Returns the year. - **month()** (uint8_t) - Returns the month. - **day()** (uint8_t) - Returns the day. - **value()** (uint32_t) - Returns the raw date value in DDMMYY format. ``` -------------------------------- ### encode() - Process NMEA Characters Source: https://context7.com/mikalhart/tinygpsplus/llms.txt The encode() method processes incoming NMEA characters one at a time, returning true when a complete valid sentence has been parsed. ```APIDOC ## encode(char c) ### Description Processes incoming NMEA characters one at a time. This method should be called for every character received from the GPS module serial stream. ### Parameters - **c** (char) - Required - The character received from the GPS serial stream. ### Response - **bool** - Returns true when a complete valid NMEA sentence has been parsed. ``` -------------------------------- ### location - Access GPS Coordinates Source: https://context7.com/mikalhart/tinygpsplus/llms.txt The location object provides access to latitude and longitude data, including validity checks, raw precision data, and fix quality information. ```APIDOC ## location Object ### Description Provides access to latitude and longitude in decimal degrees, along with metadata about the fix. ### Methods - **isValid()** (bool) - Returns true if the location data is valid. - **lat()** (double) - Returns latitude in decimal degrees. - **lng()** (double) - Returns longitude in decimal degrees. - **rawLat()** (struct) - Returns raw latitude data including degrees and billionths. - **age()** (uint32_t) - Returns the number of milliseconds since the last update. - **isUpdated()** (bool) - Returns true if the data has been updated since the last read. - **FixQuality()** (char) - Returns the fix quality indicator. ``` -------------------------------- ### HDOP - Access Horizontal Dilution of Precision Source: https://context7.com/mikalhart/tinygpsplus/llms.txt Provides the HDOP value indicating GPS fix quality. Lower values are better. ```APIDOC ## HDOP - Access Horizontal Dilution of Precision ### Description Provides the HDOP value indicating GPS fix quality (lower is better; <1 is excellent, 1-2 is good, >5 is poor). ### Method Accessory method on the TinyGPSPlus object. ### Endpoint N/A (Library function) ### Parameters None ### Request Example ```cpp #include TinyGPSPlus gps; // GGA sentence with HDOP of 1.2 const char *gpsStream = "$GPGGA,045104.000,3014.1985,N,09749.2873,W,1,09,1.2,211.6,M,-22.5,M,,0000*62\r\n"; void setup() { Serial.begin(115200); while (*gpsStream) gps.encode(*gpsStream++); if (gps.hdop.isValid()) { Serial.print("HDOP: "); Serial.println(gps.hdop.hdop(), 2); // Output: 1.20 // Interpret HDOP value double hdopVal = gps.hdop.hdop(); if (hdopVal < 1.0) Serial.println("Fix quality: Excellent"); else if (hdopVal < 2.0) Serial.println("Fix quality: Good"); else if (hdopVal < 5.0) Serial.println("Fix quality: Moderate"); else Serial.println("Fix quality: Poor"); } } void loop() {} ``` ### Response #### Success Response (N/A) - **hdop.hdop()** (double) - The HDOP value. - **hdop.isValid()** (bool) - Returns true if the HDOP value is valid. #### Response Example ``` HDOP: 1.20 Fix quality: Good ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.