If you own the Display and the GPS Module, This'll kick you right off into getting the values.
It is mainly for a Portable MPH display.
If you can suggest any improvements to the code, That'll help gladly as i'm seeing flickering a little although it's not bad.
I'd rather have no flicker at all :p I'm also thinking this is because of adafruits lazy for loop rendering (x,y)
Sorry adafruit your library sucks and needs a professional C++ coder to update with some propper algorithms.
UPDATES
1: Removed line of code. (Unix_Guru)
2: Removed Useless If checks than were required. (TOTAL_Noob)
Contrubutors:
1: Unix_Guru
__________________________________________________________________
[code]
#include "SoftwareSerial.h"
#include "SPI.h"
#include "Adafruit_GPS.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"
#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
Adafruit_GPS GPS(&Serial3);
HardwareSerial mySerial = Serial3;
#define GPSECHO true
#define _sclk 13 //52 MEGA
#define _miso 12 //50 MEGA
#define _mosi 11 //51 MEGA
#define _cs 10
#define _dc 9
#define _rst 8
Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);
void setup()
{
Serial.begin(115200);
tft.begin();
//tft.invertDisplay(1);
tft.setRotation(3);
tft.fillScreen(ILI9340_WHITE);
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
GPS.sendCommand(PGCMD_ANTENNA);
delay(100);
}
uint32_t timer = millis();
String xspeed = 0;
int xspeed1 = 0;
int text_done = 0;
int mov = 40;
void loop()
{
char c = GPS.read();
if ((c) && (GPSECHO))
Serial.write(c);
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA()))
return;
}
if (millis() - timer > 500) {
timer = millis();
if (GPS.fix != 1) {
}
if (GPS.fix == 1) {
unsigned long start = micros();
tft.setTextSize(2);
tft.fillRect(70,4, 240, 20, ILI9340_RED);
tft.setCursor(23, 7);
tft.setTextColor(ILI9340_RED);
if (text_done == 0)
{
tft.print("Geo: ");
tft.setTextSize(6);
tft.setCursor(10, 28);
tft.setTextColor(ILI9340_RED);
tft.setTextSize(5);
tft.print("MPH");
tft.setTextSize(1);
tft.setCursor(150 + mov, 32);
tft.print("Sats: ");
tft.setCursor(150 + mov, 40);
tft.print("Date: ");
tft.setCursor(150 + mov, 48);
tft.print("Time: ");
tft.setCursor(150 + mov, 57);
tft.print("Alti: ");
}
tft.setTextColor(ILI9340_WHITE);
tft.setCursor(80, 7);
if (GPS.lat == 'E') {
tft.print("-");
tft.print(GPS.latitude);
tft.print(GPS.lat);
}
else {
tft.print(GPS.latitude);
tft.print(GPS.lat);
}
tft.print(" ");
if (GPS.lon == 'W') {
tft.print("-");
tft.print(GPS.longitude);
tft.println(GPS.lon);
}
else {
tft.print(GPS.longitude);
tft.println(GPS.lon);
}
tft.fillRect(220,28, 90, 40, ILI9340_WHITE);
tft.setTextSize(1);
tft.setTextColor(ILI9340_BLUE);
tft.setCursor(190 + mov, 30);
tft.println(GPS.satellites);
tft.setCursor(190 + mov, 40);
tft.print(GPS.day);
tft.print("/");
tft.print(GPS.month);
tft.print("/");
tft.println(GPS.year);
tft.setCursor(190 + mov, 48);
tft.print(GPS.hour);
tft.print(":");
tft.print(GPS.minute);
tft.print(":");
tft.println(GPS.seconds);
tft.setCursor(190 + mov, 57);
tft.println(GPS.altitude);
tft.setTextSize(24);
tft.setCursor(30, 71);
tft.setTextColor(ILI9340_WHITE);
String speedx = "";
if(xspeed1 < 10){
tft.println("0" + String(xspeed1));
}
else {
tft.println(xspeed1);
}
xspeed1 = GPS.speed * 1.15;
tft.setCursor(30, 71);
if(xspeed1 <= 28) {
tft.setTextColor(ILI9340_BLACK);
}
if(xspeed1 >= 29 && xspeed1 <= 31) {
tft.setTextColor(ILI9340_RED);
}
if(xspeed1 >= 32 && xspeed1 <= 38) {
tft.setTextColor(ILI9340_BLACK);
}
if(xspeed1 >= 39 && xspeed1 <= 41) {
tft.setTextColor(ILI9340_RED);
}
if(xspeed1 >= 42) {
tft.setTextColor(ILI9340_BLACK);
}
if(xspeed1 < 10) {
tft.println("0" + String(xspeed1));
}
else {
tft.println(xspeed1);
}
text_done = 1;
}
}
}
[/code]