Created
April 25, 2023 16:45
-
-
Save guidani/dcf59f0c4f9bee7f18adb56992437376 to your computer and use it in GitHub Desktop.
teste 1 wemos gps
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
// Instalar a biblioteca TinyGPS | |
#include <TinyGPS.h> | |
#include <SoftwareSerial.h> | |
// Pinos da interface UART | |
#define PINO_RX 2 | |
#define PINO_TX 3 | |
// Instancia da biblioteca | |
TinyGPS gps; | |
// Serial para comunicar com o módulo | |
SoftwareSerial ss(PINO_RX, PINO_TX); | |
void setup() | |
{ | |
// Configura os pinos | |
pinMode(PINO_RX, INPUT); | |
pinMode(PINO_TX, OUTPUT); | |
// Inicia a comunicação serial padrão (monitor serial) | |
Serial.begin(9600); | |
// Inicia a comunicação serial com o modulo | |
ss.begin(9600); | |
} | |
void loop() | |
{ | |
bool newData = false; | |
unsigned long chars; | |
unsigned short sentences, failed; | |
for (unsigned long start = millis(); millis() - start < 1000;) | |
{ | |
while (ss.available()) | |
{ | |
char c = ss.read(); | |
// Processa a sentença e verifica se ela é válida | |
if (gps.encode(c)) | |
{ | |
newData = true; | |
} | |
} | |
} | |
// Se os dados foram válidos | |
if (newData){ | |
float flat, flon; | |
unsigned long age; | |
uint16_t ano; | |
uint8_t mes, dia, horas, minutos, segundos, centesimos; | |
// Extrai a latitude, longitude e o tempo dos dados | |
gps.f_get_position(&flat, &flon, &age); | |
if (flat != TinyGPS::GPS_INVALID_F_ANGLE && flon != TinyGPS::GPS_INVALID_F_ANGLE) | |
{ | |
Serial.print("Latitude = "); | |
Serial.println(flat, 6); | |
Serial.print("Longitude = "); | |
Serial.println(flon, 6); | |
Serial.print("Altitude = "); | |
Serial.println(gps.f_altitude()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment