From 5429079fba9418eb7d87cf1f60b5b2b7a2668ef5 Mon Sep 17 00:00:00 2001 From: lewisxhe Date: Fri, 29 Mar 2024 12:05:36 +0800 Subject: [PATCH] Added GPSShield example --- README.MD | 1 + README_CN.MD | 1 + examples/GPSShield/GPSShield.ino | 99 ++++++++++++++++++++++++++++++++ platformio.ini | 6 +- 4 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 examples/GPSShield/GPSShield.ino diff --git a/README.MD b/README.MD index 1831132..83e88b5 100644 --- a/README.MD +++ b/README.MD @@ -13,6 +13,7 @@ examples ├─Keyboard_T_Deck_Master # T-Deck read from keyboard ├─Microphone # Noise detection ├─Touchpad # Read touch coordinates +├─GPSShield # GPS Shield example └─UnitTest # Factory hardware unit testing ```` diff --git a/README_CN.MD b/README_CN.MD index eb13830..811a361 100644 --- a/README_CN.MD +++ b/README_CN.MD @@ -15,6 +15,7 @@ examples ├─Keyboard_T_Deck_Master # T-Deck read from keyboard ├─Microphone # Noise detection ├─Touchpad # Read touch coordinates +├─GPSShield # GPS Shield example └─UnitTest # Factory hardware unit testing ```` diff --git a/examples/GPSShield/GPSShield.ino b/examples/GPSShield/GPSShield.ino new file mode 100644 index 0000000..c7056be --- /dev/null +++ b/examples/GPSShield/GPSShield.ino @@ -0,0 +1,99 @@ +/** + * @file GPSShield.ino + * @author Lewis He (lewishe@outlook.com) + * @license MIT + * @copyright Copyright (c) 2024 Shenzhen Xin Yuan Electronic Technology Co., Ltd + * @date 2024-03-29 + * @note This sketch only applies to boards carrying GPS shields, the default is T-Deck + * It does not support GPS function. Of course, you can use an external GPS module to connect to the Gover interface. + */ + +#ifndef SerialGPS +#define SerialGPS Serial1 +#endif + +#define BOARD_GPS_TX_PIN 43 +#define BOARD_GPS_RX_PIN 44 + +#define BOARD_POWERON 10 + +#include +#include + +TinyGPSPlus gps; + + +void setup() +{ + Serial.begin(115200); + + //!⚠️ The board peripheral power control pin needs to be set to HIGH when using the peripheral + pinMode(BOARD_POWERON, OUTPUT); + digitalWrite(BOARD_POWERON, HIGH); + + //GPS Serial port + SerialGPS.begin(38400, SERIAL_8N1, BOARD_GPS_RX_PIN, BOARD_GPS_TX_PIN); + + Serial.println("This sketch only applies to boards carrying GPS shields, the default is T-Deck"); + + Serial.println("It does not support GPS function. Of course, you can use an external GPS module to connect to the Gover interface."); + + + delay(2000); + +} + +void loop() +{ + while (SerialGPS.available()) { + int c = SerialGPS.read(); + // Serial.write(c); + if (gps.encode(c)) { + displayInfo(); + } + } + delay(1); +} + + +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/platformio.ini b/platformio.ini index 53dff7d..15e307d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -23,6 +23,7 @@ src_dir = examples/UnitTest ; src_dir = examples/Microphone ; src_dir = examples/Touchpad ; src_dir = examples/Keyboard_T_Deck_Master +; src_dir = examples/GPSShield ; src_dir = examples/LvglArduinoVNC_VGA @@ -44,15 +45,14 @@ build_flags = -DBOARD_HAS_PSRAM ; Enable UARDUINO_ USB_ CDC_ ON_ BOOT will start printing and wait for terminal access during startup - ; -DARDUINO_USB_CDC_ON_BOOT=1 + -DARDUINO_USB_CDC_ON_BOOT=1 ; Enable UARDUINO_USB_CDC_ON_BOOT will turn off printing and will not block when using the battery - -UARDUINO_USB_CDC_ON_BOOT + ; -UARDUINO_USB_CDC_ON_BOOT -DDISABLE_ALL_LIBRARY_WARNINGS -extra_scripts = ./script/pos_extra_script.py [env:T-Deck] extends = env