Last active
April 28, 2024 06:54
-
-
Save KornWtp/d238863000637eb1834ab4d58d2812d5 to your computer and use it in GitHub Desktop.
ESP32+GPS ATGM336H GPS Module .ino
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 <TinyGPS++.h> | |
#include <HardwareSerial.h> | |
#define RXPin (16) | |
#define TXPin (17) | |
static const uint32_t GPSBaud = 9600; | |
// The TinyGPS++ object | |
TinyGPSPlus gps; | |
// The serial connection to the GPS device | |
HardwareSerial ss(2); | |
void setup() | |
{ | |
Serial.begin(115200); | |
ss.begin(GPSBaud, SERIAL_8N1, RXPin, TXPin, false); | |
Serial.println(TinyGPSPlus::libraryVersion()); | |
} | |
void loop() | |
{ | |
// This sketch displays information every time a new sentence is correctly encoded. | |
while (ss.available() > 0) | |
if (gps.encode(ss.read())) | |
displayInfo(); | |
if (millis() > 5000 && gps.charsProcessed() < 10) | |
{ | |
Serial.println(F("No GPS detected: check wiring.")); | |
while(true); | |
} | |
} | |
void displayInfo() | |
{ | |
Serial.print(F("Location: ")); | |
if (gps.location.isValid()) | |
{ | |
Serial.print(gps.location.lat(), 6); | |
Serial.print(F(",")); | |
Serial.print(gps.location.lng(), 6); | |
} | |
else | |
{ | |
Serial.print(F("INVALID")); | |
} | |
Serial.println(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Missing "}" in line 20