Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <TinyGPS++/TinyGPS++.h>
  2.  
  3. static const uint32_t GPSBaud = 4800;
  4.  
  5. TinyGPSPlus gps;
  6.  
  7. void setup()
  8. {
  9. Serial.begin(9600);
  10. Serial1.begin(GPSBaud);
  11. }
  12.  
  13. void displayInfo()
  14. {
  15. Serial.print(F("Location: "));
  16. if (gps.location.isValid())
  17. {
  18. Serial.print(gps.location.lat(), 6);
  19. Serial.print(F(","));
  20. Serial.print(gps.location.lng(), 6);
  21. }
  22. else
  23. {
  24. Serial.print(F("INVALID"));
  25. }
  26.  
  27. Serial.print(F(" Date/Time: "));
  28. if (gps.date.isValid())
  29. {
  30. Serial.print(gps.date.day());
  31. Serial.print(F("."));
  32. Serial.print(gps.date.month());
  33. Serial.print(F("."));
  34. Serial.print(gps.date.year());
  35. Serial.print(F("."));
  36. }
  37. else
  38. {
  39. Serial.print(F("INVALID"));
  40. }
  41.  
  42. Serial.print(F(" "));
  43. if (gps.time.isValid())
  44. {
  45. if (gps.time.hour() < 10)
  46. Serial.print(F("0"));
  47. Serial.print(gps.time.hour());
  48. Serial.print(F(":"));
  49. if (gps.time.minute() < 10)
  50. Serial.print(F("0"));
  51. Serial.print(gps.time.minute());
  52. Serial.print(F(":"));
  53. if (gps.time.second() < 10)
  54. Serial.print(F("0"));
  55. Serial.print(gps.time.second());
  56. Serial.print(F("."));
  57. if (gps.time.centisecond() < 10)
  58. Serial.print(F("0"));
  59. Serial.print(gps.time.centisecond());
  60. }
  61. else
  62. {
  63. Serial.print(F("INVALID"));
  64. }
  65.  
  66. Serial.println();
  67. }
  68. void loop()
  69. {
  70. while (Serial1.available() > 0)
  71. {
  72. if (gps.encode(Serial1.read()))
  73. {
  74. displayInfo();
  75. }
  76. }
  77. if (millis() > 5000 && gps.charsProcessed() < 10)
  78. {
  79. Serial.println(F("No GPS detected: check wiring."));
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement