Read GPS satellite fix, latitude, longitude, MSL altitude, speed (Km/Hour) over ground coordinates and heading (0-360deg).
Dependencies: Adafruit_FONA_SIMCOM_Library mbed
main.cpp
00001 /*################################################################################# 00002 00003 Program Name : SIM808 GPS 00004 Author : Crispin Mukalay 00005 Date Modified : 31/08/2018 00006 Compiler : ARMmbed 00007 Tested On : NUCLEO-F446RE 00008 00009 Description : Demonstrates the use of the SIM808 Shield to read the GPS 00010 satellite fix, latitude, longitude, MSL altitude, 00011 speed (Km/Hour) over ground coordinates and heading (0-360deg). 00012 00013 Requirements : * NUCLEO-F446RE Board 00014 * SIM808 GSM/GPS Module 00015 00016 Circuit : * The SIM808 module is connected as follows: 00017 VCC/5V/VIN - 5V 00018 GND - GND 00019 RXD - PA0 (F446's Serial4_TX pin) 00020 TXD - PA1 (F446's Serial4_RX pin) 00021 00022 ####################################################################################*/ 00023 00024 #include "mbed.h" 00025 #include "Adafruit_FONA.h" 00026 00027 Adafruit_FONA gps(PA_0, PA_1, PA_6, PA_7); //Create a Adafruit_FONA object called gps 00028 // TX RX RST RI 00029 //Not all SIM808-based boards have a RST (Reset) and RI (Ring Indicator) pin, 00030 //but when initializing the object one needs to specify them, even if they 00031 //are not there. In our case we just used two unused pins (PA_6 & PA_7) as "dummy" pins. 00032 00033 Serial pc(SERIAL_TX, SERIAL_RX); //to use the PC as a console (display output) 00034 00035 int main() { 00036 00037 int SIM808Success; 00038 bool gpsSuccess, gpsCoordinates; 00039 float fix, latitude, longitude, MSL_altitude, speed_kph, heading; 00040 00041 pc.printf("Program Started...\n"); 00042 00043 /* create connection to SIM808 */ 00044 pc.printf("\nConnecting to SIM808...\n"); 00045 SIM808Success = gps.begin(9600); //connect to SIM808 device at 9600 baud rate and return if successful(=1) or not (=0) 00046 00047 if(SIM808Success == 1) 00048 pc.printf("\nSIM808 detected successfully...\n"); 00049 else { 00050 pc.printf("\nSIM808 not detected!\n"); 00051 while(1); //program stops/freezes at this point if SIM808 not detected 00052 } 00053 00054 /* Enable GPS*/ 00055 gpsSuccess = gps.enableGPS(true); 00056 00057 if (gpsSuccess == true) 00058 pc.printf("\nGPS enable successful...\n"); 00059 else 00060 pc.printf("\nGPS enable failed!\n"); 00061 00062 00063 while(1) { 00064 wait(2); 00065 00066 /* Read coordinates from GPS*/ 00067 gpsCoordinates = gps.getGPS(&fix, &latitude, &longitude, &MSL_altitude, &speed_kph, &heading); 00068 00069 if(gpsCoordinates == true){ 00070 00071 if(fix == 1.0f){ 00072 pc.printf("\n"); 00073 pc.printf("Latitude: %.6f\n", latitude); 00074 pc.printf("Longitude: %.6f\n", longitude); 00075 pc.printf("MSL altitude: %.6f\n", MSL_altitude); 00076 pc.printf("Speed: %.6f kph\n", speed_kph); 00077 pc.printf("Heading: %.6f \n", heading); 00078 }else{ 00079 pc.printf("Waiting for satellite fix...\n"); 00080 } 00081 00082 }else{ 00083 pc.printf("Waiting for satellite fix...\n"); 00084 } 00085 } 00086 }
Generated on Fri Jul 15 2022 20:25:59 by
1.7.2