I have been having trouble with the code below not display and possibly not working and or looping. Before making changes to my code I had a problem where the Serial monitor would print up to "longitude" and occasionally print the first number of this value, however, it would pause stop and the whole code would pause/not continue. I had printed data to the Serial Monitor constantly but was told that the problem could be that the serial monitor is full. With this, I have deleted most of the code for the serial monitor as it is not needed for my project. Now I cant tell at what stage my code is not working. The code for the screen is formatted this way as I have found it is the best way to reduce flickering, however I know there is a fast display library but was unable to implement it. Could it be battery issue? I am using a 9V battery to power all of the components. Any help would be much appreciated and the code is provided below.
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <DFRobot_SIM808.h>
#include <SPI.h>
#include <Wire.h>
#define TFT_CS 10
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 8
#define date_x 20
#define date_y 17
#define time_x 20
#define time_y 35
#define v_x 17
#define v_y 70
float la;
float lo;
char DateGPS[10];
char TimeGPS[5];
String prevDate = "99/99/9999";
String Date = "00/00/0000";
String prevTime = "99:99";
String Time = "00:00";
String prevV = "999:99";
String V = "000:00";
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
DFRobot_SIM808 sim808(&Serial);
void setup()
{
Serial.begin(9600);
tft.init(240, 280);
tft.fillScreen(ST77XX_BLACK);
//******** Initialize sim808 module *************
while(!sim808.init())
{
delay(1000);
Serial.print("Sim808 init error\r\n");
}
//************* Turn on the GPS power************
if( sim808.attachGPS())
;
else
;
}
void loop()
{
//************** Get GPS data *******************
if (sim808.getGPS())
{
sprintf(DateGPS, "%02d-%02d-%04d", sim808.GPSdata.day, sim808.GPSdata.month, sim808.GPSdata.year);
Date = String(DateGPS);
if(prevDate != Date)
{
deletePrevDate();
printDate();
}
prevDate = Date;
sprintf(TimeGPS, "%02d:%02d", sim808.GPSdata.hour, sim808.GPSdata.minute);
Time = String(TimeGPS);
if(prevTime != Time)
{
deletePrevTime();
printTime();
}
prevTime = Time;
Serial.println(sim808.GPSdata.lat, 6);
Serial.println(sim808.GPSdata.lon, 6);
V = String(sim808.GPSdata.speed_kph);
if(prevV != V)
{
deletePrevV();
printV();
}
prevV = V;
//************* Turn off the GPS power ************
sim808.detachGPS();
}
}
void deletePrevDate()
{
tft.setCursor(date_x, date_y);
tft.setTextSize(2);
tft.setTextColor(ST77XX_BLACK);
tft.println(prevDate);
return;
}
void printDate()
{
tft.setCursor(date_x, date_y);
tft.setTextSize(2);
tft.setTextColor(ST77XX_WHITE);
tft.println(Date);
return;
}
void deletePrevTime()
{
tft.setCursor(time_x, time_y);
tft.setTextSize(2);
tft.setTextColor(ST77XX_BLACK);
tft.println(prevTime);
return;
}
void printTime()
{
tft.setCursor(time_x, time_y);
tft.setTextSize(2);
tft.setTextColor(ST77XX_WHITE);
tft.println(Time);
return;
}
void deletePrevV()
{
tft.setCursor(v_x, v_y);
tft.setTextSize(6);
tft.setTextColor(ST77XX_BLACK);
tft.println(prevV);
return;
}
void printV()
{
tft.setCursor(v_x, v_y);
tft.setTextSize(6);
tft.setTextColor(ST77XX_WHITE);
tft.println(V);
return;
}
serial monitor is full
is nonsense ... you can test that with a sketch that sends a lot of data