Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TinyGPS++.h>
- #include <SoftwareSerial.h>
- #include "U8glib.h"
- U8GLIB_ST7920_128X64 u8g(13, 11, 10, U8G_PIN_NONE);
- // Choose two Arduino pins to use for software serial
- int RXPin = 2;
- int TXPin = 3;
- int GPSBaud = 9600;
- // Create a TinyGPS++ object
- TinyGPSPlus gps;
- // Create a software serial port called "gpsSerial"
- SoftwareSerial gpsSerial(RXPin, TXPin);
- void draw(void) {
- // graphic commands to redraw the complete screen should be placed here
- u8g.setFont(u8g_font_7x13B);
- //u8g.setFont(u8g_font_osb21);
- u8g.drawStr( 0, 10, "Datum:");
- u8g.drawStr( 50, 10,(gps.date.month());
- u8g.drawStr( 60, 10,(gps.date.day());
- u8g.drawStr( 70, 10,(gps.date.year());
- u8g.drawStr(0, 22, "Uhr:");
- u8g.drawStr(50, 22,(gps.time.hour());
- u8g.drawStr(60, 22,(gps.time.minute());
- u8g.drawStr(70, 22,(gps.time.second());
- u8g.drawStr(0, 32, "Lat:");
- u8g.drawStr(50, 32, (gps.location.lat(), 6);
- u8g.drawStr(0, 42, "Long:");
- u8g.drawStr(50, 42, (gps.location.lng(), 6);
- u8g.drawStr(0, 52, "km/h:");
- u8g.drawStr(50, 52, (gps.speed.kmph());
- u8g.drawStr(0, 62, "High:");
- u8g.drawStr(50, 62, (gps.altitude.meters());
- }
- void setup()
- {
- // Start the Arduino hardware serial port at 9600 baud
- Serial.begin(9600);
- // Start the software serial port at the GPS's default baud
- gpsSerial.begin(GPSBaud);
- }
- void loop()
- {
- // This sketch displays information every time a new sentence is correctly encoded.
- while (gpsSerial.available() > 0)
- if (gps.encode(gpsSerial.read()))
- displayInfo();
- // If 5000 milliseconds pass and there are no characters coming in
- // over the software serial port, show a "No GPS detected" error
- if (millis() > 5000 && gps.charsProcessed() < 10)
- {
- Serial.println("No GPS detected");
- while(true);
- }
- }
- void displayInfo(){
- if (gps.location.isValid())
- {
- Serial.print("Latitude: ");
- Serial.println(gps.location.lat(), 6);
- Serial.print("Longitude: ");
- Serial.println(gps.location.lng(), 6);
- Serial.print("Altitude: ");
- Serial.println(gps.altitude.meters());
- }
- else
- {
- Serial.println("Location: Not Available");
- }
- Serial.print("Date: ");
- if (gps.date.isValid())
- {
- Serial.print(gps.date.month());
- Serial.print("/");
- Serial.print(gps.date.day());
- Serial.print("/");
- Serial.println(gps.date.year());
- }
- else
- {
- Serial.println("Not Available");
- }
- Serial.print("Kmh: ");
- if (gps.speed.kmph())
- {
- Serial.println(gps.speed.kmph());
- }
- else
- {
- Serial.println("Not Available");
- }
- Serial.print("Sat: ");
- if (gps.satellites.value())
- {
- Serial.println(gps.satellites.value());
- }
- else
- {
- Serial.println("Not Available");
- }
- Serial.print("Time: ");
- if (gps.time.isValid())
- {
- if (gps.time.hour() < 10) Serial.print(F("0"));
- Serial.print(gps.time.hour());
- Serial.print(":");
- if (gps.time.minute() < 10) Serial.print(F("0"));
- Serial.print(gps.time.minute());
- Serial.print(":");
- if (gps.time.second() < 10) Serial.print(F("0"));
- Serial.print(gps.time.second());
- Serial.print(".");
- if (gps.time.centisecond() < 10) Serial.print(F("0"));
- Serial.println(gps.time.centisecond());
- }
- else
- {
- Serial.println("Not Available");
- }
- Serial.println();
- Serial.println();
- delay(1000);
- u8g.firstPage();
- do {
- draw();
- } while ( u8g.nextPage() );
- }
Add Comment
Please, Sign In to add comment