Last active
August 9, 2023 10:52
-
-
Save KornWtp/08fe5d32d22064d1eda9d175635ede1c to your computer and use it in GitHub Desktop.
esp32+128x64 lcd+gps.io
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 <U8g2lib.h> | |
#include <TinyGPS++.h> | |
#include <HardwareSerial.h> | |
#define TXPin (16) | |
#define RXPin (17) | |
#ifdef U8X8_HAVE_HW_SPI | |
#include <SPI.h> | |
#endif | |
#ifdef U8X8_HAVE_HW_I2C | |
#include <Wire.h> | |
#endif | |
const int offset = 7; //Time Zone | |
void getPosition(); | |
float latitude , longitude; | |
int Year; | |
byte Hour , Minute , Second , Month , Day ; | |
int Timezone = 7; | |
U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18, /* MOSI=*/ 23, /* MISO=*/ 19); | |
static const uint32_t GPSBaud = 9600; | |
TinyGPSPlus gps; | |
// The serial connection to the GPS device | |
HardwareSerial ss(2); | |
void setup(void) { | |
Serial.begin(115200); | |
u8g2.begin(); | |
ss.begin(GPSBaud); | |
} | |
void loop(void) { | |
getPosition(); | |
u8g2.clearBuffer(); // clear the internal memory | |
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font | |
u8g2.drawStr(40,10,"Position"); | |
u8g2.drawStr(0,20,"Latitude : "); | |
u8g2.setCursor(60,20); | |
u8g2.print(latitude,6); | |
u8g2.drawStr(0,30,"Longitude : "); | |
u8g2.setCursor(70,30); | |
u8g2.print(longitude,6); | |
u8g2.drawStr(0,40,"Date : "); | |
u8g2.setCursor(40,40); | |
u8g2.print(Day); | |
u8g2.print("/"); | |
u8g2.print(Month); | |
u8g2.print("/"); | |
u8g2.print(Year); | |
u8g2.drawStr(0,50,"Time :"); | |
u8g2.setCursor(45,50); | |
u8g2.print(Hour+Timezone); | |
u8g2.print(":"); | |
u8g2.print(Minute); | |
u8g2.print(":"); | |
u8g2.print(Second); | |
u8g2.sendBuffer(); // transfer internal memory to the display | |
delay(1000); | |
} | |
void getPosition(){ | |
while (ss.available() > 0){ | |
if (gps.encode(ss.read())){ | |
Serial.print(F("Location: ")); | |
if (gps.location.isValid()){ | |
latitude = gps.location.lat(), 6; | |
longitude = gps.location.lng(), 6; | |
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()){ | |
Month = gps.date.month(); | |
Day = gps.date.day(); | |
Year = gps.date.year(); | |
Serial.print(gps.date.year()); | |
Serial.print(F("/")); | |
Serial.print(gps.date.month()); | |
Serial.print(F("/")); | |
Serial.print(gps.date.day()); | |
} | |
else { | |
Serial.print(F("INVALID")); | |
} | |
Serial.print(F(" ")); | |
if (gps.time.isValid()){ | |
if (gps.time.hour() < 10) Serial.print(F("0")); | |
Hour = gps.time.hour(); | |
Serial.print(gps.time.hour()); | |
Serial.print(F(":")); | |
if (gps.time.minute() < 10) Serial.print(F("0")); | |
Minute = gps.time.minute(); | |
Serial.print(gps.time.minute()); | |
Serial.print(F(":")); | |
if (gps.time.second() < 10) Serial.print(F("0")); | |
Second = gps.time.second(); | |
Serial.print(gps.time.second()); | |
} | |
else{ | |
Serial.print(F("INVALID")); | |
} | |
Serial.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment