Created
July 26, 2017 22:37
-
-
Save ShawnHymel/93221a27df79b566dd2ad1eb2c801b6a to your computer and use it in GitHub Desktop.
Parsed GPS NMEA data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
SoftwareSerial soft(10, 11); // Rx, Tx | |
// Globals | |
String utc = ""; // hhmmss.00 | |
String lat = ""; // DDMM.MMMM N/S | |
String lon = ""; // DDMM.MMMM E/W | |
String alt = ""; // x meters | |
void setup() { | |
Serial.begin(9600); | |
soft.begin(9600); | |
} | |
void loop() { | |
// Poll GPS for data | |
getGPS(); | |
// Print out time and the 'tudes | |
Serial.print("Time: "); | |
Serial.println(utc); | |
Serial.print("Latitude: "); | |
Serial.println(lat); | |
Serial.print("Longitude: "); | |
Serial.println(lon); | |
Serial.print("Altitude: "); | |
Serial.println(alt); | |
Serial.println(); | |
} | |
void getGPS() { | |
int index; | |
// Look for $GPGGA | |
if ( soft.find("$GPGGA,") ) { | |
// Parse message for time and position | |
utc = soft.readStringUntil(','); | |
lat = soft.readStringUntil(','); | |
lat.concat(soft.readStringUntil(',')); | |
lon = soft.readStringUntil(','); | |
lon.concat(soft.readStringUntil(',')); | |
// Flush data up until altitude | |
for ( int i = 0; i < 3; i++ ) { | |
soft.readStringUntil(','); | |
} | |
// Parse altitude data | |
alt = soft.readStringUntil(','); | |
alt.concat(soft.readStringUntil(',')); | |
// Flush rest of message | |
soft.readStringUntil('\r'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment