1 // Test code for Adafruit Flora GPS modules
3 // This code shows how to listen to the GPS module in an interrupt
4 // which allows the program to have more 'freedom' - just parse
5 // when a new NMEA sentence is available! Then access data when
8 // Tested and works great with the Adafruit Flora GPS module
9 // ------> http://adafruit.com/products/1059
10 // Pick one up today at the Adafruit electronics shop
11 // and help support open source hardware & software! -ada
13 #include <Adafruit_GPS.h>
14 #include <SoftwareSerial.h>
15 Adafruit_GPS GPS(&Serial1);
17 // Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
18 // Set to 'true' if you want to debug and listen to the raw GPS sentences
21 // this keeps track of whether we're using the interrupt
23 boolean usingInterrupt = false;
27 // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
30 Serial.println("Adafruit GPS library basic test!");
32 // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
34 // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
35 GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
36 // uncomment this line to turn on only the "minimum recommended" data
37 //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
38 // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
39 // the parser doesn't care about other sentences at this time
40 // Set the update rate
41 GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
42 // For the parsing code to work nicely and have time to sort thru the data, and
43 // print it out we don't suggest using anything higher than 1 Hz
45 // Request updates on antenna status, comment out to keep quiet
46 GPS.sendCommand(PGCMD_ANTENNA);
49 // Ask for firmware version
50 Serial1.println(PMTK_Q_RELEASE);
55 uint32_t timer = millis();
56 void loop() // run over and over again
58 // read data from the GPS in the 'main loop'
60 // if you want to debug, this is a good time to do it!
62 if (c) Serial.print(c);
63 // if a sentence is received, we can check the checksum, parse it...
64 if (GPS.newNMEAreceived()) {
65 // a tricky thing here is if we print the NMEA sentence, or data
66 // we end up not listening and catching other sentences!
67 // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
68 Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
69 if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
70 return; // we can fail to parse a sentence in which case we should just wait for another
72 // if millis() or timer wraps around, we'll just reset it
73 if (timer > millis()) timer = millis();
75 // approximately every 2 seconds or so, print out the current stats
76 if (millis() - timer > 2000) {
77 timer = millis(); // reset the timer
78 Serial.print("\nTime: ");
79 Serial.print(GPS.hour, DEC); Serial.print(':');
80 Serial.print(GPS.minute, DEC); Serial.print(':');
81 Serial.print(GPS.seconds, DEC); Serial.print('.');
82 Serial.println(GPS.milliseconds);
83 Serial.print("Date: ");
84 Serial.print(GPS.day, DEC); Serial.print('/');
85 Serial.print(GPS.month, DEC); Serial.print("/20");
86 Serial.println(GPS.year, DEC);
87 Serial.print("Fix: "); Serial.print((int)GPS.fix);
88 Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
90 Serial.print("Location: ");
91 Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
93 Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
94 Serial.print("Speed (knots): "); Serial.println(GPS.speed);
95 Serial.print("Angle: "); Serial.println(GPS.angle);
96 Serial.print("Altitude: "); Serial.println(GPS.altitude);
97 Serial.print("Satellites: "); Serial.println((int)GPS.satellites);