Browse Source

Add 'Seeed Wio Terminal/projects/m5-gps.ino'

cube 8 months ago
parent
commit
8af14de3fa
1 changed files with 116 additions and 0 deletions
  1. 116
    0
      Seeed Wio Terminal/projects/m5-gps.ino

+ 116
- 0
Seeed Wio Terminal/projects/m5-gps.ino View File

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