How to get GPS data to update to screen?

I am trying to build a GPS to display data on a TFT screen, but cannot get the data to update. The project is using an ESP32-S3 board, and Adafruit Ultimate GPS and Adafruit 1.69in TFT screen.

This is a simplified version. With buttons to change screens it only updates when changing screens. This version doesn't update the screen even though there is data available.

I have searched and tried various things. Please excuse my coding, I'm still new at this and just starting to use char instead of strings...

#include <Arduino.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <Adafruit_GPS.h>    //Install the adafruit GPS library
#include <SPI.h> //Load SPI Library
#include <../fonts/FreeSans9pt7b.h>
#include <../fonts/FreeSans12pt7b.h>

#define TFT_DC  11
#define TFT_CS  9
#define TFT_RST 10

#define GPSSerial Serial1
#define GPSECHO false
Adafruit_GPS GPS(&Serial1); //Create GPS object
Adafruit_ST7789 display = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

uint8_t timeZone = 10;
uint8_t adjHour;
uint8_t adjDay;
uint8_t adjMonth;
uint8_t adjYear;
uint8_t velocity;

char c; //to read characters coming from the GPS
char lat = 'X';    ///< N/S
char lon = 'X';    ///< E/W
bool fix;          ///< Have a fix?
char screenName[15];
char showPending[8] = "pending";
char displayBuf[20];
char floatBuf[20];
String lonStr;
String altStr;
String bearingStr;

unsigned long timer = millis();
static unsigned nextInterval = 1500;

GFXcanvas16 canvas(280, 240);
GFXcanvas16 cTopRow(280,30);            //  start at 0,0
GFXcanvas16 cBottom(280,20);            //  start at 0,220
GFXcanvas16 cMain(280,190);             //  start at 0,20

#define BLACK 0x0000
#define YELLOW 0xFFE0
#define GREEN 0x1f4d
#define DkGreen 0x0a62
#define DKRED 0xC800
#define BLUE 0x32FB

void setup() {
  Serial.begin(115200); //Turn on serial monitor
  GPS.begin(9600); //Turn on GPS at 9600 baud
  GPS.sendCommand("$PGCMD,33,0*6D");  //Turn off antenna update nuisance data
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //Request RMC and GGA Sentences only
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); //Set update rate to 1 hz
  delay(1000); 
  // Ask for firmware version
  GPSSerial.println(PMTK_Q_RELEASE);

  display.init(240,280);            //  this is the native resolution and rotation
  display.fillScreen(BLACK);
  display.setRotation(1);
  display.setTextWrap(false);
}

void loop() {
  readGPS();
  gpsS1();
}

void readGPS() {
    // read data from the GPS 
  char c = GPS.read();
  if (GPSECHO)
    if (c)
      Serial.print(c);
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
      return; // we can fail to parse a sentence in which case we should just wait for another
  }
}

void gpsS1() {
  strcpy(screenName, "GPS Main");
  cMain.fillScreen(BLACK);
  mainGrid("Latitude", "Altitude", "Longitude", "Heading");                  //    draws main grid lines & labels
  cMain.setFont(&FreeSans12pt7b);
  if(GPS.fix==1) {
    float lon = GPS.longitudeDegrees;
    lonStr = String((lon),4) + String(GPS.lon);
    altStr = String((GPS.altitude),1) + " m";
    bearingStr = String(GPS.angle);
    clearMainGrid();                  //    clears areas for updating data
    cMain.setTextColor(GREEN);
  } else {
    lonStr = "pending";
    altStr = "pending";
    bearingStr = "pending";
    cMain.setTextColor(DkGreen);
  }
  if((millis() - timer) >= 500) {
    timer = millis();
    cMain.setCursor(22,58);
    dtostrf(GPS.longitudeDegrees, 6, 4, floatBuf);    //  attempting to get data direct
    cMain.print(floatBuf);                            //  to see if that helps
    cMain.print(GPS.lat);                             //
    cMain.setCursor(162,58);
    cMain.print(lonStr);
    cMain.setCursor(35,152);
    cMain.print(altStr);
    cMain.setCursor(185,152);
    cMain.print(bearingStr);
    cMain.print((char)247);
  }
  display.drawRGBBitmap(0, 30, cMain.getBuffer(), cMain.width(), cMain.height());
  topRow();
}

void mainGrid(String gh1, String gh2, String gh3, String gh4) {                             	//    draws main grid lines
  cMain.fillScreen(BLACK);
  cMain.drawLine(0,93,280,93,GREEN);            //    middle horizontal
  cMain.drawLine(140,0,140,200,GREEN);          //    middle vertical
  cMain.drawRect(0, 0, 280, 2, GREEN);    //    top divider
  cMain.drawRect(0, 188, 280, 2, GREEN);  //    bottom divider
  cMain.setFont(&FreeSans9pt7b);    //  headings     myDate
  cMain.setTextColor(BLUE);
  cMain.setCursor(42,19);
  cMain.print(gh1);
  cMain.setCursor(45,113);
  cMain.print(gh2);
  cMain.setCursor(169,19);
  cMain.print(gh3);
  cMain.setCursor(183,113);
  cMain.print(gh4);
  display.drawRGBBitmap(0, 30, cMain.getBuffer(), cMain.width(), cMain.height());
}

void clearMainGrid() {                  //    clears areas for updating data
  cMain.fillRect(0, 24, 139, 67, BLACK);
  cMain.fillRect(141, 24, 139, 67, BLACK);
  cMain.fillRect(0, 118, 139, 67, BLACK);
  cMain.fillRect(141, 118, 139, 67, BLACK);
}

void topRow() {
    cTopRow.fillScreen(BLACK);
    cTopRow.setFont(&FreeSans12pt7b);
    cTopRow.setTextColor(YELLOW);
    cTopRow.setCursor(15,27);
    cTopRow.print(screenName);
    if(GPS.fix) {
      cTopRow.fillCircle(140,12,7,GREEN);
    } else if(!GPS.fix) {
      cTopRow.fillCircle(140,12,7,DKRED);
    }
    display.drawRGBBitmap(0, 0, cTopRow.getBuffer(), cTopRow.width(), cTopRow.height());
}

If anyone can help it would be appreciated.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.