42 lines
1022 B
C++
42 lines
1022 B
C++
#include <TinyGPS++.h>
|
|
#include <SoftwareSerial.h>
|
|
|
|
#define BUFFER_SIZE 256
|
|
#define SERIAL_TX_PIN 4
|
|
#define SERIAL_RX_PIN 5
|
|
|
|
TinyGPSPlus gps;
|
|
SoftwareSerial serialGPS(SERIAL_RX_PIN, SERIAL_TX_PIN);
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
while (!Serial) {
|
|
; // wait for serial port to connect. Needed for native USB port only
|
|
}
|
|
|
|
serialGPS.begin(9600);
|
|
}
|
|
|
|
void loop() {
|
|
Serial.println("Running loop...");
|
|
while (serialGPS.available() > 0) {
|
|
Serial.println("GPS data available");
|
|
if (gps.encode(serialGPS.read())) {
|
|
Serial.println("GPS data read");
|
|
if (gps.location.isValid()) {
|
|
Serial.println("GPS location valid");
|
|
float latitude = gps.location.lat();
|
|
String latitudeStr = String(latitude , 6);
|
|
float longitude = gps.location.lng();
|
|
String longitudeStr = String(longitude , 6);
|
|
|
|
Serial.print("Lat: ");
|
|
Serial.print(latitudeStr);
|
|
Serial.print(" Lon: ");
|
|
Serial.println(longitudeStr);
|
|
}
|
|
}
|
|
}
|
|
delay(500);
|
|
}
|