Created
March 7, 2025 07:10
-
-
Save fxprime/5b27b4baaa529ff7aa281b0c9e20dabf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <SoftwareSerial.h> | |
#include <TinyGPSPlus.h> | |
EspSoftwareSerial::UART gpsSerial; | |
TinyGPSPlus gps; | |
void displayInfo(); | |
void setup() { | |
Serial.begin(115200); | |
gpsSerial.begin(9600, EspSoftwareSerial::SWSERIAL_8N1, 5, 18, false, 95, 11); | |
} | |
void loop() { | |
while(gpsSerial.available()) | |
if (gps.encode(gpsSerial.read())) | |
displayInfo(); | |
// if (gpsSerial.available()) { | |
// Serial.write(gpsSerial.read()); | |
// } | |
// if (Serial.available()) { | |
// gpsSerial.write(Serial.read()); | |
// } | |
} | |
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(); | |
} | |
// ค่าที่ออกมา โดยประมาณ หลังมีไฟกระพริบตรงโมดูล GPS โดยปกติ เปิดใช้งานกับบ้านชั้นเดียวรอไม่เกิน10นาทีในครั้งแรก หลังจากเปิดมาแล้วหลายครั้งจะเร็วขึ้น และมีข้อมูลที่ออกมาดังนี้ | |
/* | |
Location: 7.855752,98.358536 Date/Time: 3/6/2025 12:38:00.00 | |
Location: 7.855752,98.358536 Date/Time: 3/6/2025 12:38:00.00 | |
Location: 7.855752,98.358536 Date/Time: 3/6/2025 12:38:00.00 | |
Location: 7.855752,98.358536 Date/Time: 3/6/2025 12:38:00.00 | |
Location: 7.855752,98.358536 Date/Time: 3/6/2025 12:38:00.00 | |
Location: 7.855752,98.358536 Date/Time: 3/6/2025 12:38:00.00 | |
Location: 7.855752,98.358536 Date/Time: 3/6/2025 12:38:00.00 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment