Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TinyGPSPlus.h>
- String lon;
- String latt;
- TinyGPSPlus gps;
- void setup() {
- Serial.begin(9600);
- Serial2.begin(9600);
- delay(2000);
- }
- void loop() {
- readGPS_Data();
- }
- void readGPS_Data() {
- while (Serial2.available() > 0)
- if (gps.encode(Serial2.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()) {
- lon = String(gps.location.lng(), 6);
- latt = String(gps.location.lat(), 6);
- Serial.print("Lat: ");
- Serial.print(latt);
- Serial.print(F(","));
- Serial.print("Lng: ");
- Serial.print(lon);
- Serial.println();
- }
- else {
- Serial.println(F("INVALID"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment