Good evening folks,
So I'm trying to marry two programs that work just fine on their own, trimmed down to just what I need. Problem is that I can't get BOTH my GPS AND my display to work at the same time and I've narrowed it down to one particular line.
Using a Huzzah32 from Adafruit utilizing the ESP32 chip. Using the SSD1351 display, from here. Most current version of Arduino IDE. OS is Linux Mint 18.2. Programs have been slimmed down from the Adafruit GPS Library, GPS_HardwareSerial_Parsing sample, and the ESP32_graphictest from here.
#include <Adafruit_GPS.h>
#include <SPI.h>
#include <SSD_13XX.h>
// For the ESP32
#define _cs 23 // goes to TFT CS
#define _dc 22 // goes to TFT DC
#define _mosi 18 // goes to TFT MOSI
#define _sclk 5 // goes to TFT SCK/CLK
#define _rst 12 // ESP RST to TFT RESET
#define _miso // Not connected
// 3.3V // Goes to TFT LED
// 5v // Goes to TFT Vcc
// Gnd // Goes to TFT Gnd
uint8_t errorCode = 0;
SSD_13XX tft = SSD_13XX(_cs, _dc);
//not sure this is needed in IDF
#if defined(ESP32)
HardwareSerial Serial1(2);
#endif
#define GPSSerial Serial1
// Connect to the GPS on the hardware port
Adafruit_GPS GPS(&GPSSerial);
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO false
uint32_t timer = millis();
void setup()
{
Serial.begin(115200);
// 9600 NMEA is default baud rate, alternate 4800
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// Set the update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
// Request updates on antenna status, comment out to keep quiet
GPS.sendCommand(PGCMD_ANTENNA);
GPSSerial.println(PGCMD_ANTENNA);
// Ask for firmware version
GPSSerial.println(PMTK_Q_RELEASE);
tft.begin(true);
}
void loop()
{
// read data from the GPS in the 'main loop'
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) Serial.print(c);
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
//Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
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
}
// if millis() or timer wraps around, we'll just reset it
if (timer > millis()) timer = millis();
if (millis() - timer > 100) {
timer = millis(); // reset the timer
Serial.print("\nTime: ");
if (GPS.hour <= 0){
Serial.print(GPS.hour +7, DEC);
} else {
Serial.print(GPS.hour -5, DEC);
}
if (GPS.minute <=0){
Serial.print(':0');
} else {
Serial.print(':');
}
Serial.print(GPS.minute, DEC); Serial.print(':');Serial.println(GPS.seconds, DEC);
Serial.print("Date: ");
Serial.print(GPS.month, DEC); Serial.print('/');
Serial.print(GPS.day, DEC); Serial.print("/20"); Serial.println(GPS.year, DEC);
if (GPS.fix) {
Serial.print("Speed (MPH): "); Serial.println(GPS.speed * 1.15078);
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
}
}
tft.setCursor(0, 0);
tft.setTextColor(WHITE); tft.setTextScale(1);
if (GPS.hour<=0){
tft.print(GPS.hour +7);
} else {
tft.print(GPS.hour -5);
}
if (GPS.minute <=10){
tft.print(':0');tft.println(GPS.minute);
} else {
tft.print(':');tft.println(GPS.minute);
}
tft.setTextScale(5);
tft.println(GPS.speed);
tft.setTextScale(1);
tft.print("Satelites ");tft.print(GPS.satellites);
tft.setCursor(0, 0);
tft.setTextColor(BLACK); tft.setTextScale(1);
if (GPS.hour<=0){
tft.print(GPS.hour +7);
} else {
tft.print(GPS.hour -5);
}
if (GPS.minute <=10){
tft.print(':0');tft.println(GPS.minute);
} else {
tft.print(':');tft.println(GPS.minute);
}
tft.setTextScale(5);
tft.println(GPS.speed);
tft.setTextScale(1);
tft.print("Satelites ");tft.print(GPS.satellites);
}
The line causing the bug up is..
tft.begin();
If I put it to false, the display works as supposed to, receiving time and date from GPS only. Put it to true and the GPS reads like it should, but no display. Leave it empty, and it seems to be just like false.
Can someone explain this conundrum to me?