Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3. #include <TinyGPS.h>
  4. #include <Adafruit_GFX_AS8.h> // Core graphics library
  5. #include <Adafruit_ILI9341_AS8.h> // Hardware-specific library
  6.  
  7. /* This sample code demonstrates the normal use of a TinyGPS object.
  8. It requires the use of SoftwareSerial, and assumes that you have a
  9. 4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
  10. */
  11.  
  12. TinyGPS gps;
  13. //SoftwareSerial ss(4, 3);
  14.  
  15. // The control pins for the LCD can be assigned to any digital or
  16. // analog pins...but we'll use the analog pins as this allows us to
  17. // double up the pins with the touch screen (see the TFT paint example).
  18. #define LCD_CS A3 // Chip Select goes to Analog 3
  19. #define LCD_CD A2 // Command/Data goes to Analog 2
  20. #define LCD_WR A1 // LCD Write goes to Analog 1
  21. #define LCD_RD A0 // LCD Read goes to Analog 0
  22.  
  23. #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
  24. Adafruit_ILI9341_AS8 tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  25.  
  26. unsigned long targetTime = 0;
  27. byte red = 31;
  28. byte green = 0;
  29. byte blue = 0;
  30. byte state = 0;
  31. unsigned int colour = red << 11;
  32.  
  33. void setup()
  34. {
  35. //Serial.begin(115200);
  36. Serial.begin(9600);
  37.  
  38. Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  39. Serial.println("by Mikal Hart");
  40. Serial.println();
  41.  
  42. tft.reset();
  43. delay(10);
  44. tft.begin(0x9341);
  45. tft.setRotation(1);
  46. }
  47.  
  48. void loop()
  49. {
  50. bool newData = false;
  51. unsigned long chars;
  52. unsigned short sentences, failed;
  53.  
  54. // For one second we parse GPS data and report some key values
  55. for (unsigned long start = millis(); millis() - start < 1000;)
  56. {
  57. while (Serial.available())
  58. {
  59. char c = Serial.read();
  60. //Serial.write(c); // uncomment this line if you want to see the GPS data flowing
  61. if (gps.encode(c)) // Did a new valid sentence come in?
  62. newData = true;
  63. }
  64. }
  65.  
  66. if (newData)
  67. {
  68. float flat, flon;
  69. unsigned long age;
  70. gps.f_get_position(&flat, &flon, &age);
  71. Serial.print("LAT=");
  72. Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
  73. Serial.print(" LON=");
  74. Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
  75. Serial.print(" SAT=");
  76. Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
  77. Serial.print(" PREC=");
  78. Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
  79.  
  80. unsigned long fix_age, time, date, speed, course;
  81. gps.get_datetime(&date, &time, &fix_age);
  82. Serial.print(" Date=");
  83. Serial.print(date);
  84.  
  85. int year;
  86. byte month, day, hour, minutes, seconds, hundredths;
  87. unsigned long fix_age2;
  88. String year_str;
  89. String month_str;
  90. String day_str;
  91. String hour_str;
  92. String minutes_str;
  93. String seconds_str;
  94. String hundredths_str;
  95. char year_char[5];
  96. char month_char[3];
  97. char day_char[3];
  98. char hour_char[3];
  99. char minutes_char[3];
  100. char seconds_char[4];
  101. char hundredths_char[5];
  102. gps.crack_datetime(&year, &month, &day, &hour, &minutes, &seconds, &hundredths, &fix_age2);
  103.  
  104. tft.setTextSize(1);
  105. tft.fillScreen(ILI9341_BLACK);
  106. tft.setTextColor(ILI9341_GREEN);
  107.  
  108.  
  109. year_str=String(year);
  110. month_str=String(month);
  111. day_str=String(day);
  112. hour_str=String(hour);
  113. minutes_str=String(minutes);
  114. seconds_str=String(seconds);
  115. hundredths_str=String(hundredths);
  116.  
  117.  
  118. year_str.toCharArray(year_char,5);
  119. month_str.toCharArray(month_char,3);
  120. day_str.toCharArray(day_char,3);
  121. hour_str.toCharArray(hour_char,3);
  122. minutes_str.toCharArray(minutes_char,3);
  123. seconds_str.toCharArray(seconds_char,4);
  124. hundredths_str.toCharArray(hundredths_char,5);
  125.  
  126. tft.drawString(year_char,0,0,2);
  127. tft.drawString(month_char,40,0,2);
  128. tft.drawString(day_char,60,0,2);
  129. tft.drawString(hour_char,80,0,2);
  130. tft.drawString(minutes_char,100,0,2);
  131. tft.drawString(seconds_char,120,0,2);
  132. tft.drawString(hundredths_char,140,0,2);
  133.  
  134. int xpos=0;
  135. xpos+=tft.drawString("-------------",0,64,2);
  136. tft.drawChar(127,xpos,64,2);
  137. }
  138.  
  139. gps.stats(&chars, &sentences, &failed);
  140. Serial.print(" CHARS=");
  141. Serial.print(chars);
  142. Serial.print(" SENTENCES=");
  143. Serial.print(sentences);
  144. Serial.print(" CSUM ERR=");
  145. Serial.println(failed);
  146. if (chars == 0)
  147. Serial.println("** No characters received from GPS: check wiring **");
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement