I have a simple clock program running on a new ILI9341 from the PJRC store (code included below), and it seems to be working fine. However, after several hours of run time, it starts to show some artifacts in the blank areas, and then some hours later it starts displaying 'ghost' images of the intended date and numbers.
When coding the application, I initialized the screen with 'tft.fillScreen(ILI9341_BLACK);' in setup(), but deliberately didn't refresh the background in loop(), to avoid the annoying 'blink' each time the background refreshed. Instead I used ' tft.fillRect(x,y,h,w, ILI9341_BLACK);' to just overwrite the sections of the screen used to display the date and time information. Apparently something along the line is losing synch with where it is supposed to be writing to the screen, or something.
Here's the code:
And here are some photos of the screen acting normally, and then as it progressively gets worse
Normal Display:
Start Seeing Artifacts:
More Artifacts:
Complete Craziness:
I know (or at least I think) I can avoid all this by refreshing the entire display every second, but then I have to put up with that annoying 'blink'. Is there any other option here?
Frank
When coding the application, I initialized the screen with 'tft.fillScreen(ILI9341_BLACK);' in setup(), but deliberately didn't refresh the background in loop(), to avoid the annoying 'blink' each time the background refreshed. Instead I used ' tft.fillRect(x,y,h,w, ILI9341_BLACK);' to just overwrite the sections of the screen used to display the date and time information. Apparently something along the line is losing synch with where it is supposed to be writing to the screen, or something.
Here's the code:
Code:
/*
Name: Teensy_LCDClockV2.ino
Created: 2/11/2021 3:57:01 PM
Author: FRANKNEWXPS15\Frank
*/
/***************************************************
This is our GFX example for the Adafruit ILI9341 Breakout and Shield
----> http://www.adafruit.com/products/1651
Check out the links above for our tutorials and wiring diagrams
These displays use SPI to communicate, 4 or 5 pins are required to
interface (RST is optional)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#include <Wire.h>
#include "RTClib.h"
#include "SPI.h"
#include "ILI9341_t3.h"
#include "font_Arial.h"
#pragma region RTC Support
//#define FORCE_RTC_TO_LAST_COMPILE_TIME //uncomment to manually set RTC to last compile time
RTC_DS3231 rtc;
//char daysOfTheWeek[7][12] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
char daysOfTheWeek[7][12] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
DateTime now, lastTime;
char buffer[100];
struct tStamp
{
unsigned long mSec;
byte RTC_Status;
};
#define DS3231_ADDRESS 0x68 ///< I2C address for DS3231
#define DS3231_STATUSREG 0x0F ///< Status register
#define RTCStatArraySize 10
#define RTCStatTime_IntervalMsec 100
tStamp RTCStatArray[RTCStatArraySize];
#pragma endregion RTC Support
#pragma region TFT Display Support
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
#define N0_DIAGNOSTICS
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
#pragma endregion TFT Display Support
void setup()
{
Serial.begin(9600);
unsigned long mSec = millis();
while (!Serial && millis()-mSec < 3000) // wait for Arduino Serial Monitor
{
delay(100);
}
Serial.println("Teensy 3.2 TFT Clock Program");
#pragma region TFT INITIALIZATION
Serial.println("Initializing TFT display");
tft.begin();
// Note: you can now set the SPI speed to any value
// the default value is 30Mhz, but most ILI9341 displays
// can handle at least 60Mhz and as much as 100Mhz
// tft.setClock(60000000);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(2);
tft.setRotation(1);
#pragma endregion region TFT INITIALIZATION
#pragma region TFT DIAGNOSTICS
#ifndef N0_DIAGNOSTICS
// read diagnostics (optional but can help debug problems)
uint8_t x = tft.readcommand8(ILI9341_RDMODE);
Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDMADCTL);
Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDPIXFMT);
Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDIMGFMT);
Serial.print("Image Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDSELFDIAG);
Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
Serial.println(F("Benchmark Time (microseconds)"));
Serial.print(F("Screen fill "));
Serial.println(testFillScreen());
delay(200);
Serial.print(F("Text "));
Serial.println(testText());
delay(600);
Serial.print(F("Proportional Text "));
Serial.println(testProportionalText());
delay(600);
Serial.print(F("Lines "));
Serial.println(testLines(ILI9341_CYAN));
delay(200);
Serial.print(F("Horiz/Vert Lines "));
Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
delay(200);
Serial.print(F("Rectangles (outline) "));
Serial.println(testRects(ILI9341_GREEN));
delay(200);
Serial.print(F("Rectangles (filled) "));
Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
delay(200);
Serial.print(F("Circles (filled) "));
Serial.println(testFilledCircles(10, ILI9341_MAGENTA));
Serial.print(F("Circles (outline) "));
Serial.println(testCircles(10, ILI9341_WHITE));
delay(200);
Serial.print(F("Triangles (outline) "));
Serial.println(testTriangles());
delay(200);
Serial.print(F("Triangles (filled) "));
Serial.println(testFilledTriangles());
delay(200);
Serial.print(F("Rounded rects (outline) "));
Serial.println(testRoundRects());
delay(200);
Serial.print(F("Rounded rects (filled) "));
Serial.println(testFilledRoundRects());
delay(200);
Serial.println(F("Done!"));
#endif // !N0_DIAGNOSTICS
#pragma endregion region TFT DIAGNOSTICS
#pragma region RTC_SETUP
Serial.println("Initializing RTC...");
tft.println("Initializing RTC...");
delay(1000);
if (!rtc.begin())
{
Serial.println("Couldn't find RTC");
tft.println("Couldn't find RTC");
while (1);
}
bool lp = rtc.lostPower();
Serial.print("lostPower() reports "); Serial.println(lp);
tft.printf("lostPower() = %d\n", lp);
delay(1000);
if (rtc.lostPower())
{
Serial.println("RTC lost power. Setting RTC to last compile time");
tft.println("RTC lost power. Setting RTC to last compile time");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
#ifdef FORCE_RTC_TO_LAST_COMPILE_TIME
Serial.println("Forcing RTC to last compile time");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
#endif //
//DateTime now = rtc.now();
now = rtc.now();
//char buffer[100];
memset(buffer, '\0', 100);
GetDayDateTimeStringFromDateTime(now, buffer);
Serial.println("Retrieving Date/Time from RTC....");
Serial.print("Date String = "); Serial.println(buffer);
#pragma endregion RTC_SETUP
//DEBUG!!
//tft.println("Setting time to just before midnight");
//rtc.adjust(DateTime(2021, 02, 13, 07, 59, 45));
//DEBUG!!
}
void loop(void)
{
now = rtc.now();
//Display day and date
//tft.fillRect(0, 0, 290, 40, ILI9341_RED);
tft.fillRect(0, 0, 290, 40, ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(0, 0);
tft.setFont(Arial_32);
tft.printf("%s %02d/%02d/%02d\n",
daysOfTheWeek[now.dayOfTheWeek()], now.month(), now.day(), now.year());
//Serial.printf("%d:%d:%02d\t%d:%d:%02d\n", now.hour(), now.minute(), now.second(),
//lastTime.hour(), lastTime.minute(), lastTime.second());
//Display time
tft.setCursor(0, 100);
tft.setTextColor(ILI9341_RED);
tft.setFont(Arial_60);
tft.fillRect(0, 100, 350, 65, ILI9341_BLACK);
tft.setCursor(0, 100);
int hournum = now.hour();
hournum = (hournum > 12) ? hournum - 12 : hournum;
tft.printf("%2d:%02d:%02d", hournum, now.minute(), now.second());
lastTime = now;
delay(1000);
}
#pragma region DATE_TIME_FUNCTIONS
void GetDayDateTimeStringFromDateTime(DateTime dt, char* bufptr)
{
int mydayofweek = dt.dayOfTheWeek();
//mydayofweek = (mydayofweek < 0) ? 0 : mydayofweek; //guard for return of 0 from weekday()
int myday = dt.day();
int mymonth = dt.month();
int myyear = dt.year();
int myhour = dt.hour();
int mymin = dt.minute();
int mysec = dt.second();
char* dayofweek = (char*)daysOfTheWeek[mydayofweek];
sprintf(bufptr, "%s %4d/%02d/%02d at %02d:%02d:%02d", dayofweek, mymonth, myday, myyear, myhour, mymin, mysec);
}
void HourStringFromDateTime(DateTime dt, char* bufptr)
{
int hourval = dt.hour();
if (hourval > 12)
{
hourval -= 12;
}
//sprintf(bufptr, "%02d", hourval);
sprintf(bufptr, "%d", hourval);
}
void MinuteStringFromDateTime(DateTime dt, char* bufptr)
{
sprintf(bufptr, "%02d", dt.minute());
}
#pragma endregion DATE_TIME_FUNCTIONS
And here are some photos of the screen acting normally, and then as it progressively gets worse
Normal Display:
Start Seeing Artifacts:
More Artifacts:
Complete Craziness:
I know (or at least I think) I can avoid all this by refreshing the entire display every second, but then I have to put up with that annoying 'blink'. Is there any other option here?
Frank