Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TinyGPS++.h>
- TinyGPSPlus gps;
- // The serial connection to the GPS device
- //SoftwareSerial ss(RXPin, TXPin);
- #define ss Serial1
- #define rst 32
- String str_lat="";
- String str_lon="";
- String str_date="";
- String str_time="";
- #define RXD1 17
- #define TXD1 16
- void setup()
- {
- Serial.begin(115200);
- pinMode(rst, OUTPUT);
- ss.begin(9600, SERIAL_8N1, RXD1, TXD1);
- delay(100);
- digitalWrite(rst, LOW);delay(500);
- //digitalWrite(rst, HIGH);delay(500);
- //digitalWrite(rst, LOW);delay(500);
- }
- void loop()
- {
- // This sketch displays information every time a new sentence is correctly encoded.
- while (ss.available() > 0)
- if (gps.encode(ss.read()))
- displayInfo();
- if (millis() > 5000 && gps.charsProcessed() < 10)
- {
- Serial.println(F("No GPS detected: check wiring."));
- while (true);
- }
- }
- void displayInfo()
- {
- String str_buf_lat = "";
- String str_buf_lon = "";
- String str_buf_date = "";
- String str_buf_time = "";
- Serial.print(F("Location: "));
- if (gps.location.isValid())
- {
- Serial.print(gps.location.lat(), 6);
- Serial.print(F(","));
- Serial.print(gps.location.lng(), 6);
- str_buf_lat = String(gps.location.lat(), 6);
- str_buf_lat = String(gps.location.lng(), 6);
- str_lat = str_buf_lat;
- str_lon = str_buf_lon;
- }
- 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());
- str_buf_date = String(gps.date.month()) + "/" + String(gps.date.day()) + "/" + String(gps.date.year());
- str_date = str_buf_date;
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- Serial.print(F(" "));
- if (gps.time.isValid())
- {
- int jam = gps.time.hour();
- jam = jam +7;
- if(jam >= 24 ){
- jam = jam - 24;
- }
- str_buf_time = String(jam) + ":" + String(gps.time.minute()) + ":" + String(gps.time.second());
- str_time = str_buf_time;
- Serial.print(str_time);
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- Serial.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement