UsingCustomFields.ino 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <TinyGPS++.h>
  2. #include <SoftwareSerial.h>
  3. /*
  4. This sample demonstrates TinyGPS++'s capacity for extracting custom
  5. fields from any NMEA sentence. TinyGPS++ has built-in facilities for
  6. extracting latitude, longitude, altitude, etc., from the $GPGGA and
  7. $GPRMC sentences. But with the TinyGPSCustom type, you can extract
  8. other NMEA fields, even from non-standard NMEA sentences.
  9. It requires the use of SoftwareSerial, and assumes that you have a
  10. 4800-baud serial GPS device hooked up on pins 4(RX) and 3(TX).
  11. */
  12. static const int RXPin = 4, TXPin = 3;
  13. static const uint32_t GPSBaud = 4800;
  14. // The TinyGPS++ object
  15. TinyGPSPlus gps;
  16. // The serial connection to the GPS device
  17. SoftwareSerial ss(RXPin, TXPin);
  18. /*
  19. By declaring TinyGPSCustom objects like this, we announce that we
  20. are interested in the 15th, 16th, and 17th fields in the $GPGSA
  21. sentence, respectively the PDOP (F("positional dilution of precision")),
  22. HDOP (F("horizontal...")), and VDOP (F("vertical...")).
  23. (Counting starts with the field immediately following the sentence name,
  24. i.e. $GPGSA. For more information on NMEA sentences, consult your
  25. GPS module's documentation and/or http://aprs.gids.nl/nmea/.)
  26. If your GPS module doesn't support the $GPGSA sentence, then you
  27. won't get any output from this program.
  28. */
  29. TinyGPSCustom pdop(gps, "GPGSA", 15); // $GPGSA sentence, 15th element
  30. TinyGPSCustom hdop(gps, "GPGSA", 16); // $GPGSA sentence, 16th element
  31. TinyGPSCustom vdop(gps, "GPGSA", 17); // $GPGSA sentence, 17th element
  32. void setup()
  33. {
  34. Serial.begin(115200);
  35. ss.begin(GPSBaud);
  36. Serial.println(F("UsingCustomFields.ino"));
  37. Serial.println(F("Demonstrating how to extract any NMEA field using TinyGPSCustom"));
  38. Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  39. Serial.println(F("by Mikal Hart"));
  40. Serial.println();
  41. }
  42. void loop()
  43. {
  44. // Every time anything is updated, print everything.
  45. if (gps.altitude.isUpdated() || gps.satellites.isUpdated() ||
  46. pdop.isUpdated() || hdop.isUpdated() || vdop.isUpdated())
  47. {
  48. Serial.print(F("ALT=")); Serial.print(gps.altitude.meters());
  49. Serial.print(F(" PDOP=")); Serial.print(pdop.value());
  50. Serial.print(F(" HDOP=")); Serial.print(hdop.value());
  51. Serial.print(F(" VDOP=")); Serial.print(vdop.value());
  52. Serial.print(F(" SATS=")); Serial.println(gps.satellites.value());
  53. }
  54. while (ss.available() > 0)
  55. gps.encode(ss.read());
  56. }