Arduino Mega 2560 and 3.5inch TFT Display

Greetings Everyone,

Wonder if you could help I've got an Arduino Mega and I've managed to learn basics of writing simple sketches to clear screen, change the colours etc and display text.
The project I'm working on is to display DS3231 RTC time which I've got working but the clock display becomes unreadable because digits overlap each other. Just wondered if you could provide any help.
I've included a picture of the screen and the sketch.

LCD-3.5inch_RTC_Shield_Display.ino (1.4 KB)

Apologies Everyone - Here's the code in tags please let me know if it's in readable format
:slightly_smiling_face:

/*
* 3.5" Shield for Arduino Uno and Mega2560
* Using LCDWIKI Libraries
* Basic sketch to learn and test how the display works
* Display Text

Modified By Carl Reid
Date Friday 7th July 2023
*/

#include <LCDWIKI_GUI.h>      //Core Graphics Library
#include <LCDWIKI_KBV.h>      //Hardware Specefic Library
#include <DS3231.h>           //Library to Control RTC Module

LCDWIKI_KBV mylcd(ILI9486, A3,A2,A1,A0,A4); //model,cs,cd,wr,rd,reset
DS3231 rtc(SDA,SCL);          //Sets pins SDA for Data & SCL for Clock on RTC Module

//********* Define Colours Below ***************
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

void setup()
{

mylcd.Init_LCD();                   //Initialize Display Object
rtc.begin();                        //Initialize the rtc Object

mylcd.Set_Rotation(1);              //Set Screen Orientation
mylcd.Fill_Screen(YELLOW);           //Background Colour
mylcd.Set_Text_Size(2);             //Text Size
mylcd.Set_Text_colour(BLACK);       //Text Colour
mylcd.Set_Text_Mode(1);             //Text howit's Displayed

}

void loop()
{

mylcd.Print("Arduino Mega 2560 TFT Shield Clock", 100, 50);  //Numbers = across, down
mylcd.Print("Current Time: ", 100, 100);         // Print text on screen
mylcd.Print(rtc.getTimeStr(), 275 ,100);         //Gets Time Data from RTC Module and Displays Info
delay(1000);

}

Thanks,
Carl

Publish your program in code tags. Hardly anyone will download your file. I guess now you just print the time on the display and normally each subsequent record is superimposed on the previous one and becomes a mess. In such cases, I print the old value with the background color to delete it and only then print the new value with the required color.

Hi Flashko

Thank you for replying back I think I've added the sketch in code tags so hopefully it's readable, if anyone could add amendments for me to try then that would be helpful. So far any static text I want to display works, also I can change the background colour and also text.
As you've worded correctly the new value gets superimposed on the previous one :slightly_smiling_face:

Yes, thanks. Did you try what I told you? When you print the value you store it in a variable. When the new value is different from this variable, you print the variable with the old value with the background color to erase the current caption, then print the new value with the selected text color, and store the printed value back into the variable. Thus you minimize the commands to the display and reduce the load on the microcontroller.

In this video you can see the effect of this refresh method.

Hi Flashko
Sorry for the delay I was away for the weekend, would you be able to provide a section of the code for what you have just described for me to have have a look at please.
I'm almost there the mistake I'm making is refreshing the screen with yellow does work but the whole text blinks, the clock digits do not superimpose each other.

Hi Flashko,
Thank you for your help so far yesterday while I was watching a film I kept going over your example until I hopefully understood if one hopes :slightly_smiling_face:
I've modified mine a bit I think it's ok but I'm still tweaking it a bit.
Challenging bit would be with the DS3231 RTC module I think with that I'll have to try and find a way of creating two variables say CLOCK1 and CLOCK2 and do the same as with this sketch.
If you see anything obvious I can amend please let me know, I'm more into displaying info on LCD's and TFT's I've got I2C's working ok 16x2 and 20x4 no problem :grinning:

/*
* Sketch to Display Characters on 3.5" TFT Screen
* Print characters in various sizes and colours
* Count from 1-60 and repeats cycle
*/

#include <MCUFRIEND_kbv.h>
#include <Adafruit_GFX.h>

// Define Colours Below
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

MCUFRIEND_kbv tft;

int show_number=1;
int hide_number=0;
int PauseSec=1000;


void setup()
{

uint16_t ID = tft.readID();
tft.begin(ID);
tft.setRotation(1);
tft.fillScreen (BLACK);

tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.setCursor(140,10);
tft.print("Hello Carly");

tft.setTextColor(CYAN);
tft.setTextSize(2);
tft.setCursor(10,100);
tft.print("3.5 inch TFT, Arduino UNO/Mega Shield");

tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.setCursor(100,200);
tft.print("Count 1-60: ");
}

void loop()
{
  
if (hide_number == 60) (show_number = 1);

tft.setCursor(320,200);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println(show_number);

delay(PauseSec);

tft.setCursor(320,200);
tft.setTextColor(BLACK);
tft.setTextSize(3);
tft.println(hide_number);

show_number = show_number + 1;
hide_number = show_number;

}

In my opinion, your program will not work properly. Have you tried it to see the result?

Yes the first numbers say 1-4 superimpose on each other after that it's fine right up to 60 it then cycles back to 1 and does the same thing again.
Almost there... :slight_smile:

Here's a snapshot of the screen :slight_smile:

That is because the initial values of show_number and hide_number are not the same. Initially the code displays a 1, but overwrites it with a 0. From then on, the code should operate correctly, but it takes a few iterations before all the initial pixels from the 1 are overwritten with the background color.

Hi David_2018

Thank you very much for answering my query I'll check that later today as it's 00:32hrs in UK, so far the only things I've looked up are the libraries that the sketches use everything else I'm learning as I go along.
I'll do a quick check and see if I set the values to 1 what you happen. :slight_smile:

I usually organize the code a bit differently, overwriting the previous number immediately before writing the new value. Taking too long between the overwrite and the new value can lead to a noticeable flicker, and keeping everything together in a sequence helps when you have multiple different things to update on a display.

void loop()
{
  tft.setTextSize(3);
  tft.setCursor(320, 200);
  tft.setTextColor(BLACK);
  tft.println(hide_number);
  tft.setCursor(320, 200);
  tft.setTextColor(WHITE);
  tft.println(show_number);
  hide_number = show_number; //save the value that was written to the display

  delay(PauseSec);
  show_number = show_number + 1;
  if (show_number > 60) (show_number = 1);
}

Hi David_2018

Brilliant..!
What I did was to set the values on the two variables to the same.
int show_number=1;
int hide_number=1;

Then going on what your first reply said I moved this statement to this position

if (hide_number == 60) (show_number = 1);
hide_number = show_number;

Now all the numbers show up correctly on the screen counting from 1 to 60 :grinning:
Thank you very much I've just seen your second reply I'll have a look at that as well.

Ah I see what you've done now, I'll try that :slight_smile:

Yes your right..!
There's less flicker on the display thank you David_2018 I'll be looking at the code a bit more to make sure I fully understand.
Funny enough the 3.5" TFT Shield was the most challenging to get working so far, the LCD's 16x2 and the 20x4 were no problem they're both I2C driven.
I also have TFT 1.3" inch 240x240 SPI display that's going ok.

Next I'll be looking to display time from DS3231 RTC module on the 3.5" TFT Shield that I managed to get working but had the superimposing displayed numbers :sweat_smile:

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