Guest User

Untitled

a guest
Jun 5th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. #include <TinyGPS++.h>
  2. #include <SoftwareSerial.h>
  3. #include "U8glib.h"
  4. U8GLIB_ST7920_128X64 u8g(13, 11, 10, U8G_PIN_NONE);
  5.  
  6.  
  7. // Choose two Arduino pins to use for software serial
  8. int RXPin = 2;
  9. int TXPin = 3;
  10. int GPSBaud = 9600;
  11. // Create a TinyGPS++ object
  12. TinyGPSPlus gps;
  13.  
  14. // Create a software serial port called "gpsSerial"
  15. SoftwareSerial gpsSerial(RXPin, TXPin);
  16.  
  17.  
  18. void draw(void) {
  19. // graphic commands to redraw the complete screen should be placed here
  20. u8g.setFont(u8g_font_7x13B);
  21. //u8g.setFont(u8g_font_osb21);
  22. u8g.drawStr( 0, 10, "Datum:");
  23. u8g.drawStr( 50, 10,(gps.date.month());
  24. u8g.drawStr( 60, 10,(gps.date.day());
  25. u8g.drawStr( 70, 10,(gps.date.year());
  26.  
  27. u8g.drawStr(0, 22, "Uhr:");
  28. u8g.drawStr(50, 22,(gps.time.hour());
  29. u8g.drawStr(60, 22,(gps.time.minute());
  30. u8g.drawStr(70, 22,(gps.time.second());
  31.  
  32. u8g.drawStr(0, 32, "Lat:");
  33. u8g.drawStr(50, 32, (gps.location.lat(), 6);
  34.  
  35. u8g.drawStr(0, 42, "Long:");
  36. u8g.drawStr(50, 42, (gps.location.lng(), 6);
  37.  
  38. u8g.drawStr(0, 52, "km/h:");
  39. u8g.drawStr(50, 52, (gps.speed.kmph());
  40.  
  41. u8g.drawStr(0, 62, "High:");
  42. u8g.drawStr(50, 62, (gps.altitude.meters());
  43. }
  44.  
  45. void setup()
  46. {
  47. // Start the Arduino hardware serial port at 9600 baud
  48. Serial.begin(9600);
  49.  
  50. // Start the software serial port at the GPS's default baud
  51. gpsSerial.begin(GPSBaud);
  52. }
  53.  
  54. void loop()
  55. {
  56. // This sketch displays information every time a new sentence is correctly encoded.
  57. while (gpsSerial.available() > 0)
  58. if (gps.encode(gpsSerial.read()))
  59. displayInfo();
  60.  
  61. // If 5000 milliseconds pass and there are no characters coming in
  62. // over the software serial port, show a "No GPS detected" error
  63. if (millis() > 5000 && gps.charsProcessed() < 10)
  64. {
  65. Serial.println("No GPS detected");
  66. while(true);
  67. }
  68. }
  69.  
  70. void displayInfo(){
  71. if (gps.location.isValid())
  72. {
  73. Serial.print("Latitude: ");
  74. Serial.println(gps.location.lat(), 6);
  75. Serial.print("Longitude: ");
  76. Serial.println(gps.location.lng(), 6);
  77. Serial.print("Altitude: ");
  78. Serial.println(gps.altitude.meters());
  79. }
  80. else
  81. {
  82. Serial.println("Location: Not Available");
  83. }
  84.  
  85. Serial.print("Date: ");
  86. if (gps.date.isValid())
  87. {
  88. Serial.print(gps.date.month());
  89. Serial.print("/");
  90. Serial.print(gps.date.day());
  91. Serial.print("/");
  92. Serial.println(gps.date.year());
  93. }
  94. else
  95. {
  96. Serial.println("Not Available");
  97. }
  98. Serial.print("Kmh: ");
  99. if (gps.speed.kmph())
  100. {
  101. Serial.println(gps.speed.kmph());
  102.  
  103. }
  104. else
  105. {
  106. Serial.println("Not Available");
  107. }
  108. Serial.print("Sat: ");
  109. if (gps.satellites.value())
  110. {
  111. Serial.println(gps.satellites.value());
  112.  
  113. }
  114. else
  115. {
  116. Serial.println("Not Available");
  117. }
  118. Serial.print("Time: ");
  119. if (gps.time.isValid())
  120. {
  121. if (gps.time.hour() < 10) Serial.print(F("0"));
  122. Serial.print(gps.time.hour());
  123. Serial.print(":");
  124. if (gps.time.minute() < 10) Serial.print(F("0"));
  125. Serial.print(gps.time.minute());
  126. Serial.print(":");
  127. if (gps.time.second() < 10) Serial.print(F("0"));
  128. Serial.print(gps.time.second());
  129. Serial.print(".");
  130. if (gps.time.centisecond() < 10) Serial.print(F("0"));
  131. Serial.println(gps.time.centisecond());
  132. }
  133. else
  134. {
  135. Serial.println("Not Available");
  136. }
  137.  
  138. Serial.println();
  139. Serial.println();
  140. delay(1000);
  141.  
  142. u8g.firstPage();
  143. do {
  144. draw();
  145. } while ( u8g.nextPage() );
  146. }
Add Comment
Please, Sign In to add comment