SHARE
TWEET

Untitled

a guest May 23rd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_GPS.h>
  2.  
  3. // what's the name of the hardware serial port?
  4. #define GPSSerial Serial1
  5.  
  6. // Connect to the GPS on the hardware port
  7. Adafruit_GPS GPS(&GPSSerial);
  8.  
  9. // Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
  10. // Set to 'true' if you want to debug and listen to the raw GPS sentences
  11. #define GPSECHO false
  12.  
  13. uint32_t timer = millis();
  14.  
  15.  
  16. void setup()
  17. {
  18.   //while (!Serial);  // uncomment to have the sketch wait until Serial is ready
  19.  
  20.   // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  21.   // also spit it out
  22.   Serial.begin(115200);
  23.   Serial.println("Adafruit GPS library basic test!");
  24.  
  25.   // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  26.   GPS.begin(9600);
  27.   // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  28.   GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  29.   // uncomment this line to turn on only the "minimum recommended" data
  30.   //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  31.   // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  32.   // the parser doesn't care about other sentences at this time
  33.   // Set the update rate
  34.   GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
  35.   // For the parsing code to work nicely and have time to sort thru the data, and
  36.   // print it out we don't suggest using anything higher than 1 Hz
  37.  
  38.   // Request updates on antenna status, comment out to keep quiet
  39.   GPS.sendCommand(PGCMD_ANTENNA);
  40.  
  41.   delay(1000);
  42.  
  43.   // Ask for firmware version
  44.   GPSSerial.println(PMTK_Q_RELEASE);
  45. }
  46.  
  47. void loop() // run over and over again
  48. {
  49.   // read data from the GPS in the 'main loop'
  50.   char c = GPS.read();
  51.   // if you want to debug, this is a good time to do it!
  52.   if (GPSECHO)
  53.     if (c) Serial.print(c);
  54.   // if a sentence is received, we can check the checksum, parse it...
  55.   if (GPS.newNMEAreceived()) {
  56.     // a tricky thing here is if we print the NMEA sentence, or data
  57.     // we end up not listening and catching other sentences!
  58.     // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
  59.     Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
  60.     if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
  61.       return; // we can fail to parse a sentence in which case we should just wait for another
  62.   }
  63.   // if millis() or timer wraps around, we'll just reset it
  64.   if (timer > millis()) timer = millis();
  65.  
  66.   // approximately every 2 seconds or so, print out the current stats
  67.   if (millis() - timer > 2000) {
  68.     timer = millis(); // reset the timer
  69.     Serial.print("\nTime: ");
  70.     Serial.print(GPS.hour, DEC); Serial.print(':');
  71.     Serial.print(GPS.minute, DEC); Serial.print(':');
  72.     Serial.print(GPS.seconds, DEC); Serial.print('.');
  73.     Serial.println(GPS.milliseconds);
  74.     Serial.print("Date: ");
  75.     Serial.print(GPS.day, DEC); Serial.print('/');
  76.     Serial.print(GPS.month, DEC); Serial.print("/20");
  77.     Serial.println(GPS.year, DEC);
  78.     Serial.print("Fix: "); Serial.print((int)GPS.fix);
  79.     Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
  80.     if (GPS.fix) {
  81.       Serial.print("Location: ");
  82.       Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
  83.       Serial.print(", ");
  84.       Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
  85.       Serial.print("Speed (knots): "); Serial.println(GPS.speed);
  86.       Serial.print("Angle: "); Serial.println(GPS.angle);
  87.       Serial.print("Altitude: "); Serial.println(GPS.altitude);
  88.       Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
  89.     }
  90.   }
  91. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top