Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <SoftwareSerial.h>
  2.  
  3. #include <TinyGPS.h>
  4.  
  5. /* This sample code demonstrates the normal use of a TinyGPS object.
  6.    It requires the use of SoftwareSerial, and assumes that you have a
  7.    4800-baud serial GPS device hooked up on pins 2(rx) and 3(tx).
  8. */
  9.  
  10. TinyGPS gps;
  11. SoftwareSerial ss(2, 3);
  12.  
  13. void setup()
  14. {
  15.   Serial.begin(115200);
  16.   ss.begin(4800);
  17.  
  18.   Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  19.   Serial.println("by Mikal Hart");
  20.   Serial.println();
  21. }
  22.  
  23. void loop()
  24. {
  25.   bool newData = false;
  26.   unsigned long chars;
  27.   unsigned short sentences, failed;
  28.  
  29.   // For one second we parse GPS data and report some key values
  30.   for (unsigned long start = millis(); millis() - start < 1000;)
  31.   {
  32.     while (ss.available())
  33.     {
  34.       char c = ss.read();
  35.       // Serial.write(c); // uncomment this line if you want to see the GPS data flowing
  36.       if (gps.encode(c)) // Did a new valid sentence come in?
  37.         newData = true;
  38.     }
  39.   }
  40.  
  41.   if (newData)
  42.   {
  43.     float flat, flon;
  44.     unsigned long age;
  45.     gps.f_get_position(&flat, &flon, &age);
  46.     Serial.print("LAT=");
  47.     Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
  48.     Serial.print(" LON=");
  49.     Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
  50.     Serial.print(" SAT=");
  51.     Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
  52.     Serial.print(" PREC=");
  53.     Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
  54.   }
  55.  
  56.   gps.stats(&chars, &sentences, &failed);
  57.   Serial.print(" CHARS=");
  58.   Serial.print(chars);
  59.   Serial.print(" SENTENCES=");
  60.   Serial.print(sentences);
  61.   Serial.print(" CSUM ERR=");
  62.   Serial.println(failed);
  63. }