Problem to display time on LCD TFT 2.8''

Hi,
I want to build a real time clock timer however I have some problems to show the time on TFT LCD display- white screen appears. The LCD screen is working fine i.e I can display graphics and text but when it comes to display a time it does not work as it should. I have noticed that when the program executes command t = rtc.getTime() the screen is being wiped out - not sure why ?

The hardware I have used:

  • 2.8’’ TFT LCD display(ILI9341)
  • ds3231 RTC

I would like to ask for help more experienced colleagues how to fix this problem.
The code is shown below(it is very simple but I just started learning about TFT LCD screens 8))

Thanks in advance

#include <Adafruit_TFTLCD.h> 
#include <Adafruit_GFX.h>    
#include <TouchScreen.h>
#include <DS3231.h>
#include <Time.h>

DS3231  rtc(SDA, SCL);
Time t;

#define LCD_CS A3 
#define LCD_CD A2 
#define LCD_WR A1 
#define LCD_RD A0 
#define LCD_RESET A4 

#define TS_MINX 141
#define TS_MINY 140
#define TS_MAXX 940
#define TS_MAXY 888

#define YP A3
#define XM A2
#define YM 9
#define XP 8

#define BLACK   0x0000
#define WHITE   0xFFFF

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

boolean buttonEnabled = true;

void setup() {
  rtc.begin();
  tft.reset();
  uint16_t identifier = tft.readID();
  tft.begin(identifier);
  tft.setRotation(3);
  tft.fillScreen(BLACK);
  tft.drawRoundRect(0,0,320,240,5, WHITE);
  }

void loop() {
 t = rtc.getTime();
 tft.setTextSize(2);
 tft.setCursor(0,10);
 tft.print("Date: ");
 tft.print(rtc.getTimeStr());
 delay(1000);
}

I found the DS3231.h library from the Library Manager. It does not match your class methods.

What "DS3231.h" do you have?
Where did it come from?
It is always wise to use libraries supported by the Library Manager.

I am guessing that you have a Mcufriend style of TFT shield.

#define LCD_CS A3

#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

This means that you are sharing the LCD_RESET pin with the DS3231's SDA pin. (A4 on a Uno)
You will reset the TFT whenever you access the I2C bus.

A Mega2560 or Due has separate (and accessible) I2C pins.

David.

Thanks for your feedback.
I don't quite remember now from where I downloaded ds3231 library but it works fine(I used the same library to build clock using LCD display).

This means that you are sharing the LCD_RESET pin with the DS3231's SDA pin. (A4 on a Uno)
You will reset the TFT whenever you access the I2C bus.

Based on your answer I'm assuming that it will not be possible to use this type of TFT display with DS3231 RTC ? Or maybe is there any other way to make it works ?

Yes, you can use them together, just move pin LCD_RST from TFT to not be connected to Arduino A4 to Arduino PD0 pin with a wire and update this in your.ino file for declaration of reset #define LCD_RESET PD0!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.