1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #include <TinyGPS++.h> // download from https://github.com/mikalhart/TinyGPSPlus
TinyGPSPlus gps;
#include <SoftwareSerial.h>
const uint8_t RXPin = 2; // the arduino pin on which to receive serial data from your GPS
const uint8_t TXPin = 3; // the arduino pin on which to transmit serial data to your GPS
SoftwareSerial gpsSerial(RXPin, TXPin);
void setup() {
Serial.begin(115200);
gpsSerial.begin(9600);
Serial.println(F("\n\n----\nA l'écoute\n"));
}
void loop() {
while (gpsSerial.available()) {
byte b = gpsSerial.read();
Serial.write((char) b);
if (gps.encode(b)) {
if (gps.location.isValid()) {
Serial.print(F("Position GPS1: ")); Serial.print(gps.location.lat(),6);
Serial.write(','); Serial.println(gps.location.lng(),6);
}
}
}
} |
Partager