Add 'Seeed Wio Terminal/m5-gps-left.ino'
This commit is contained in:
103
Seeed Wio Terminal/m5-gps-left.ino
Normal file
103
Seeed Wio Terminal/m5-gps-left.ino
Normal file
@@ -0,0 +1,103 @@
|
||||
|
||||
#include <TinyGPS++.h>
|
||||
#include <wiring_private.h>
|
||||
|
||||
static const uint32_t GPSBaud = 115200;
|
||||
|
||||
// The TinyGPS++ object
|
||||
TinyGPSPlus gps;
|
||||
|
||||
// The serial connection to the GPS device - Left side Grove connector.
|
||||
// Left side Grove connector shares pins with I2C1 of 40 pin connector.
|
||||
static Uart Serial3(&sercom3, PIN_WIRE_SCL, PIN_WIRE_SDA, SERCOM_RX_PAD_1, UART_TX_PAD_0);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial3.begin(GPSBaud);
|
||||
pinPeripheral(PIN_WIRE_SCL, PIO_SERCOM_ALT);
|
||||
pinPeripheral(PIN_WIRE_SCL, PIO_SERCOM_ALT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// This sketch displays information every time a new sentence is correctly encoded.
|
||||
while (Serial3.available() > 0)
|
||||
if (gps.encode(Serial3.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();
|
||||
}
|
||||
|
||||
void SERCOM3_0_Handler()
|
||||
{
|
||||
Serial3.IrqHandler();
|
||||
}
|
||||
void SERCOM3_1_Handler()
|
||||
{
|
||||
Serial3.IrqHandler();
|
||||
}
|
||||
void SERCOM3_2_Handler()
|
||||
{
|
||||
Serial3.IrqHandler();
|
||||
}
|
||||
void SERCOM3_3_Handler()
|
||||
{
|
||||
Serial3.IrqHandler();
|
||||
}
|
||||
Reference in New Issue
Block a user