-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAIR_530.ino
More file actions
58 lines (49 loc) · 1.75 KB
/
Copy pathAIR_530.ino
File metadata and controls
58 lines (49 loc) · 1.75 KB
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
#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
// Define the RX and TX pins for SoftwareSerial
static const int RXPin = 10, TXPin = 11;
static const uint32_t GPSBaud = 9600;
// Create a TinyGPSPlus object
TinyGPSPlus gps;
// Set up SoftwareSerial to communicate with the GPS
SoftwareSerial ss(RXPin, TXPin);
void setup()
{
// Start serial communication at 115200 baud for the serial monitor
Serial.begin(9600);
// Start the SoftwareSerial communication at GPS baud rate (9600)
ss.begin(GPSBaud);
// Print setup message
Serial.println(F("GPS Coordinates and Time Retrieval"));
Serial.println(F("Using TinyGPSPlus Library"));
Serial.println(F("by Mikal Hart"));
Serial.println();
}
void loop()
{
// Continuously read data from the GPS and process it
while (ss.available() > 0) {
gps.encode(ss.read()); // Feed the data into the TinyGPSPlus object
}
// If we have updated coordinates and time, print them
//if (gps.location.isUpdated()) {
// Print Latitude and Longitude
Serial.print(F("Latitude: "));
Serial.print(gps.location.lat(), 6); // Print latitude with 6 decimal places
Serial.print(F(" Longitude: "));
Serial.println(gps.location.lng(), 6); // Print longitude with 6 decimal places
//}
// if (gps.time.isUpdated()) {
// Print UTC Time (hours, minutes, seconds)
Serial.print(F("Time (UTC): "));
Serial.print(gps.time.hour());
Serial.print(F(":"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
Serial.print(gps.time.second());
Serial.print(F("."));
Serial.println(gps.time.centisecond()); // Centisecond is a fraction of a second
//}
// Add a small delay to make output readable
//delay(500);
}