Adafruit GPS , distance and count footsteps

Dependencies:   mbed SDFileSystem MBed_Adafruit-GPS-Library USBDevice

Committer:
reanimationxp
Date:
Thu Dec 22 05:55:53 2016 +0000
Revision:
2:7166ad3f9a2a
Parent:
1:b100ab44119d
Child:
3:e38a115af1dd
adding jhey's new new code. again. -reanimationxp

Who changed what in which revision?

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