You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
#include "TinyGPS++.h";
|
|
|
|
#define GPS_RX_PIN 16
|
|
#define GPS_TX_PIN 17
|
|
|
|
TinyGPSPlus gps;
|
|
|
|
/* LAT = latitude
|
|
LON = longitude
|
|
ALT = altitude
|
|
Note: all 32-bit flaoting point decimal operations ARE atomic for the ESP32.
|
|
This means that sharing data across threads and cores IS SAFE!
|
|
So launching the web server on a separate thread will ot cause a data race */
|
|
float LAT, LON, ALT;
|
|
|
|
void setup() {
|
|
/*
|
|
Serial speed of USB.
|
|
NOTE: this model of ESP has a native baud rate of 115200, meaning that boot message will display properly along with all other serial output
|
|
*/
|
|
Serial.begin(115200);
|
|
// Serial speed of GPS module
|
|
Serial2.begin(9600, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN);
|
|
Serial.println("Setup complete!");
|
|
}
|
|
|
|
void loop() {
|
|
// if there is anything to read from serial port 2
|
|
while (Serial2.available()) {
|
|
// read one character into the char "in"
|
|
char in = Serial2.read();
|
|
//Serial.print(in);
|
|
// send to GPS encoder to create new data
|
|
gps.encode(in);
|
|
// if a new location is given
|
|
if (gps.location.isUpdated()) {
|
|
// set all location attributes we desire
|
|
LAT = gps.location.lat();
|
|
LON = gps.location.lng();
|
|
ALT = gps.altitude.meters();
|
|
Serial.print("LAT=");
|
|
Serial.print(LAT, 6);
|
|
Serial.print(" LON=");
|
|
Serial.print(LON, 6);
|
|
Serial.print(" ALT=");
|
|
Serial.println(ALT, 6);
|
|
} // close if
|
|
} // close while
|
|
} // close loop
|