TFT lcd blank screen

I am working on a project where I have time and date on my 2.8" tft display but all I have is a white screen.
Here is the code:

#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h> // Hardware-specific library
MCUFRIEND_kbv tft;
#define BLACK 0x0000
#define RED 0xF800
#define GREEN 0x07E0
#define WHITE 0xFFFF
#define GREY 0x8410

void setup(void) {
Serial.begin(9600);
while (!Serial) ; // wait for serial
delay(200);
Serial.println("DS1307RTC Read Test");
Serial.println("-------------------");
tft.begin();
tft.setRotation(0);
tft.setTextSize(5);
tft.fillScreen(BLACK);
tft.setTextColor(WHITE);
}

void loop(void) {
tmElements_t tm;

if (RTC.read(tm)) {
tft.setCursor(0, 0);
tft.print("Ok, Time = ");
print2digits(tm.Hour);
tft.write(':');
print2digits(tm.Minute);
tft.write(':');
print2digits(tm.Second);
tft.print(", Date (D/M/Y) = ");
tft.print(tm.Day);
tft.write('/');
tft.print(tm.Month);
tft.write('/');
tft.print(tmYearToCalendar(tm.Year));

Serial.print("Ok, Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();

} else {
if (RTC.chipPresent()) {
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
} else {
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}
delay(1000);
}

void print2digits(int number) {
if (number >= 0 && number < 10) {
Serial.write('0');
}
Serial.print(number);
}

Do you still have the short sketch you wrote that just turns the screen red, then green, then blue, then white, and doesn't have all the time keeping stuff?

Please remember to use code tags when posting code

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

I'm not sure what code you are talking about, but the screen does work fine without the rtc code, like with dht22 and bme280 sensors, and even just to print text. Here is a simple test code that works:

#include <Adafruit_GFX.h> // Core graphics library
#include <MCUFRIEND_kbv.h> // Hardware-specific library
MCUFRIEND_kbv tft;
#define BLACK 0x0000
#define RED 0xF800
#define GREEN 0x07E0
#define WHITE 0xFFFF
#define GREY 0x8410

void setup(void)
{
Serial.begin(9600);
tft.begin();
tft.setRotation(0);
tft.fillScreen(BLACK);
tft.setTextColor(WHITE);
tft.setTextSize(2);
}

void loop(void)
{
tft.setCursor(0, 0);
tft.print("Test");
delay(1000);
}

I'm not sure what code tags are?

You didn't tell us that.

Put a simple text print at the end of setup, and a big delay after it.

I did that and it worked in the setup but once it started reading from the rtc it wont print to the display.

The control labelled "</>" in the edit window.

It's all been explained before.
Many times.

So what would be one conclusion be?

Once it starts reading from the rtc the display does not work.

That wouldn't be my conclusion.

Maybe there's something you still haven't told us.

It works with the serial monitor and i2c lcd display just not with tft display.

Please don't make this like pulling teeth.

Does the serial monitor update?

It updates with new info every second.

Then you did not read the advice given in the link that I posted

You have two serious problems

  1. you call tft.begin(); when you should use tft.begin(ID);
  2. the DS1307 is an I2C device. A Uno has SDA on Analog#4 pin which is LCD_RST on an Mcufriend Shield.

Look at the examples for (1). i.e. how to use tft.readID();
(2) You can never use this Shield with I2C on a Uno
(2) the MEGA2560 uses different port pins for I2C

Please report back with ID. There is a hardware mod that is possible on some controllers. This would let you use it on a Uno.

David.

I am using the SDA and SCL pins on the Arduino by aref and gnd pins not used by the lcd shield.

If you have a Uno or Nano, SDA is on PC4. And so is Analog#4 on PC4.

On a MEGA2560, SDA is on PD1. But Analog#4 on PF4. Hence no problem.

What is your ID?

David.

My address is 0x9341

Hi, @blakeblake11
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

This will show you how to post your code in a scrolling screen.

Tom... :grinning: :+1: :coffee: :australia: