Advertisement
mikroavr

read_gps_L86

Jun 30th, 2022
1,266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <TinyGPS++.h>
  2. TinyGPSPlus gps;
  3.  
  4. // The serial connection to the GPS device
  5. //SoftwareSerial ss(RXPin, TXPin);
  6. #define ss Serial1
  7. #define rst 32
  8.  
  9. String str_lat="";
  10. String str_lon="";
  11. String str_date="";
  12. String str_time="";
  13.  
  14. #define RXD1 17
  15. #define TXD1 16
  16.  
  17. void setup()
  18. {
  19.   Serial.begin(115200);
  20.   pinMode(rst, OUTPUT);
  21.   ss.begin(9600, SERIAL_8N1, RXD1, TXD1);
  22.   delay(100);
  23.   digitalWrite(rst, LOW);delay(500);
  24.   //digitalWrite(rst, HIGH);delay(500);
  25.   //digitalWrite(rst, LOW);delay(500);
  26.  
  27. }
  28.  
  29. void loop()
  30. {
  31.   // This sketch displays information every time a new sentence is correctly encoded.
  32.   while (ss.available() > 0)
  33.     if (gps.encode(ss.read()))
  34.       displayInfo();
  35.  
  36.   if (millis() > 5000 && gps.charsProcessed() < 10)
  37.   {
  38.     Serial.println(F("No GPS detected: check wiring."));
  39.     while (true);
  40.   }
  41. }
  42.  
  43. void displayInfo()
  44. {
  45.   String str_buf_lat = "";
  46.   String str_buf_lon = "";
  47.   String str_buf_date = "";
  48.   String str_buf_time = "";
  49.  
  50.   Serial.print(F("Location: "));
  51.   if (gps.location.isValid())
  52.   {
  53.     Serial.print(gps.location.lat(), 6);
  54.     Serial.print(F(","));
  55.     Serial.print(gps.location.lng(), 6);
  56.     str_buf_lat = String(gps.location.lat(), 6);
  57.     str_buf_lat = String(gps.location.lng(), 6);
  58.     str_lat = str_buf_lat;
  59.     str_lon = str_buf_lon;
  60.   }
  61.   else
  62.   {
  63.     Serial.print(F("INVALID"));
  64.   }
  65.  
  66.   Serial.print(F("  Date/Time: "));
  67.   if (gps.date.isValid())
  68.   {
  69.     Serial.print(gps.date.month());
  70.     Serial.print(F("/"));
  71.     Serial.print(gps.date.day());
  72.     Serial.print(F("/"));
  73.     Serial.print(gps.date.year());
  74.     str_buf_date = String(gps.date.month()) + "/" + String(gps.date.day()) + "/" + String(gps.date.year());
  75.     str_date = str_buf_date;
  76.   }
  77.   else
  78.   {
  79.     Serial.print(F("INVALID"));
  80.   }
  81.  
  82.   Serial.print(F(" "));
  83.   if (gps.time.isValid())
  84.   {
  85.     int jam =  gps.time.hour();
  86.     jam = jam +7;
  87.     if(jam >= 24 ){
  88.       jam = jam - 24;
  89.     }
  90.     str_buf_time = String(jam) + ":" + String(gps.time.minute()) + ":" + String(gps.time.second());
  91.     str_time = str_buf_time;
  92.     Serial.print(str_time);
  93.   }
  94.   else
  95.   {
  96.     Serial.print(F("INVALID"));
  97.   }
  98.  
  99.   Serial.println();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement