Hi lovely people.
New to Arduino and this is my first project.
I am trying to create a very simple log display using an Arduino Mega2560 and a DFRobot DFR0669 (3.5”480x320 TFT LCD Capacitive Touchscreen Breakout Wiki - DFRobot).
It's using SPI to communicate, and I am using the DFR provided libraries to interface with the display.
I have a simple sketch to output an event log to a new line every 200ms, and keep an uptime timer updated every 1000ms. I am not using delay().
Problem is it seems to be closer to 800-1000ms between the lines updating on the display, it seems the Arduino is waiting for the display to draw the line of text, which it does character by character, before it moves on.
So to fill the 480x320 display with text should take about 3 seconds, at which point it should refresh and keep rolling. However it takes more like 30 seconds. Also the wipe of the screen takes a second to process.
I was expecting the screen refresh would be instant, and I though the text would just display immediately. As it stands, the project is not fit for purpose.
Am I just pushing the limits of what's possible with the tool here, or am I missing a trick?!
#include "DFRobot_GDL.h"
#include "uptime.h"
#define TFT_DC 8
#define TFT_CS 53
#define TFT_RST 9
/**
* @brief Constructor Constructor of hardware SPI communication
* @param dc Command/data line pin for SPI communication
* @param cs Chip select pin for SPI communication
* @param rst reset pin of the screen
*/
DFRobot_ILI9488_320x480_HW_SPI screen(/*dc=*/TFT_DC,/*cs=*/TFT_CS,/*rst=*/TFT_RST);
//DFRobot_ILI9488_320x480_DMA_SPI screen(/*dc=*/TFT_DC,/*cs=*/TFT_CS,/*rst=*/TFT_RST);
/*
*User-selectable macro definition color
*COLOR_RGB565_BLACK COLOR_RGB565_NAVY COLOR_RGB565_DGREEN COLOR_RGB565_DCYAN
*COLOR_RGB565_MAROON COLOR_RGB565_PURPLE COLOR_RGB565_OLIVE COLOR_RGB565_LGRAY
*COLOR_RGB565_DGRAY COLOR_RGB565_BLUE COLOR_RGB565_GREEN COLOR_RGB565_CYAN
*COLOR_RGB565_RED COLOR_RGB565_MAGENTA COLOR_RGB565_YELLOW COLOR_RGB565_ORANGE
*COLOR_RGB565_WHITE
*/
unsigned long timer1 =0;
unsigned long timer2 =0;
int refresh1 = 1000;
int refresh2 = 100;
int16_t cursor_x = 0;
int16_t cursor_y = 0;
void setup() {
Serial.begin(115200);
screen.begin();
// Set text wrapping mode
// true = Text word wrap, false = No word wrap
screen.setTextWrap(false);
screen.setTextColor(COLOR_RGB565_BLACK, COLOR_RGB565_WHITE);
//Set text size to 0
screen.setTextSize(0);
//Fill color, RGB color with 565 structure
screen.fillScreen(COLOR_RGB565_WHITE);
}
void loop(){
if (millis()>timer1+refresh1){//do this every 1000 ms
timer1+=refresh1;
printStatus();
}
if (millis()>timer2+refresh2){//do this every 300 ms
timer2+=refresh2;
printLog("Here is a message to be displayed");
}
}
void printStatus(){
//Set the coordinate position x = 0, y = 50
screen.setCursor(0, 470);
//First call calculate_uptime() to calculate the uptime
//and then read the uptime variables.
uptime::calculateUptime();
//Output text
screen.print("Ross2D2 uptime ");
screen.print(uptime::getHours());
screen.print(":");
screen.print(uptime::getMinutes());
screen.print(":");
screen.print(uptime::getSeconds());
}
void printLog(char *eventLog) {
if(cursor_y>=460){
cursor_y = 0; //go back to the top
screen.fillScreen(COLOR_RGB565_WHITE); //wipe the screen
}
screen.setCursor(cursor_x, cursor_y);
screen.print(millis());
screen.print(": ");
screen.println(eventLog);
cursor_x = screen.getCursorX();
cursor_y = screen.getCursorY();
}