Sorry I forgot to include the sketch, it's early here.
// Bike Speedometer using GPS NEO-6M-0-001
// with ESP32 DEV bd
// with Adafruit display
#include <TinyGPS++.h>
#include <SPI.h>
#include <Adafruit_GFX.h> // Core graphics library
#include "Adafruit_HX8357.h"
//#include <TFT_eSPI.h> // Hardware-specific library
#include <SD.h>
// These are 'flexible' lines that can be changed
#define TFT_CS 15
#define TFT_DC 27
#define TFT_RST 4 // RST can be set to -1 if you tie it to Arduino's reset
//TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
// SoftSPI - note that on some processors this might be *faster* than hardware SPI!
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST, MISO);
// Connect the GPS Power pin to 5V
// Connect the GPS Ground pin to ground
// Connect the GPS TX (transmit) pin to Digital 16
// Connect the GPS RX (receive) pin to Digital 17
#define RXD2 16
#define TXD2 17
HardwareSerial neogps(1);
TinyGPSPlus GPS;
// GPS Variables
String NMEA1; //Variable for first NMEA sentence
String NMEA2; //Variable for second NMEA sentence
char c; //to read characters coming from the GPS
float deg; //Will hold positin data in simple degree format
float degWhole; //Variable for the whole part of position
float degDec; //Variable for the decimal part of degree
float GPS_Lon = 00;
float GPS_Lat = 00;
float Latitude = 0.0;
float Longitude = 0.0;
float distance = 0.0;
bool newData = false;
int cntr = 0;
unsigned long int scan_time = millis();
int GPS_Scanned = 0;
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// SD Card Select pin
const int chipSelect = 5;
void setup() {
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
// also spit it out
Serial.begin(115200);
delay(5000);
// Set all chip selects high to avoid bus contention during initialisation of each peripheral
// digitalWrite(21, HIGH); // Touch controller chip select (if used)
// digitalWrite(15, HIGH); // TFT screen chip select
// digitalWrite(5, HIGH); // SD card chips select, must use GPIO 5 (ESP32 SS)
// GPS
// Begin serail communications with Neo6mGPS
Serial.println("Start GPS");
neogps.begin(9600, SERIAL_8N1, RXD2, TXD2);
tft.begin();
tft.fillScreen(BLACK); //clears screen, sets to Black
tft.setRotation(0); // rotates screen 90' for landscape mode
// Sets the background color of the screen to black
tft.fillScreen(BLACK);
// Back to Home button
/*
tft.fillRoundRect(30, 20, 50, 30, 10, BLUE);
tft.drawRoundRect(30, 20, 50, 30, 10, WHITE);
tft.setCursor(40, 27);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("<-");
tft.setCursor(100, 30);
tft.setTextColor(WHITE);
tft.setTextSize(1);
tft.print("Back to Main Menu");
*/
// Prints the title on the screen
tft.setCursor(65, 20);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("GPS Status");
// Draws the red line under the title
tft.drawFastHLine(10, 60, 320, RED);
// draw start/stop logging button
// (X, Y, W, H, R)
// tft.fillRoundRect(30, 420, 50, 30, 10, WHITE);
scan_time = millis(); // reset scan time
/*
// Initialize SD card
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
//don't do anything more:
//while (1);
}
else {
Serial.println("card initialized.");
}
*/
} // end setup()
void loop() {
// read GPS
while (neogps.available())
{
if (GPS.encode(neogps.read()))
{
newData = true;
} // end if (gps.encode(neogps.read
} // end while
if (((millis() - scan_time) > 1000)) {
//if (GPS.location.isValid())
if(newData == true)
{
newData = false;
Serial.println(F("VALID"));
Serial.print("Lat = ");
Serial.print(GPS.location.lat(), 4);
Serial.print(F("\t"));
Serial.print("Lon = ");
Serial.print(GPS.location.lng(), 4);
Serial.print(F("\t"));
Serial.print("Speed = ");
Serial.println(GPS.speed.mph()); // Speed in miles per hour (double)
// Show green circle when GPS connected
tft.fillCircle(290, 30, 10, GREEN);
// test if this part of sketch is working
cntr = cntr + 1;
Serial.println(cntr);
// calculate distance
if(GPS.speed.mph() > 0.5){
distance = distance+(GPS.speed.mph()/3600);
} // end if(GPS.speed.mph() > 0.5)
}
else
{
Serial.println(F("INVALID"));
tft.fillCircle(290, 30, 10, RED);
}
// Update screen variables
// Display Longitude
tft.setCursor(50, 70);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Longitude");
tft.setCursor(50, 100);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(4);
tft.print(GPS.location.lng(), 4);
// Display Latitude
tft.setCursor(50, 150);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Latitude");
tft.setCursor(50, 180);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(4);
tft.print(GPS.location.lat(), 4);
// Display Speed
tft.setCursor(50, 230);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Speed");
tft.setCursor(50, 260);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(4);
tft.print(GPS.speed.mph(), 1);
// Display Distance
tft.setCursor(50, 310);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Distance");
tft.setCursor(50, 340);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(4);
tft.print(distance);
if (millis() > 5000 && GPS.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
scan_time = millis(); // reset scan time
} // end (((millis() - scan_time) > 1000)
if ((millis() - scan_time ) > 3000) {
scan_time = millis();
Serial.println("reset");
GPS_Scanned = 0;
} // end (millis() - scan_time > 3000)
} // end loop