forked from mkconer/ESP8266_GPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESP8266_GPS_OLED_Youtube.ino
79 lines (64 loc) · 3.35 KB
/
ESP8266_GPS_OLED_Youtube.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <TinyGPS++.h> // Tiny GPS Plus Library
#include <SoftwareSerial.h> // Software Serial Library so we can use other Pins for communication with the GPS module
#include <Adafruit_ssd1306syp.h> // Adafruit oled library for display
Adafruit_ssd1306syp display(4,5); // OLED display (SDA to Pin 4), (SCL to Pin 5)
static const int RXPin = 12, TXPin = 13; // Ublox 6m GPS module to pins 12 and 13
static const uint32_t GPSBaud = 9600; // Ublox GPS default Baud Rate is 9600
const double Home_LAT = **.******; // Your Home Latitude
const double Home_LNG = **.******; // Your Home Longitude
TinyGPSPlus gps; // Create an Instance of the TinyGPS++ object called gps
SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
void setup()
{
display.initialize(); // Initialize OLED display
display.clear(); // Clear OLED display
display.setTextSize(1); // Set OLED text size to small
display.setTextColor(WHITE); // Set OLED color to White
display.setCursor(0,0); // Set cursor to 0,0
display.println("GPS example");
display.println(TinyGPSPlus::libraryVersion());
display.update(); // Update display
delay(1500); // Pause 1.5 seconds
ss.begin(GPSBaud); // Set Software Serial Comm Speed to 9600
}
void loop()
{
display.clear();
display.setCursor(0,0);
display.print("Latitude : ");
display.println(gps.location.lat(), 5);
display.print("Longitude : ");
display.println(gps.location.lng(), 4);
display.print("Satellites: ");
display.println(gps.satellites.value());
display.print("Elevation : ");
display.print(gps.altitude.feet());
display.println("ft");
display.print("Time UTC : ");
display.print(gps.time.hour()); // GPS time UTC
display.print(":");
display.print(gps.time.minute()); // Minutes
display.print(":");
display.println(gps.time.second()); // Seconds
display.print("Heading : ");
display.println(gps.course.deg());
display.print("Speed : ");
display.println(gps.speed.mph());
unsigned long Distance_To_Home = (unsigned long)TinyGPSPlus::distanceBetween(gps.location.lat(),gps.location.lng(),Home_LAT, Home_LNG);
display.print("KM to Home: "); // Have TinyGPS Calculate distance to home and display it
display.print(Distance_To_Home);
display.update(); // Update display
delay(200);
smartDelay(500); // Run Procedure smartDelay
if (millis() > 5000 && gps.charsProcessed() < 10)
display.println(F("No GPS data received: check wiring"));
}
static void smartDelay(unsigned long ms) // This custom version of delay() ensures that the gps object is being "fed".
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}