Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 00002 #include "mbed.h" 00003 #include "GPS.h" 00004 00005 Serial pc(D8, PA_10); // tx, rx 00006 DigitalOut led1(LED1); 00007 00008 // SET THIS. 00009 // Create an instance of the GPS object. You will need to 00010 // set p25 to whichever Serial RX pin you have connected 00011 // your GPS module to. 00012 GPS gps(NC, D0); 00013 00014 char rmc[GPS_BUFFER_LEN]; 00015 char gga[GPS_BUFFER_LEN]; 00016 char vtg[GPS_BUFFER_LEN]; 00017 char ukn[GPS_BUFFER_LEN]; 00018 00019 // 0.1 second flash of LED2 00020 DigitalOut led2(LED2); 00021 Timeout t2; 00022 void t2out(void) { led2 = 0; } 00023 void blip2(void) { led2 = 1; t2.attach(&t2out, 0.1); } 00024 00025 // 0.1 second flash of LED3 00026 DigitalOut led3(LED3); 00027 Timeout t3; 00028 void t3out(void) { led3 = 0; } 00029 void blip3(void) { led3 = 1; t3.attach(&t3out, 0.1); } 00030 00031 // 0.1 second flash of LED4 00032 DigitalOut led4(LED4); 00033 00034 Timeout t4; 00035 void t4out(void) { led4 = 0; } 00036 void blip4(void) { led4 = 1; t4.attach(&t4out, 0.1); } 00037 00038 int main() { 00039 GPS_Time q1; 00040 00041 // SET THIS. 00042 // Ensure you set the baud rate to match your serial 00043 // communications to your PC/Max/Linux host so you 00044 // can read the messages. 00045 pc.baud(PCBAUD); 00046 00047 // Tell MODGPS "we want copies of the NMEA sentences". When a callback 00048 // is made our buffers will contain a copy of the last received sentence 00049 // before it was processed/destroyed. 00050 gps.setRmc(rmc); 00051 gps.setGga(gga); 00052 gps.setVtg(vtg); 00053 gps.setUkn(ukn); 00054 00055 // SET THIS. 00056 // Most GPS modules use 9600,8,n,1 so that's what 00057 // we default to here. Ensure your GPS module matches 00058 // this, otherwise set it to match. 00059 gps.baud(GPSBUAD); 00060 gps.format(8, GPS::None, 1); 00061 00062 // OPTIONAL 00063 // If you GPS has a 1 pulse per second output you can 00064 // connect it to an Mbed pin. Here you specify what pin 00065 // and on what "edge" teh signal is active. If your GPS 00066 // module has a rising edge at the one second point then 00067 // use GPS::ppsRise 00068 #ifdef PPSPIN 00069 gps.ppsAttach(PPSPIN, GPS::ppsFall); 00070 #endif 00071 00072 // Sample of a callback to a function when the 1PPS activates. 00073 // For this example, we flash LED2 for 0.1 second. 00074 gps.attach_pps(&blip2); 00075 00076 // Sample of a callback to a function when a NMEA GGA message is recieved. 00077 // For this example, we flash LED2 for 0.1 second. 00078 gps.attach_gga(&blip3); 00079 00080 // Sample of a callback to a function when a NMEA RMC message is recieved. 00081 // For this example, we flash LED2 for 0.1 second. 00082 gps.attach_rmc(&blip4); 00083 00084 while(1) { 00085 // Every 3 seconds, flip LED1 and print the basic GPS info. 00086 wait(3); 00087 led1 = 1; 00088 00089 // Demonstrate how to find out the GPS location co-ords. 00090 pc.printf("Method 1. Lat = %.4f ", gps.latitude()); 00091 pc.printf("Lon = %.4f ", gps.longitude()); 00092 pc.printf("Alt = %.4f ", gps.altitude()); 00093 00094 // Gran a snapshot of the current time. 00095 gps.timeNow(&q1); 00096 pc.printf("%02d:%02d:%02d %02d/%02d/%04d\r\n", 00097 q1.hour, q1.minute, q1.second, q1.day, q1.month, q1.year); 00098 00099 // Alternative method that does the same thing. 00100 pc.printf("Method 2. Lat = %.4f ", gps.latitude()); 00101 pc.printf("Lon = %.4f ", gps.longitude()); 00102 pc.printf("Alt = %.4f ", gps.altitude()); 00103 00104 GPS_Time *q2 = gps.timeNow(); 00105 pc.printf("%02d:%02d:%02d %02d/%02d/%04d\r\n\n", 00106 q2->hour, q2->minute, q2->second, q2->day, q2->month, q2->year); 00107 delete(q2); 00108 led1 = 0; 00109 } 00110 } 00111
Generated on Wed Jul 20 2022 06:29:12 by
1.7.2