Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- #include <TinyGPS.h>
- #include <Adafruit_GFX_AS8.h> // Core graphics library
- #include <Adafruit_ILI9341_AS8.h> // Hardware-specific library
- /* This sample code demonstrates the normal use of a TinyGPS object.
- It requires the use of SoftwareSerial, and assumes that you have a
- 4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
- */
- TinyGPS gps;
- //SoftwareSerial ss(4, 3);
- // The control pins for the LCD can be assigned to any digital or
- // analog pins...but we'll use the analog pins as this allows us to
- // double up the pins with the touch screen (see the TFT paint example).
- #define LCD_CS A3 // Chip Select goes to Analog 3
- #define LCD_CD A2 // Command/Data goes to Analog 2
- #define LCD_WR A1 // LCD Write goes to Analog 1
- #define LCD_RD A0 // LCD Read goes to Analog 0
- #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
- Adafruit_ILI9341_AS8 tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
- unsigned long targetTime = 0;
- byte red = 31;
- byte green = 0;
- byte blue = 0;
- byte state = 0;
- unsigned int colour = red << 11;
- void setup()
- {
- //Serial.begin(115200);
- Serial.begin(9600);
- Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version());
- Serial.println("by Mikal Hart");
- Serial.println();
- tft.reset();
- delay(10);
- tft.begin(0x9341);
- tft.setRotation(1);
- }
- void loop()
- {
- bool newData = false;
- unsigned long chars;
- unsigned short sentences, failed;
- // For one second we parse GPS data and report some key values
- for (unsigned long start = millis(); millis() - start < 1000;)
- {
- while (Serial.available())
- {
- char c = Serial.read();
- //Serial.write(c); // uncomment this line if you want to see the GPS data flowing
- if (gps.encode(c)) // Did a new valid sentence come in?
- newData = true;
- }
- }
- if (newData)
- {
- float flat, flon;
- unsigned long age;
- gps.f_get_position(&flat, &flon, &age);
- Serial.print("LAT=");
- Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
- Serial.print(" LON=");
- Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
- Serial.print(" SAT=");
- Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
- Serial.print(" PREC=");
- Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
- unsigned long fix_age, time, date, speed, course;
- gps.get_datetime(&date, &time, &fix_age);
- Serial.print(" Date=");
- Serial.print(date);
- int year;
- byte month, day, hour, minutes, seconds, hundredths;
- unsigned long fix_age2;
- String year_str;
- String month_str;
- String day_str;
- String hour_str;
- String minutes_str;
- String seconds_str;
- String hundredths_str;
- char year_char[5];
- char month_char[3];
- char day_char[3];
- char hour_char[3];
- char minutes_char[3];
- char seconds_char[4];
- char hundredths_char[5];
- gps.crack_datetime(&year, &month, &day, &hour, &minutes, &seconds, &hundredths, &fix_age2);
- tft.setTextSize(1);
- tft.fillScreen(ILI9341_BLACK);
- tft.setTextColor(ILI9341_GREEN);
- year_str=String(year);
- month_str=String(month);
- day_str=String(day);
- hour_str=String(hour);
- minutes_str=String(minutes);
- seconds_str=String(seconds);
- hundredths_str=String(hundredths);
- year_str.toCharArray(year_char,5);
- month_str.toCharArray(month_char,3);
- day_str.toCharArray(day_char,3);
- hour_str.toCharArray(hour_char,3);
- minutes_str.toCharArray(minutes_char,3);
- seconds_str.toCharArray(seconds_char,4);
- hundredths_str.toCharArray(hundredths_char,5);
- tft.drawString(year_char,0,0,2);
- tft.drawString(month_char,40,0,2);
- tft.drawString(day_char,60,0,2);
- tft.drawString(hour_char,80,0,2);
- tft.drawString(minutes_char,100,0,2);
- tft.drawString(seconds_char,120,0,2);
- tft.drawString(hundredths_char,140,0,2);
- int xpos=0;
- xpos+=tft.drawString("-------------",0,64,2);
- tft.drawChar(127,xpos,64,2);
- }
- gps.stats(&chars, &sentences, &failed);
- Serial.print(" CHARS=");
- Serial.print(chars);
- Serial.print(" SENTENCES=");
- Serial.print(sentences);
- Serial.print(" CSUM ERR=");
- Serial.println(failed);
- if (chars == 0)
- Serial.println("** No characters received from GPS: check wiring **");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement