Displaying time on an Arduino tft display

Right. But it doesn't work. So you need to break the system down into parts that you can make work. Else, you have a big mystery that doesn't work and you don't know where the problem is.

What you are trying to do is not working.

The simplicity or complexity of displaying time with this device, really isn't relevant...

Get the time to show on the screen, thats why im asking here if there is an error with my code which is preventing the screen from showing the time, I eliminated the wiring issue to the screen by just plugging the screen into the UNO, so now our main issue would be: Code or RTC wiring

Didn't you just say,

even when I plugin the display on Arduino I get no results

?

Please pay attention! The RTC wiring is associated with the display wiring through the A4/A5 pins. That is why I want you to perform independent tests, to verify them both. But if you are using A4/A5 and also SDA/SCL for different purposes, your problem is no mystery, it is a straightforward pin conflict.

A4 is SDA, A5 is SCL.

The UNO has connections directly from the A4 header pin to the SDA header pin, and from the A5 header pin to the SCL header pin.

The RTC uses A4/SDA and A5/SCL for the I2C data transfer.

The display connects LCD_RST to A4. This is the reset line for the display.

Whenever your sketch communicates with the RTC, it is resetting the display.

You MUST disconnect the display LCD_RST pin from A4. It can be connected to the RESET pin on the UNO, it is only needed to reset the display at power-on, and the display library only uses it when the display is initialized and never again, so it is best to initialize the display before the RTC.

As pointed out numerous times already. :neutral_face: The whole answer is in post #5.

Thanks for clarifying! I actually just connected everything using jumper wires and removed the reset pins which were connected to my display and it worked! But only one issue I have now which is the text is over lapping I have changed the position in my code to: showmsgXY(90, 250, 2, &FreeSans9pt7b, t);

However it just centered the text in my screen but the text is still over lapping, what are the modifications in the code I should do to just space it out?

You may have to write blank spaces to those text locations before the call

void showmsgXY

or embed that functionality inside the function.

void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
{
  int16_t x1, y1;
  uint16_t wid, ht;

  tft.setFont(f);
  tft.setCursor(x, y);
  tft.setTextColor(0x0000);
  tft.setTextSize(sz);
  tft.print("                      "); //same size number of chars in time string
  tft.setCursor(x, y);
  tft.print(msg);
}

I didn't count the blanks. Please check that.

The previous text that is on the screen remains on the screen until you erase it, so it gets combined with the new text.

You can clear the entire screen, but this generally causes noticeable blinking.

Adafruit's library has functions to get the dimensions of a rectangular area that fits over the text, so you can draw a box in the background color to erase the old text.

The method I prefer is to save a copy of the old text, then when it is time to write new text over it, set the text color to match the background color, display the old text (this effectively erases it), then set the text color to your normal text color and display the new text.

Writing spaces generally does not work, because the spaces are blank characters that combine with the old text, effectively changing nothing.

Ok, do they not have an "alpha channel", transparency control?

Not really sure. I know the default font that Adafruit uses for their library will fill in the background color around the characters, so it is easy to use, but the various other fonts are encoded differently and cannot do this. To make matters worse, a lot of the fonts are proportional spaced, so the length of the text (and the area it occupies on the screen) is dependent on the actual characters being displayed. That is the reason the library has a function where you can give it the text and it will return the dimensions of the area on the screen that you need to overwrite.

Adafruit:

Text is normally drawn “clear” — the open parts of each character show the original background contents, but if you want the text to block out what’s underneath, a background color can be specified as an optional second parameter to setTextColor().

Check out the page on fonts:

And specifically referring to the fonts included in the font folder with Adafruit's library:

There's always something, isn't there. :slight_smile:

I'd love to see the explanation. Maybe because there isn't any alpha channel...

Well, the background option really only works with fixed-pitch fonts, and people do like proportional spacing.

Displays can be such fun.

Oooh yeah that would not work. I see what you mean. However, the method they want us to use seems tedious. If it's a one-off I could get there by trial and error, but what if it's dynamically created text sizes?

I'm not trying to make you speak for Adafruit...

I'm not just kvetching, I have a display I'm working with this week...

Yeah that is true, I'm not sure on how to do it so it refreshes the text on the screen not the screen it self. For now though (if it is easer) am I able to just refresh the screen using a line of code for it to update? If so how?

Did you just create a duplicate user account?

I don't particularly like Adafruit's method, overwriting with the old text in the background color tends to be a bit faster.

You can just figure out how long the longest line will ever be, and always blank out that entire area before writing new text.

It's better than clearing the entire screen, for sure. This clock has a fixed format - the rectangle is fixed size.