Advertisement
nurchairulsyam

GPS

Dec 8th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <TinyGPS++.h>
  2. #include <SoftwareSerial.h>
  3.  
  4. static const int RXPin = 8, TXPin = 9;
  5. static const uint32_t GPSBaud = 9600;
  6.  
  7. // The TinyGPS++ object
  8. TinyGPSPlus gps;
  9.  
  10. // The serial connection to the GPS device
  11. SoftwareSerial ss(RXPin, TXPin);
  12.  
  13. void setup()
  14. {
  15. Serial.begin(115200);
  16. ss.begin(GPSBaud);
  17.  
  18. Serial.println(F("DeviceExample.ino"));
  19. Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
  20. Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  21. Serial.println(F("by Mikal Hart"));
  22. Serial.println(F("Edited By www.maxphi.com"));
  23. Serial.println();
  24. }
  25.  
  26. void loop()
  27. {
  28. // This sketch displays information every time a new sentence is correctly encoded.
  29. while (ss.available() > 0)
  30. if (gps.encode(ss.read()))
  31. displayInfo();
  32.  
  33. if (millis() > 5000 && gps.charsProcessed() < 10)
  34. {
  35. Serial.println(F("No GPS detected: check wiring."));
  36. while(true);
  37. }
  38. }
  39.  
  40. void displayInfo()
  41. {
  42. Serial.print(F("Location: "));
  43. if (gps.location.isValid())
  44. {
  45. Serial.print(gps.location.lat(), 6);
  46. Serial.print(F(","));
  47. Serial.print(gps.location.lng(), 6);
  48. }
  49. else
  50. {
  51. Serial.print(F("INVALID"));
  52. }
  53. Serial.println();
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement