Advertisement
apl-mhd

gps only

Jul 15th, 2021
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1.  
  2. #include <TinyGPS++.h> // library for GPS module
  3. #include <SoftwareSerial.h>
  4. #include <ESP8266WiFi.h>
  5. TinyGPSPlus gps;  // The TinyGPS++ object
  6.  
  7. SoftwareSerial ss(4, 5); // The serial connection to the GPS device
  8.  
  9. float latitude , longitude;
  10. String date_str , time_str , lat_str , lng_str;
  11.  
  12.  
  13. void setup() {
  14.     Serial.begin(115200);
  15.  
  16.   ss.begin(9600);
  17.   Serial.println();
  18.  
  19. }
  20.  
  21. void loop() {
  22.  
  23. //  Serial.println("afadf");
  24.    while (ss.available() > 0){ //while data is available
  25.     if (gps.encode(ss.read())) //read gps data
  26.     {
  27.       if (gps.location.isValid()) //check whether gps location is valid
  28.       {
  29.         latitude = gps.location.lat();
  30.         lat_str = String(latitude , 6); // latitude location is stored in a string
  31.         longitude = gps.location.lng();
  32.         lng_str = String(longitude , 6); //longitude location is stored in a string
  33.  
  34.         Serial.println(latitude);
  35.       }
  36.  
  37. }
  38.    }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement