Adafruit GPS , distance and count footsteps

Dependencies:   mbed SDFileSystem MBed_Adafruit-GPS-Library USBDevice

Committer:
the_nabil
Date:
Wed Dec 18 14:23:38 2019 +0000
Revision:
5:da8e5af9d44b
Parent:
4:e87d9fbc4869
Child:
6:f1b3ee4199b7
GPS Marche

Who changed what in which revision?

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