Write Arduino GPS test sketch

This commit is contained in:
Starbeamrainbowlabs 2019-06-07 23:05:56 +01:00
parent 221641270a
commit 315a0be156
3 changed files with 88 additions and 0 deletions

3
.gitmodules vendored
View file

@ -7,3 +7,6 @@
[submodule "iot/libraries/arduino-lmic"]
path = iot/libraries/arduino-lmic
url = https://github.com/mcci-catena/arduino-lmic.git
[submodule "iot/libraries/TinyGPSPlus"]
path = iot/libraries/TinyGPSPlus
url = https://github.com/mikalhart/TinyGPSPlus.git

84
iot/GPSTest/GPSTest.ino Normal file
View file

@ -0,0 +1,84 @@
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
// NOTE: RX and TX must be swapped with respect to the pin definitions on the NE-6M itself.
#define PIN_GPS_RX 4
#define PIN_GPS_TX 3
#define BAUD_PC 115200
#define BAUD_GPS 9600
TinyGPSPlus gps;
SoftwareSerial serial_gps(PIN_GPS_RX, PIN_GPS_TX);
void setup();
void loop();
void gps_display();
void setup() {
Serial.begin(BAUD_PC);
serial_gps.begin(BAUD_GPS);
Serial.print("TinyGPS++ v");
Serial.print(TinyGPSPlus::libraryVersion());
Serial.println(" Test");
}
void loop() {
while(serial_gps.available() > 0) {
if(!gps.encode(serial_gps.read()))
continue;
gps_display();
}
if (millis() > 5000 && gps.charsProcessed() < 10) {
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
}
void gps_display() {
if(!gps.location.isUpdated()) return;
// From the device example
Serial.print(F("Location: "));
if (gps.location.isValid()) {
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
Serial.print(F(" "));
}
else
Serial.print(F("(invalid) "));
Serial.print(F("DateTime: "));
if (gps.date.isValid()) {
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else
Serial.print(F("(invalid) "));
Serial.print(F(" "));
if (gps.time.isValid()) {
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
}
else
Serial.print(F("(invalid)"));
Serial.println();
}

@ -0,0 +1 @@
Subproject commit b4c8e29d1def35806fb1fc75fe0013036843d643