Adafruit GPS , distance and count footsteps
Dependencies: mbed SDFileSystem MBed_Adafruit-GPS-Library USBDevice
main.cpp@4:e87d9fbc4869, 2019-12-18 (annotated)
- Committer:
- zmoutaou
- Date:
- Wed Dec 18 07:44:26 2019 +0000
- Revision:
- 4:e87d9fbc4869
- Parent:
- 3:e38a115af1dd
- Child:
- 5:da8e5af9d44b
fdgadgdagdaf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
reanimationxp | 2:7166ad3f9a2a | 1 | |
reanimationxp | 2:7166ad3f9a2a | 2 | #include "mbed.h" |
reanimationxp | 2:7166ad3f9a2a | 3 | #include "MBed_Adafruit_GPS.h" |
zmoutaou | 4:e87d9fbc4869 | 4 | #include "USBSerial.h" |
reanimationxp | 2:7166ad3f9a2a | 5 | |
zmoutaou | 4:e87d9fbc4869 | 6 | USBSerial pc; |
reanimationxp | 2:7166ad3f9a2a | 7 | Serial * gps_Serial; |
zmoutaou | 4:e87d9fbc4869 | 8 | |
reanimationxp | 2:7166ad3f9a2a | 9 | |
reanimationxp | 2:7166ad3f9a2a | 10 | int main() { |
reanimationxp | 2:7166ad3f9a2a | 11 | |
zmoutaou | 4:e87d9fbc4869 | 12 | //pc.baud(115200); //sets virtual COM serial communication to high rate; this is to allow more time to be spent on GPS retrieval |
reanimationxp | 2:7166ad3f9a2a | 13 | |
zmoutaou | 4:e87d9fbc4869 | 14 | gps_Serial = new Serial(PA_2,PA_3); //serial object for use w/ GPS |
reanimationxp | 2:7166ad3f9a2a | 15 | Adafruit_GPS myGPS(gps_Serial); //object of Adafruit's GPS class |
reanimationxp | 2:7166ad3f9a2a | 16 | char c; //when read via Adafruit_GPS::read(), the class returns single character stored here |
reanimationxp | 2:7166ad3f9a2a | 17 | Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info? |
reanimationxp | 2:7166ad3f9a2a | 18 | const int refresh_Time = 2000; //refresh time in ms |
reanimationxp | 2:7166ad3f9a2a | 19 | |
reanimationxp | 2:7166ad3f9a2a | 20 | myGPS.begin(9600); //sets baud rate for GPS communication; note this may be changed via Adafruit_GPS::sendCommand(char *) |
reanimationxp | 2:7166ad3f9a2a | 21 | //a list of GPS commands is available at http://www.adafruit.com/datasheets/PMTK_A08.pdf |
reanimationxp | 2:7166ad3f9a2a | 22 | |
reanimationxp | 2:7166ad3f9a2a | 23 | 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 | 2:7166ad3f9a2a | 24 | myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); |
reanimationxp | 2:7166ad3f9a2a | 25 | myGPS.sendCommand(PGCMD_ANTENNA); |
reanimationxp | 2:7166ad3f9a2a | 26 | |
reanimationxp | 2:7166ad3f9a2a | 27 | pc.printf("Connection established at 115200 baud...\n"); |
reanimationxp | 2:7166ad3f9a2a | 28 | |
reanimationxp | 2:7166ad3f9a2a | 29 | wait(1); |
reanimationxp | 2:7166ad3f9a2a | 30 | |
reanimationxp | 2:7166ad3f9a2a | 31 | refresh_Timer.start(); //starts the clock on the timer |
reanimationxp | 2:7166ad3f9a2a | 32 | |
reanimationxp | 2:7166ad3f9a2a | 33 | while(true){ |
reanimationxp | 2:7166ad3f9a2a | 34 | c = myGPS.read(); //queries the GPS |
reanimationxp | 2:7166ad3f9a2a | 35 | |
zmoutaou | 4:e87d9fbc4869 | 36 | if (c) { } //this line will echo the GPS data if not paused |
reanimationxp | 2:7166ad3f9a2a | 37 | |
reanimationxp | 2:7166ad3f9a2a | 38 | //check if we recieved a new message from GPS, if so, attempt to parse it, |
reanimationxp | 2:7166ad3f9a2a | 39 | if ( myGPS.newNMEAreceived() ) { |
reanimationxp | 2:7166ad3f9a2a | 40 | if ( !myGPS.parse(myGPS.lastNMEA()) ) { |
reanimationxp | 2:7166ad3f9a2a | 41 | continue; |
reanimationxp | 2:7166ad3f9a2a | 42 | } |
reanimationxp | 2:7166ad3f9a2a | 43 | } |
reanimationxp | 2:7166ad3f9a2a | 44 | |
reanimationxp | 2:7166ad3f9a2a | 45 | //check if enough time has passed to warrant printing GPS info to screen |
reanimationxp | 2:7166ad3f9a2a | 46 | //note if refresh_Time is too low or pc.baud is too low, GPS data may be lost during printing |
reanimationxp | 2:7166ad3f9a2a | 47 | if (refresh_Timer.read_ms() >= refresh_Time) { |
reanimationxp | 2:7166ad3f9a2a | 48 | refresh_Timer.reset(); |
reanimationxp | 2:7166ad3f9a2a | 49 | pc.printf("Time: %d:%d:%d.%u\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds); |
reanimationxp | 2:7166ad3f9a2a | 50 | pc.printf("Date: %d/%d/20%d\n", myGPS.day, myGPS.month, myGPS.year); |
reanimationxp | 2:7166ad3f9a2a | 51 | pc.printf("Fix: %d\n", (int) myGPS.fix); |
reanimationxp | 2:7166ad3f9a2a | 52 | pc.printf("Quality: %d\n", (int) myGPS.fixquality); |
reanimationxp | 2:7166ad3f9a2a | 53 | if (myGPS.fix) { |
reanimationxp | 2:7166ad3f9a2a | 54 | pc.printf("Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon); |
reanimationxp | 2:7166ad3f9a2a | 55 | pc.printf("Speed: %5.2f knots\n", myGPS.speed); |
reanimationxp | 2:7166ad3f9a2a | 56 | pc.printf("Angle: %5.2f\n", myGPS.angle); |
reanimationxp | 2:7166ad3f9a2a | 57 | pc.printf("Altitude: %5.2f\n", myGPS.altitude); |
reanimationxp | 2:7166ad3f9a2a | 58 | pc.printf("Satellites: %d\n", myGPS.satellites); |
reanimationxp | 2:7166ad3f9a2a | 59 | } |
reanimationxp | 2:7166ad3f9a2a | 60 | } |
reanimationxp | 2:7166ad3f9a2a | 61 | } |
reanimationxp | 2:7166ad3f9a2a | 62 | } |
reanimationxp | 2:7166ad3f9a2a | 63 | |
reanimationxp | 2:7166ad3f9a2a | 64 | |
reanimationxp | 2:7166ad3f9a2a | 65 | /* |
reanimationxp | 2:7166ad3f9a2a | 66 | |
reanimationxp | 1:b100ab44119d | 67 | //gps.cpp |
reanimationxp | 1:b100ab44119d | 68 | //for use with Adafruit Ultimate GPS |
reanimationxp | 1:b100ab44119d | 69 | //Reads in and parses GPS data |
reanimationxp | 1:b100ab44119d | 70 | |
reanimationxp | 1:b100ab44119d | 71 | #include "mbed.h" |
reanimationxp | 1:b100ab44119d | 72 | #include "MBed_Adafruit_GPS.h" |
reanimationxp | 1:b100ab44119d | 73 | |
reanimationxp | 1:b100ab44119d | 74 | Serial * gps_Serial; |
reanimationxp | 1:b100ab44119d | 75 | Serial pc (USBTX, USBRX); |
reanimationxp | 1:b100ab44119d | 76 | |
reanimationxp | 1:b100ab44119d | 77 | int main() { |
reanimationxp | 1:b100ab44119d | 78 | |
reanimationxp | 1:b100ab44119d | 79 | 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 | 80 | |
reanimationxp | 1:b100ab44119d | 81 | gps_Serial = new Serial(p28,p27); //serial object for use w/ GPS |
reanimationxp | 1:b100ab44119d | 82 | Adafruit_GPS myGPS(gps_Serial); //object of Adafruit's GPS class |
reanimationxp | 1:b100ab44119d | 83 | char c; //when read via Adafruit_GPS::read(), the class returns single character stored here |
reanimationxp | 1:b100ab44119d | 84 | Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info? |
reanimationxp | 1:b100ab44119d | 85 | const int refresh_Time = 2000; //refresh time in ms |
reanimationxp | 1:b100ab44119d | 86 | |
reanimationxp | 1:b100ab44119d | 87 | myGPS.begin(9600); //sets baud rate for GPS communication; note this may be changed via Adafruit_GPS::sendCommand(char *) |
reanimationxp | 1:b100ab44119d | 88 | //a list of GPS commands is available at http://www.adafruit.com/datasheets/PMTK_A08.pdf |
reanimationxp | 1:b100ab44119d | 89 | |
reanimationxp | 1:b100ab44119d | 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 |
reanimationxp | 1:b100ab44119d | 91 | myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); |
reanimationxp | 1:b100ab44119d | 92 | myGPS.sendCommand(PGCMD_ANTENNA); |
reanimationxp | 1:b100ab44119d | 93 | |
reanimationxp | 1:b100ab44119d | 94 | pc.printf("Connection established at 115200 baud...\n"); |
reanimationxp | 1:b100ab44119d | 95 | |
reanimationxp | 1:b100ab44119d | 96 | wait(1); |
reanimationxp | 1:b100ab44119d | 97 | |
reanimationxp | 1:b100ab44119d | 98 | refresh_Timer.start(); //starts the clock on the timer |
reanimationxp | 1:b100ab44119d | 99 | |
reanimationxp | 1:b100ab44119d | 100 | while(true){ |
reanimationxp | 1:b100ab44119d | 101 | c = myGPS.read(); //queries the GPS |
reanimationxp | 1:b100ab44119d | 102 | |
reanimationxp | 1:b100ab44119d | 103 | if (c) { pc.printf("%c", c); } //this line will echo the GPS data if not paused |
reanimationxp | 1:b100ab44119d | 104 | |
reanimationxp | 1:b100ab44119d | 105 | //check if we recieved a new message from GPS, if so, attempt to parse it, |
reanimationxp | 1:b100ab44119d | 106 | if ( myGPS.newNMEAreceived() ) { |
reanimationxp | 1:b100ab44119d | 107 | if ( !myGPS.parse(myGPS.lastNMEA()) ) { |
reanimationxp | 1:b100ab44119d | 108 | continue; |
reanimationxp | 1:b100ab44119d | 109 | } |
reanimationxp | 1:b100ab44119d | 110 | } |
reanimationxp | 1:b100ab44119d | 111 | |
reanimationxp | 1:b100ab44119d | 112 | //check if enough time has passed to warrant printing GPS info to screen |
reanimationxp | 1:b100ab44119d | 113 | //note if refresh_Time is too low or pc.baud is too low, GPS data may be lost during printing |
reanimationxp | 1:b100ab44119d | 114 | if (refresh_Timer.read_ms() >= refresh_Time) { |
reanimationxp | 1:b100ab44119d | 115 | refresh_Timer.reset(); |
reanimationxp | 1:b100ab44119d | 116 | pc.printf("Time: %d:%d:%d.%u\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds); |
reanimationxp | 1:b100ab44119d | 117 | pc.printf("Date: %d/%d/20%d\n", myGPS.day, myGPS.month, myGPS.year); |
reanimationxp | 1:b100ab44119d | 118 | pc.printf("Fix: %d\n", (int) myGPS.fix); |
reanimationxp | 1:b100ab44119d | 119 | pc.printf("Quality: %d\n", (int) myGPS.fixquality); |
reanimationxp | 1:b100ab44119d | 120 | if (myGPS.fix) { |
reanimationxp | 1:b100ab44119d | 121 | pc.printf("Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon); |
reanimationxp | 1:b100ab44119d | 122 | pc.printf("Speed: %5.2f knots\n", myGPS.speed); |
reanimationxp | 1:b100ab44119d | 123 | pc.printf("Angle: %5.2f\n", myGPS.angle); |
reanimationxp | 1:b100ab44119d | 124 | pc.printf("Altitude: %5.2f\n", myGPS.altitude); |
reanimationxp | 1:b100ab44119d | 125 | pc.printf("Satellites: %d\n", myGPS.satellites); |
reanimationxp | 1:b100ab44119d | 126 | } |
reanimationxp | 1:b100ab44119d | 127 | } |
reanimationxp | 1:b100ab44119d | 128 | } |
reanimationxp | 1:b100ab44119d | 129 | } |
reanimationxp | 3:e38a115af1dd | 130 | */ |
reanimationxp | 2:7166ad3f9a2a | 131 | |
reanimationxp | 1:b100ab44119d | 132 | |
reanimationxp | 1:b100ab44119d | 133 | /* |
reanimationxp | 1:b100ab44119d | 134 | |
jhey | 0:604848fcb49c | 135 | //gps.cpp |
jhey | 0:604848fcb49c | 136 | //for use with Adafruit Ultimate GPS |
jhey | 0:604848fcb49c | 137 | //Reads in and parses GPS data |
jhey | 0:604848fcb49c | 138 | |
jhey | 0:604848fcb49c | 139 | #include "mbed.h" |
jhey | 0:604848fcb49c | 140 | #include "MBed_Adafruit_GPS.h" |
jhey | 0:604848fcb49c | 141 | |
jhey | 0:604848fcb49c | 142 | Serial * gps_Serial; |
jhey | 0:604848fcb49c | 143 | Serial pct (USBTX, USBRX); |
jhey | 0:604848fcb49c | 144 | |
jhey | 0:604848fcb49c | 145 | int main() { |
jhey | 0:604848fcb49c | 146 | |
jhey | 0:604848fcb49c | 147 | 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 | 148 | |
jhey | 0:604848fcb49c | 149 | gps_Serial = new Serial(PTC17,PTC16); //serial object for use w/ GPS |
jhey | 0:604848fcb49c | 150 | Adafruit_GPS myGPS(gps_Serial); //object of Adafruit's GPS class |
jhey | 0:604848fcb49c | 151 | char c; //when read via Adafruit_GPS::read(), the class returns single character stored here |
jhey | 0:604848fcb49c | 152 | Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info? |
jhey | 0:604848fcb49c | 153 | const int refresh_Time = 2000; //refresh time in ms |
jhey | 0:604848fcb49c | 154 | |
jhey | 0:604848fcb49c | 155 | myGPS.begin(9600); //sets baud rate for GPS communication; note this may be changed via Adafruit_GPS::sendCommand(char *) |
jhey | 0:604848fcb49c | 156 | //a list of GPS commands is available at http://www.adafruit.com/datasheets/PMTK_A08.pdf |
jhey | 0:604848fcb49c | 157 | |
jhey | 0:604848fcb49c | 158 | 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 | 159 | myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); |
jhey | 0:604848fcb49c | 160 | myGPS.sendCommand(PGCMD_ANTENNA); |
jhey | 0:604848fcb49c | 161 | |
jhey | 0:604848fcb49c | 162 | pct.printf("Connection established at 115200 baud...\n"); |
jhey | 0:604848fcb49c | 163 | |
jhey | 0:604848fcb49c | 164 | wait(1); |
jhey | 0:604848fcb49c | 165 | |
jhey | 0:604848fcb49c | 166 | refresh_Timer.start(); //starts the clock on the timer |
jhey | 0:604848fcb49c | 167 | |
jhey | 0:604848fcb49c | 168 | while(true){ |
jhey | 0:604848fcb49c | 169 | c = myGPS.read(); //queries the GPS |
jhey | 0:604848fcb49c | 170 | |
jhey | 0:604848fcb49c | 171 | if (c) { pct.printf("%c", c); } //this line will echo the GPS data if not paused |
jhey | 0:604848fcb49c | 172 | |
jhey | 0:604848fcb49c | 173 | //check if we recieved a new message from GPS, if so, attempt to parse it, |
jhey | 0:604848fcb49c | 174 | if ( myGPS.newNMEAreceived() ) { |
jhey | 0:604848fcb49c | 175 | if ( !myGPS.parse(myGPS.lastNMEA()) ) { |
jhey | 0:604848fcb49c | 176 | continue; |
jhey | 0:604848fcb49c | 177 | } |
jhey | 0:604848fcb49c | 178 | } |
jhey | 0:604848fcb49c | 179 | |
jhey | 0:604848fcb49c | 180 | //check if enough time has passed to warrant printing GPS info to screen |
jhey | 0:604848fcb49c | 181 | //note if refresh_Time is too low or pc.baud is too low, GPS data may be lost during printing |
jhey | 0:604848fcb49c | 182 | if (refresh_Timer.read_ms() >= refresh_Time) { |
jhey | 0:604848fcb49c | 183 | refresh_Timer.reset(); |
jhey | 0:604848fcb49c | 184 | pct.printf("Time: %d:%d:%d.%u\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds); |
jhey | 0:604848fcb49c | 185 | pct.printf("Date: %d/%d/20%d\n", myGPS.day, myGPS.month, myGPS.year); |
jhey | 0:604848fcb49c | 186 | pct.printf("Fix: %d\n", (int) myGPS.fix); |
jhey | 0:604848fcb49c | 187 | pct.printf("Quality: %d\n", (int) myGPS.fixquality); |
jhey | 0:604848fcb49c | 188 | if (myGPS.fix) { |
jhey | 0:604848fcb49c | 189 | pct.printf("Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon); |
jhey | 0:604848fcb49c | 190 | pct.printf("Speed: %5.2f knots\n", myGPS.speed); |
jhey | 0:604848fcb49c | 191 | pct.printf("Angle: %5.2f\n", myGPS.angle); |
jhey | 0:604848fcb49c | 192 | pct.printf("Altitude: %5.2f\n", myGPS.altitude); |
jhey | 0:604848fcb49c | 193 | pct.printf("Satellites: %d\n", myGPS.satellites); |
jhey | 0:604848fcb49c | 194 | } |
jhey | 0:604848fcb49c | 195 | |
jhey | 0:604848fcb49c | 196 | } |
jhey | 0:604848fcb49c | 197 | |
jhey | 0:604848fcb49c | 198 | } |
jhey | 0:604848fcb49c | 199 | |
jhey | 0:604848fcb49c | 200 | |
reanimationxp | 1:b100ab44119d | 201 | } |
reanimationxp | 1:b100ab44119d | 202 | |
reanimationxp | 1:b100ab44119d | 203 | */ |