|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
|
|
|
2
|
+#include <TinyGPS++.h>
|
|
|
3
|
+#include <wiring_private.h>
|
|
|
4
|
+
|
|
|
5
|
+static const uint32_t GPSBaud = 115200;
|
|
|
6
|
+
|
|
|
7
|
+// The TinyGPS++ object
|
|
|
8
|
+TinyGPSPlus gps;
|
|
|
9
|
+
|
|
|
10
|
+// The serial connection to the GPS device - Left side Grove connector.
|
|
|
11
|
+// Left side Grove connector shares pins with I2C1 of 40 pin connector.
|
|
|
12
|
+static Uart Serial3(&sercom3, PIN_WIRE_SCL, PIN_WIRE_SDA, SERCOM_RX_PAD_1, UART_TX_PAD_0);
|
|
|
13
|
+
|
|
|
14
|
+void setup()
|
|
|
15
|
+{
|
|
|
16
|
+ Serial.begin(115200);
|
|
|
17
|
+
|
|
|
18
|
+ Serial3.begin(GPSBaud);
|
|
|
19
|
+ pinPeripheral(PIN_WIRE_SCL, PIO_SERCOM_ALT);
|
|
|
20
|
+ pinPeripheral(PIN_WIRE_SCL, PIO_SERCOM_ALT);
|
|
|
21
|
+}
|
|
|
22
|
+
|
|
|
23
|
+void loop()
|
|
|
24
|
+{
|
|
|
25
|
+ // This sketch displays information every time a new sentence is correctly encoded.
|
|
|
26
|
+ while (Serial3.available() > 0)
|
|
|
27
|
+ if (gps.encode(Serial3.read()))
|
|
|
28
|
+ displayInfo();
|
|
|
29
|
+
|
|
|
30
|
+ if (millis() > 5000 && gps.charsProcessed() < 10)
|
|
|
31
|
+ {
|
|
|
32
|
+ Serial.println(F("No GPS detected: check wiring."));
|
|
|
33
|
+ while(true);
|
|
|
34
|
+ }
|
|
|
35
|
+}
|
|
|
36
|
+
|
|
|
37
|
+void displayInfo()
|
|
|
38
|
+{
|
|
|
39
|
+ Serial.print(F("Location: "));
|
|
|
40
|
+ if (gps.location.isValid())
|
|
|
41
|
+ {
|
|
|
42
|
+ Serial.print(gps.location.lat(), 6);
|
|
|
43
|
+ Serial.print(F(","));
|
|
|
44
|
+ Serial.print(gps.location.lng(), 6);
|
|
|
45
|
+ }
|
|
|
46
|
+ else
|
|
|
47
|
+ {
|
|
|
48
|
+ Serial.print(F("INVALID"));
|
|
|
49
|
+ }
|
|
|
50
|
+
|
|
|
51
|
+ Serial.print(F(" Date/Time: "));
|
|
|
52
|
+ if (gps.date.isValid())
|
|
|
53
|
+ {
|
|
|
54
|
+ Serial.print(gps.date.month());
|
|
|
55
|
+ Serial.print(F("/"));
|
|
|
56
|
+ Serial.print(gps.date.day());
|
|
|
57
|
+ Serial.print(F("/"));
|
|
|
58
|
+ Serial.print(gps.date.year());
|
|
|
59
|
+ }
|
|
|
60
|
+ else
|
|
|
61
|
+ {
|
|
|
62
|
+ Serial.print(F("INVALID"));
|
|
|
63
|
+ }
|
|
|
64
|
+
|
|
|
65
|
+ Serial.print(F(" "));
|
|
|
66
|
+ if (gps.time.isValid())
|
|
|
67
|
+ {
|
|
|
68
|
+ if (gps.time.hour() < 10) Serial.print(F("0"));
|
|
|
69
|
+ Serial.print(gps.time.hour());
|
|
|
70
|
+ Serial.print(F(":"));
|
|
|
71
|
+ if (gps.time.minute() < 10) Serial.print(F("0"));
|
|
|
72
|
+ Serial.print(gps.time.minute());
|
|
|
73
|
+ Serial.print(F(":"));
|
|
|
74
|
+ if (gps.time.second() < 10) Serial.print(F("0"));
|
|
|
75
|
+ Serial.print(gps.time.second());
|
|
|
76
|
+ Serial.print(F("."));
|
|
|
77
|
+ if (gps.time.centisecond() < 10) Serial.print(F("0"));
|
|
|
78
|
+ Serial.print(gps.time.centisecond());
|
|
|
79
|
+ }
|
|
|
80
|
+ else
|
|
|
81
|
+ {
|
|
|
82
|
+ Serial.print(F("INVALID"));
|
|
|
83
|
+ }
|
|
|
84
|
+
|
|
|
85
|
+ Serial.println();
|
|
|
86
|
+}
|
|
|
87
|
+
|
|
|
88
|
+void SERCOM3_0_Handler()
|
|
|
89
|
+{
|
|
|
90
|
+ Serial3.IrqHandler();
|
|
|
91
|
+}
|
|
|
92
|
+void SERCOM3_1_Handler()
|
|
|
93
|
+{
|
|
|
94
|
+ Serial3.IrqHandler();
|
|
|
95
|
+}
|
|
|
96
|
+void SERCOM3_2_Handler()
|
|
|
97
|
+{
|
|
|
98
|
+ Serial3.IrqHandler();
|
|
|
99
|
+}
|
|
|
100
|
+void SERCOM3_3_Handler()
|
|
|
101
|
+{
|
|
|
102
|
+ Serial3.IrqHandler();
|
|
|
103
|
+}
|