From 6b6da95535755ad6456e68e4f44f64b8d6b0b72c Mon Sep 17 00:00:00 2001 From: Corentin Dupont Date: Sat, 25 Jan 2020 23:11:02 +0100 Subject: [PATCH] GPS --- WaziDev.mk | 2 +- .../sensors/Position/NEO-6M/DeviceExample.ino | 98 +++++++++++++++++++ examples/sensors/Position/NEO-6M/Makefile | 1 + 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 examples/sensors/Position/NEO-6M/DeviceExample.ino create mode 100644 examples/sensors/Position/NEO-6M/Makefile diff --git a/WaziDev.mk b/WaziDev.mk index dee3257..650d41f 100644 --- a/WaziDev.mk +++ b/WaziDev.mk @@ -6,7 +6,7 @@ USER_LIB_PATH = /home/cdupont/Documents/Waziup/WaziDev/libraries BOARD_TAG = pro BOARD_SUB = 8MHzatmega328 MONITOR_PORT = /dev/ttyUSB0 -ARDUINO_LIBS = SPI SX1272 LowPower EEPROM U8g2 Wire TinyGPSPlus OneWire DHT Dallas-Temperature WaziDev LiquidCrystal AES-128_V10 Base64 +ARDUINO_LIBS = SPI SX1272 LowPower EEPROM U8g2 Wire TinyGPSPlus OneWire DHT Dallas-Temperature WaziDev LiquidCrystal AES-128_V10 Base64 SoftwareSerial MONITOR_BAUDRATE = 38400 include /usr/share/arduino/Arduino.mk diff --git a/examples/sensors/Position/NEO-6M/DeviceExample.ino b/examples/sensors/Position/NEO-6M/DeviceExample.ino new file mode 100644 index 0000000..6a5b307 --- /dev/null +++ b/examples/sensors/Position/NEO-6M/DeviceExample.ino @@ -0,0 +1,98 @@ +/******************** + * Program: NEO 6M GPS sensor tester + * Description: prints coordinates and date/time to serial + * Connections: + * NEO 6M GND -> GND + * NEO 6M VCC -> VCC + * NEO 6M TX -> D4 + * NEO 6M RX -> D3 + ********************/ +#include +#include + +static const int RXPin = 4, TXPin = 3; +static const uint32_t GPSBaud = 9600; + +// The TinyGPS++ object +TinyGPSPlus gps; +void displayInfo(); + +// The serial connection to the GPS device +SoftwareSerial ss(RXPin, TXPin); + +void setup() +{ + Serial.begin(38400); + ss.begin(GPSBaud); + + Serial.println(F("DeviceExample.ino")); + Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module")); + Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion()); + Serial.println(F("by Mikal Hart")); + Serial.println(); +} + +void loop() +{ + // This sketch displays information every time a new sentence is correctly encoded. + while (ss.available() > 0) + if (gps.encode(ss.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()) + { + Serial.print(gps.location.lat(), 6); + Serial.print(F(",")); + Serial.print(gps.location.lng(), 6); + } + else + { + Serial.print(F("INVALID")); + } + + Serial.print(F(" Date/Time: ")); + 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(); +} diff --git a/examples/sensors/Position/NEO-6M/Makefile b/examples/sensors/Position/NEO-6M/Makefile new file mode 100644 index 0000000..a30e837 --- /dev/null +++ b/examples/sensors/Position/NEO-6M/Makefile @@ -0,0 +1 @@ +include ../../../../WaziDev.mk