/*
plakemphet
5/02/2022
ArduNano LatLong-01
OLED 128x64
การต่อใช้งาน
Vcc - > 3.3 / 5 V
Gnd -> Gnd
SCL -> A5
SDA -> A4
GPS Pins
RED = +5V
GREEN = Tx connected to Rx on NANO Pin 11
WHITE = Rx connected to Tx on NANO P:in 10
BLACK = GND
*/
#include "Adafruit_GFX.h"
#include "Adafruit_SH1106.h"
#include "TinyGPSPlus.h"
#include <SoftwareSerial.h>
static const int RXPin = 11, TXPin = 10;
static const uint32_t GPSBaud = 4800;
// The TinyGPSPlus object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
#define OLED_RESET 4
Adafruit_SH1106 OLED(OLED_RESET);
String locDate, locHour, locMin, locSec;
void setup()
{
Serial.begin(115200);
ss.begin(GPSBaud);
OLED.begin(SH1106_SWITCHCAPVCC, 0x3C);
OLED.clearDisplay();
OLED.setTextSize(2);
OLED.setTextColor(WHITE);
OLED.setCursor(0, 5);
OLED.println("GPS Info");
OLED.display();
delay(1000);
OLED.clearDisplay();
}
void loop()
{
showLocation();
smartDelay(1000);
}
void showLocation()
{
// Show Location
OLED.setTextSize(1);
OLED.setCursor(0, 0);
OLED.fillRect(0, 0, OLED.width(), 10, BLACK);
OLED.print("Sat: ");
OLED.print(gps.satellites.value());
OLED.print(" Alt: ");
OLED.println(gps.altitude.meters());
OLED.display();
OLED.setTextSize(2);
OLED.fillRect(0, 20, OLED.width(), 40, BLACK);
OLED.setCursor(0, 20);
OLED.print(gps.location.lat(), 6);
OLED.setCursor(0, 40);
OLED.setCursor(0, 40);
OLED.println(gps.location.lng(), 6);
OLED.display();
}
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}