Hello! First time posting here, so I hope I go about this correctly.
I'm trying to use a GC9A01A tft display for a basic GPS project, I'm wanting it to display speed, lat, long, etc. on the screen. I am able to get it to display a basic GUI on the screen during the setup, however whenever I try to put parsed information on the screen in the main loop section, it doesn't print on the screen at all.
What confuses me to no end is that I'm able to display the parsed information on the serial monitor, but once I try to display it on the TFT display, it doesn't work. I'm honestly a complete novice, so feel free to treat me like a total idiot, lol. Hope someone can help with my predicament. Here's hoping I'm just missing something simple.
Controller: Elegoo uno r3
GPS module: Adafruit ultimate GPS breakout v3
display: GC9A01A TFT
Librarys in use:
- Adafruit_GFX.h
- Adafruit_GC9A01A.h
- SPI.h
- Adafruit_GPS.h
- SoftwareSerial.h
#include <Adafruit_GFX.h>
#include <Adafruit_GC9A01A.h>
#include <SPI.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
// Example Pin Connections (Adjust for your board)
#define TFT_CS 2
#define TFT_DC 1
#define TFT_RST 5
#define TFT_BL 3
Adafruit_GC9A01A tft(TFT_CS, TFT_DC, TFT_RST);
SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO true
int obtainedFix = 0;
void setup() {
// put your setup code here, to run once:
tft.begin();
tft.setRotation(1); // Adjust orientation
tft.fillScreen(GC9A01A_BLACK);
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH);
//Start up screen, Hello world!
tft.setCursor(50, 110);
tft.setTextColor(GC9A01A_WHITE);
tft.setTextSize(2);
tft.println("Hello World!");
tft.setCursor(40, 140);
tft.setTextSize(1);
tft.println("Initializing.");
delay(500);
tft.setCursor(40, 140);
tft.println("Initializing..");
delay(500);
tft.setCursor(40, 140);
tft.println("Initializing...");
delay(500); //Yes I know this is silly, but Let me have this.
tft.fillScreen(GC9A01A_BLACK);
//UI stuff
tft.setTextColor(GC9A01A_RED);
tft.setTextSize(2);
tft.setCursor(50, 25);
tft.println("FIX");
tft.setTextColor(GC9A01A_WHITE);
tft.setCursor(25, 50);
tft.println("KTS:");
tft.setCursor(25, 80);
tft.println("Lat:");
tft.setCursor(13, 110);
tft.println("Long:");
tft.setCursor(13, 140);
tft.println("Sats:");
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GPS & SERIAL START-UP
Serial.begin(115200);
delay(2000);
Serial.println("Hello, how are you? I'm stressed, and hope this will eventually work! Turning on GPS...");
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //INFO TYPE: RMC GGA
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); //Update rate
GPS.sendCommand(PGCMD_ANTENNA); //ANTENNA UPDATES.
delay(1000);
// Ask for firmware version
mySerial.println(PMTK_Q_RELEASE);
}
uint32_t timer = millis();
void loop() {
// put your main code here, to run repeatedly:
char c = GPS.read();
if ((c) && (GPSECHO))
Serial.write(c);
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA()))
return;
}
//Print parsed data onto screen
if (millis() - timer > 1000) {
timer = millis(); // reset the timer
Serial.print("Fix: "); Serial.println((int)GPS.fix);
if (GPS.fix == true){
if (obtainedFix == 0){
Serial.println("SEE? IT WORKS WITH SERIAL. WHY ISN'T IT UPDATING THE SCREEN");
tft.setTextColor(GC9A01A_GREEN);
tft.setCursor(50, 25);
tft.print("FIX");
obtainedFix ++;
}
}
}
}