Advertisement
LeventeDaradici

How to read data from GPS signal - Arduino for beginners

Dec 5th, 2021
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.95 KB | None | 0 0
  1. #include <TinyGPS++.h>
  2. #include <SoftwareSerial.h>
  3.  
  4. static const int RXPin = 4, TXPin = 3;
  5. static const uint32_t GPSBaud = 9600;
  6.  
  7. TinyGPSPlus gps;
  8.  
  9. SoftwareSerial ss(RXPin, TXPin);
  10.  
  11. void setup(){
  12.   Serial.begin(9600);
  13.   ss.begin(GPSBaud);
  14. }
  15.  
  16. void loop(){
  17.   while (ss.available() > 0){
  18.     gps.encode(ss.read());
  19.     if (gps.location.isUpdated()){
  20.       Serial.print("Latitude= ");
  21.       Serial.print(gps.location.lat(), 6);      
  22.       Serial.print(" Longitude= ");
  23.       Serial.println(gps.location.lng(), 6);
  24.        
  25.       Serial.print("Raw latitude = ");
  26.       Serial.print(gps.location.rawLat().negative ? "-" : "+");
  27.       Serial.println(gps.location.rawLat().deg);
  28.       Serial.println(gps.location.rawLat().billionths);
  29.      
  30.       Serial.print("Raw longitude = ");
  31.       Serial.print(gps.location.rawLng().negative ? "-" : "+");
  32.       Serial.println(gps.location.rawLng().deg);
  33.       Serial.println(gps.location.rawLng().billionths);
  34.  
  35.       Serial.print("Raw date DDMMYY = ");
  36.       Serial.println(gps.date.value());
  37.  
  38.       Serial.print("Year = ");
  39.       Serial.println(gps.date.year());
  40.       Serial.print("Month = ");
  41.       Serial.println(gps.date.month());
  42.       Serial.print("Day = ");
  43.       Serial.println(gps.date.day());
  44.  
  45.       Serial.print("Raw time in HHMMSSCC = ");
  46.       Serial.println(gps.time.value());
  47.  
  48.       Serial.print("Hour = ");
  49.       Serial.println(gps.time.hour());
  50.       Serial.print("Minute = ");
  51.       Serial.println(gps.time.minute());
  52.       Serial.print("Second = ");
  53.       Serial.println(gps.time.second());
  54.       Serial.print("Centisecond = ");
  55.       Serial.println(gps.time.centisecond());
  56.  
  57.       Serial.print("Raw speed in 100ths/knot = ");
  58.       Serial.println(gps.speed.value());
  59.       Serial.print("Speed in knots/h = ");
  60.       Serial.println(gps.speed.knots());
  61.       Serial.print("Speed in miles/h = ");
  62.       Serial.println(gps.speed.mph());
  63.       Serial.print("Speed in m/s = ");
  64.       Serial.println(gps.speed.mps());
  65.       Serial.print("Speed in km/h = ");
  66.       Serial.println(gps.speed.kmph());
  67.  
  68.       Serial.print("Raw course in degrees = ");
  69.       Serial.println(gps.course.value());
  70.       Serial.print("Course in degrees = ");
  71.       Serial.println(gps.course.deg());
  72.  
  73.       Serial.print("Raw altitude in centimeters = ");
  74.       Serial.println(gps.altitude.value());
  75.       Serial.print("Altitude in meters = ");
  76.       Serial.println(gps.altitude.meters());
  77.       Serial.print("Altitude in miles = ");
  78.       Serial.println(gps.altitude.miles());
  79.       Serial.print("Altitude in kilometers = ");
  80.       Serial.println(gps.altitude.kilometers());
  81.       Serial.print("Altitude in feet = ");
  82.       Serial.println(gps.altitude.feet());
  83.  
  84.       Serial.print("Number os satellites in use = ");
  85.       Serial.println(gps.satellites.value());
  86.  
  87.       Serial.print("HDOP = ");
  88.       Serial.println(gps.hdop.value());
  89.       delay(20000);
  90.     }
  91.   }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement