![](/media/cache/group/logo_mPY59fz.jpg.50x50_q85.jpg)
Adafruit GPS , distance and count footsteps
Dependencies: mbed SDFileSystem MBed_Adafruit-GPS-Library USBDevice
main.cpp@1:b100ab44119d, 2016-12-22 (annotated)
- Committer:
- reanimationxp
- Date:
- Thu Dec 22 05:52:09 2016 +0000
- Revision:
- 1:b100ab44119d
- Parent:
- 0:604848fcb49c
- Child:
- 2:7166ad3f9a2a
committing jhey's new code. old code is commented. -reanimationxp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
reanimationxp | 1:b100ab44119d | 1 | //gps.cpp |
reanimationxp | 1:b100ab44119d | 2 | //for use with Adafruit Ultimate GPS |
reanimationxp | 1:b100ab44119d | 3 | //Reads in and parses GPS data |
reanimationxp | 1:b100ab44119d | 4 | |
reanimationxp | 1:b100ab44119d | 5 | #include "mbed.h" |
reanimationxp | 1:b100ab44119d | 6 | #include "MBed_Adafruit_GPS.h" |
reanimationxp | 1:b100ab44119d | 7 | |
reanimationxp | 1:b100ab44119d | 8 | Serial * gps_Serial; |
reanimationxp | 1:b100ab44119d | 9 | Serial pc (USBTX, USBRX); |
reanimationxp | 1:b100ab44119d | 10 | |
reanimationxp | 1:b100ab44119d | 11 | int main() { |
reanimationxp | 1:b100ab44119d | 12 | |
reanimationxp | 1:b100ab44119d | 13 | pc.baud(115200); //sets virtual COM serial communication to high rate; this is to allow more time to be spent on GPS retrieval |
reanimationxp | 1:b100ab44119d | 14 | |
reanimationxp | 1:b100ab44119d | 15 | gps_Serial = new Serial(p28,p27); //serial object for use w/ GPS |
reanimationxp | 1:b100ab44119d | 16 | Adafruit_GPS myGPS(gps_Serial); //object of Adafruit's GPS class |
reanimationxp | 1:b100ab44119d | 17 | char c; //when read via Adafruit_GPS::read(), the class returns single character stored here |
reanimationxp | 1:b100ab44119d | 18 | Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info? |
reanimationxp | 1:b100ab44119d | 19 | const int refresh_Time = 2000; //refresh time in ms |
reanimationxp | 1:b100ab44119d | 20 | |
reanimationxp | 1:b100ab44119d | 21 | myGPS.begin(9600); //sets baud rate for GPS communication; note this may be changed via Adafruit_GPS::sendCommand(char *) |
reanimationxp | 1:b100ab44119d | 22 | //a list of GPS commands is available at http://www.adafruit.com/datasheets/PMTK_A08.pdf |
reanimationxp | 1:b100ab44119d | 23 | |
reanimationxp | 1:b100ab44119d | 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 |
reanimationxp | 1:b100ab44119d | 25 | myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); |
reanimationxp | 1:b100ab44119d | 26 | myGPS.sendCommand(PGCMD_ANTENNA); |
reanimationxp | 1:b100ab44119d | 27 | |
reanimationxp | 1:b100ab44119d | 28 | pc.printf("Connection established at 115200 baud...\n"); |
reanimationxp | 1:b100ab44119d | 29 | |
reanimationxp | 1:b100ab44119d | 30 | wait(1); |
reanimationxp | 1:b100ab44119d | 31 | |
reanimationxp | 1:b100ab44119d | 32 | refresh_Timer.start(); //starts the clock on the timer |
reanimationxp | 1:b100ab44119d | 33 | |
reanimationxp | 1:b100ab44119d | 34 | while(true){ |
reanimationxp | 1:b100ab44119d | 35 | c = myGPS.read(); //queries the GPS |
reanimationxp | 1:b100ab44119d | 36 | |
reanimationxp | 1:b100ab44119d | 37 | if (c) { pc.printf("%c", c); } //this line will echo the GPS data if not paused |
reanimationxp | 1:b100ab44119d | 38 | |
reanimationxp | 1:b100ab44119d | 39 | //check if we recieved a new message from GPS, if so, attempt to parse it, |
reanimationxp | 1:b100ab44119d | 40 | if ( myGPS.newNMEAreceived() ) { |
reanimationxp | 1:b100ab44119d | 41 | if ( !myGPS.parse(myGPS.lastNMEA()) ) { |
reanimationxp | 1:b100ab44119d | 42 | continue; |
reanimationxp | 1:b100ab44119d | 43 | } |
reanimationxp | 1:b100ab44119d | 44 | } |
reanimationxp | 1:b100ab44119d | 45 | |
reanimationxp | 1:b100ab44119d | 46 | //check if enough time has passed to warrant printing GPS info to screen |
reanimationxp | 1:b100ab44119d | 47 | //note if refresh_Time is too low or pc.baud is too low, GPS data may be lost during printing |
reanimationxp | 1:b100ab44119d | 48 | if (refresh_Timer.read_ms() >= refresh_Time) { |
reanimationxp | 1:b100ab44119d | 49 | refresh_Timer.reset(); |
reanimationxp | 1:b100ab44119d | 50 | pc.printf("Time: %d:%d:%d.%u\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds); |
reanimationxp | 1:b100ab44119d | 51 | pc.printf("Date: %d/%d/20%d\n", myGPS.day, myGPS.month, myGPS.year); |
reanimationxp | 1:b100ab44119d | 52 | pc.printf("Fix: %d\n", (int) myGPS.fix); |
reanimationxp | 1:b100ab44119d | 53 | pc.printf("Quality: %d\n", (int) myGPS.fixquality); |
reanimationxp | 1:b100ab44119d | 54 | if (myGPS.fix) { |
reanimationxp | 1:b100ab44119d | 55 | pc.printf("Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon); |
reanimationxp | 1:b100ab44119d | 56 | pc.printf("Speed: %5.2f knots\n", myGPS.speed); |
reanimationxp | 1:b100ab44119d | 57 | pc.printf("Angle: %5.2f\n", myGPS.angle); |
reanimationxp | 1:b100ab44119d | 58 | pc.printf("Altitude: %5.2f\n", myGPS.altitude); |
reanimationxp | 1:b100ab44119d | 59 | pc.printf("Satellites: %d\n", myGPS.satellites); |
reanimationxp | 1:b100ab44119d | 60 | } |
reanimationxp | 1:b100ab44119d | 61 | } |
reanimationxp | 1:b100ab44119d | 62 | } |
reanimationxp | 1:b100ab44119d | 63 | } |
reanimationxp | 1:b100ab44119d | 64 | |
reanimationxp | 1:b100ab44119d | 65 | /* |
reanimationxp | 1:b100ab44119d | 66 | |
jhey | 0:604848fcb49c | 67 | //gps.cpp |
jhey | 0:604848fcb49c | 68 | //for use with Adafruit Ultimate GPS |
jhey | 0:604848fcb49c | 69 | //Reads in and parses GPS data |
jhey | 0:604848fcb49c | 70 | |
jhey | 0:604848fcb49c | 71 | #include "mbed.h" |
jhey | 0:604848fcb49c | 72 | #include "MBed_Adafruit_GPS.h" |
jhey | 0:604848fcb49c | 73 | |
jhey | 0:604848fcb49c | 74 | Serial * gps_Serial; |
jhey | 0:604848fcb49c | 75 | Serial pct (USBTX, USBRX); |
jhey | 0:604848fcb49c | 76 | |
jhey | 0:604848fcb49c | 77 | int main() { |
jhey | 0:604848fcb49c | 78 | |
jhey | 0:604848fcb49c | 79 | 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 | 80 | |
jhey | 0:604848fcb49c | 81 | gps_Serial = new Serial(PTC17,PTC16); //serial object for use w/ GPS |
jhey | 0:604848fcb49c | 82 | Adafruit_GPS myGPS(gps_Serial); //object of Adafruit's GPS class |
jhey | 0:604848fcb49c | 83 | char c; //when read via Adafruit_GPS::read(), the class returns single character stored here |
jhey | 0:604848fcb49c | 84 | Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info? |
jhey | 0:604848fcb49c | 85 | const int refresh_Time = 2000; //refresh time in ms |
jhey | 0:604848fcb49c | 86 | |
jhey | 0:604848fcb49c | 87 | myGPS.begin(9600); //sets baud rate for GPS communication; note this may be changed via Adafruit_GPS::sendCommand(char *) |
jhey | 0:604848fcb49c | 88 | //a list of GPS commands is available at http://www.adafruit.com/datasheets/PMTK_A08.pdf |
jhey | 0:604848fcb49c | 89 | |
jhey | 0:604848fcb49c | 90 | 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 | 91 | myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); |
jhey | 0:604848fcb49c | 92 | myGPS.sendCommand(PGCMD_ANTENNA); |
jhey | 0:604848fcb49c | 93 | |
jhey | 0:604848fcb49c | 94 | pct.printf("Connection established at 115200 baud...\n"); |
jhey | 0:604848fcb49c | 95 | |
jhey | 0:604848fcb49c | 96 | wait(1); |
jhey | 0:604848fcb49c | 97 | |
jhey | 0:604848fcb49c | 98 | refresh_Timer.start(); //starts the clock on the timer |
jhey | 0:604848fcb49c | 99 | |
jhey | 0:604848fcb49c | 100 | while(true){ |
jhey | 0:604848fcb49c | 101 | c = myGPS.read(); //queries the GPS |
jhey | 0:604848fcb49c | 102 | |
jhey | 0:604848fcb49c | 103 | if (c) { pct.printf("%c", c); } //this line will echo the GPS data if not paused |
jhey | 0:604848fcb49c | 104 | |
jhey | 0:604848fcb49c | 105 | //check if we recieved a new message from GPS, if so, attempt to parse it, |
jhey | 0:604848fcb49c | 106 | if ( myGPS.newNMEAreceived() ) { |
jhey | 0:604848fcb49c | 107 | if ( !myGPS.parse(myGPS.lastNMEA()) ) { |
jhey | 0:604848fcb49c | 108 | continue; |
jhey | 0:604848fcb49c | 109 | } |
jhey | 0:604848fcb49c | 110 | } |
jhey | 0:604848fcb49c | 111 | |
jhey | 0:604848fcb49c | 112 | //check if enough time has passed to warrant printing GPS info to screen |
jhey | 0:604848fcb49c | 113 | //note if refresh_Time is too low or pc.baud is too low, GPS data may be lost during printing |
jhey | 0:604848fcb49c | 114 | if (refresh_Timer.read_ms() >= refresh_Time) { |
jhey | 0:604848fcb49c | 115 | refresh_Timer.reset(); |
jhey | 0:604848fcb49c | 116 | pct.printf("Time: %d:%d:%d.%u\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds); |
jhey | 0:604848fcb49c | 117 | pct.printf("Date: %d/%d/20%d\n", myGPS.day, myGPS.month, myGPS.year); |
jhey | 0:604848fcb49c | 118 | pct.printf("Fix: %d\n", (int) myGPS.fix); |
jhey | 0:604848fcb49c | 119 | pct.printf("Quality: %d\n", (int) myGPS.fixquality); |
jhey | 0:604848fcb49c | 120 | if (myGPS.fix) { |
jhey | 0:604848fcb49c | 121 | pct.printf("Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon); |
jhey | 0:604848fcb49c | 122 | pct.printf("Speed: %5.2f knots\n", myGPS.speed); |
jhey | 0:604848fcb49c | 123 | pct.printf("Angle: %5.2f\n", myGPS.angle); |
jhey | 0:604848fcb49c | 124 | pct.printf("Altitude: %5.2f\n", myGPS.altitude); |
jhey | 0:604848fcb49c | 125 | pct.printf("Satellites: %d\n", myGPS.satellites); |
jhey | 0:604848fcb49c | 126 | } |
jhey | 0:604848fcb49c | 127 | |
jhey | 0:604848fcb49c | 128 | } |
jhey | 0:604848fcb49c | 129 | |
jhey | 0:604848fcb49c | 130 | } |
jhey | 0:604848fcb49c | 131 | |
jhey | 0:604848fcb49c | 132 | |
reanimationxp | 1:b100ab44119d | 133 | } |
reanimationxp | 1:b100ab44119d | 134 | |
reanimationxp | 1:b100ab44119d | 135 | */ |