Adafruit GPS , distance and count footsteps

Dependencies:   mbed SDFileSystem MBed_Adafruit-GPS-Library USBDevice

Committer:
jhey
Date:
Thu Dec 22 03:37:10 2016 +0000
Revision:
0:604848fcb49c
Child:
1:b100ab44119d
gps demo initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhey 0:604848fcb49c 1 //gps.cpp
jhey 0:604848fcb49c 2 //for use with Adafruit Ultimate GPS
jhey 0:604848fcb49c 3 //Reads in and parses GPS data
jhey 0:604848fcb49c 4
jhey 0:604848fcb49c 5 #include "mbed.h"
jhey 0:604848fcb49c 6 #include "MBed_Adafruit_GPS.h"
jhey 0:604848fcb49c 7
jhey 0:604848fcb49c 8 Serial * gps_Serial;
jhey 0:604848fcb49c 9 Serial pct (USBTX, USBRX);
jhey 0:604848fcb49c 10
jhey 0:604848fcb49c 11 int main() {
jhey 0:604848fcb49c 12
jhey 0:604848fcb49c 13 pct.baud(115200); //sets virtual COM serial communication to high rate; this is to allow more time to be spent on GPS retrieval
jhey 0:604848fcb49c 14
jhey 0:604848fcb49c 15 gps_Serial = new Serial(PTC17,PTC16); //serial object for use w/ GPS
jhey 0:604848fcb49c 16 Adafruit_GPS myGPS(gps_Serial); //object of Adafruit's GPS class
jhey 0:604848fcb49c 17 char c; //when read via Adafruit_GPS::read(), the class returns single character stored here
jhey 0:604848fcb49c 18 Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info?
jhey 0:604848fcb49c 19 const int refresh_Time = 2000; //refresh time in ms
jhey 0:604848fcb49c 20
jhey 0:604848fcb49c 21 myGPS.begin(9600); //sets baud rate for GPS communication; note this may be changed via Adafruit_GPS::sendCommand(char *)
jhey 0:604848fcb49c 22 //a list of GPS commands is available at http://www.adafruit.com/datasheets/PMTK_A08.pdf
jhey 0:604848fcb49c 23
jhey 0:604848fcb49c 24 myGPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //these commands are defined in MBed_Adafruit_GPS.h; a link is provided there for command creation
jhey 0:604848fcb49c 25 myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
jhey 0:604848fcb49c 26 myGPS.sendCommand(PGCMD_ANTENNA);
jhey 0:604848fcb49c 27
jhey 0:604848fcb49c 28 pct.printf("Connection established at 115200 baud...\n");
jhey 0:604848fcb49c 29
jhey 0:604848fcb49c 30 wait(1);
jhey 0:604848fcb49c 31
jhey 0:604848fcb49c 32 refresh_Timer.start(); //starts the clock on the timer
jhey 0:604848fcb49c 33
jhey 0:604848fcb49c 34 while(true){
jhey 0:604848fcb49c 35 c = myGPS.read(); //queries the GPS
jhey 0:604848fcb49c 36
jhey 0:604848fcb49c 37 if (c) { pct.printf("%c", c); } //this line will echo the GPS data if not paused
jhey 0:604848fcb49c 38
jhey 0:604848fcb49c 39 //check if we recieved a new message from GPS, if so, attempt to parse it,
jhey 0:604848fcb49c 40 if ( myGPS.newNMEAreceived() ) {
jhey 0:604848fcb49c 41 if ( !myGPS.parse(myGPS.lastNMEA()) ) {
jhey 0:604848fcb49c 42 continue;
jhey 0:604848fcb49c 43 }
jhey 0:604848fcb49c 44 }
jhey 0:604848fcb49c 45
jhey 0:604848fcb49c 46 //check if enough time has passed to warrant printing GPS info to screen
jhey 0:604848fcb49c 47 //note if refresh_Time is too low or pc.baud is too low, GPS data may be lost during printing
jhey 0:604848fcb49c 48 if (refresh_Timer.read_ms() >= refresh_Time) {
jhey 0:604848fcb49c 49 refresh_Timer.reset();
jhey 0:604848fcb49c 50 pct.printf("Time: %d:%d:%d.%u\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds);
jhey 0:604848fcb49c 51 pct.printf("Date: %d/%d/20%d\n", myGPS.day, myGPS.month, myGPS.year);
jhey 0:604848fcb49c 52 pct.printf("Fix: %d\n", (int) myGPS.fix);
jhey 0:604848fcb49c 53 pct.printf("Quality: %d\n", (int) myGPS.fixquality);
jhey 0:604848fcb49c 54 if (myGPS.fix) {
jhey 0:604848fcb49c 55 pct.printf("Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
jhey 0:604848fcb49c 56 pct.printf("Speed: %5.2f knots\n", myGPS.speed);
jhey 0:604848fcb49c 57 pct.printf("Angle: %5.2f\n", myGPS.angle);
jhey 0:604848fcb49c 58 pct.printf("Altitude: %5.2f\n", myGPS.altitude);
jhey 0:604848fcb49c 59 pct.printf("Satellites: %d\n", myGPS.satellites);
jhey 0:604848fcb49c 60 }
jhey 0:604848fcb49c 61
jhey 0:604848fcb49c 62 }
jhey 0:604848fcb49c 63
jhey 0:604848fcb49c 64 }
jhey 0:604848fcb49c 65
jhey 0:604848fcb49c 66
jhey 0:604848fcb49c 67 }