Displaying Icons on 3.5in TFT Touch Screen (ILI9481)

Hi everyone,
This is my first post on an Arduino forum, so if my post isn’t at the right spot just let me know :). I’m currently working on a automatic bonsai tree care program. I’m now it the stage of building and programming the TFT interface and as mentioned in the title I’m using a 3.5in TFT touchscreen with a Arduino Mega 2650. I have problem displaying icons on the screen. I tried to find online for hours and all i could find either wasn’t what i wanted to do or didn’t work… This forum is my last resort. I need your help hahaha! I’ve attached my sketch folder with the program I have so far and the icon I’m trying to display. If anybody would be so kind to help me understand why it isn’t working and what I need to do to make it work, it would be awesome!

Thank you very much!
Arcadia117

Auto_Bonsai_Care__v1.0.zip (10.1 KB)

You have generated a C array of (uint16_t) pixels in your Icons directory.
But then you changed the type to uint8_t in the icons.c tab.

There are several ways to show a colour bitmap e.g.

...
extern const uint16_t SoilMoisture48[];  //pixel array in PROGMEM i.e uint16_t
...
     tft.drawRGBBitmap(260, 120, SoilMoisture48, 48, 48);

or

...
extern const uint16_t SoilMoisture48[];
...
    tft.setAddrWindow(260, 120, 260+48-1, 120+48-1); //this takes start, end arguments
    //pushColors() understands uint8_t arrays or uint16_t arrays in SRAM
    //pushColors() just expects a stream of bytes from PROGMEM.  It defaults to little-endian 
    tft.pushColors((const uint8_t*)SoilMoisture48,48*48,1);

I would advise using the GFX method. It may be SLOW but it is straightforward.

pushColors() is much faster. It can display images that are stored in big-endian or little-endian.

In practice, if your application has lots of icons you would write a helper function that does any horrible casting in one place.
If you only have one icon, just use the drawRGBBitmap() method.

void displayIcon(int x, int y, const uint16_t bitmap[], int w, int h)
{
#if 0
    tft.drawRGBBitmap(x, y, bitmap, w, h);  //GFX method
#else
    tft.setAddrWindow(x, y, x + w - 1, y + h - 1); //hardware method
    tft.pushColors((const uint8_t*)bitmap,w * h,true);
#endif
}
    ...
    // Display Icons
    displayIcon(260, 120, SoilMoisture48, 48, 48);
    ...

David.

Wow thank you very much !!! it finally worked !!

1 Like

Which did you choose?

GFX method or hardware method?

Thanks for pointing out the ambiguity.
If and when I issue a new Release of the library, I will clarify the example.

David.

Hi David,
I used the hardware method since i have about 11 icons to display at different moment on the screen depending on temperature, water tank level, etc…! so this method worked best for me ! I have another question thought that might be in the same category of this post. I’m currently working on updating the value of different sensor and i want to only display them when I’m on the home screen (currentPage = 1). When I start the program it only gets the first reading and when it goes for the second reading, my home screen disappear and the TFT display goes white. If i look on the serial monitor thought, I can see my programm working and to what it supposed to do (i.e. activate step motor, turn on/off relays, etc…). Could you help me with that ? I’ve attached the program and a picture of the wiring if you want to try it!
Thank you so much for your help!
Arcadia117

Auto_Bonsai_Care__v1.0_2020-03-06.zip (277 KB)

I strongly recommend that you study the “button_simple” example.
Life is easier with Adafruit_GFX_Button
And Touch is easier with copy-paste of “const int” statements instead of #defines.

Your white screen is due to:

  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();   // Read touchscreen
  digitalWrite(13, LOW);
  
  pinMode(XM, OUTPUT);
  pinMode(YM, OUTPUT);

The Analog Touch pins are XM, YP. You will crash if you don’t restore after a ts.getPoint() call.

const char softwareVersion[4] = "v1.0";

Your array is too small to hold the NUL. (hence the garbage print)

David.

Thanks for the fast reply!! i really appreciate it ! so to my understanding the only problem was that YM instead of YP in the loop ? god i would have looked a long time to find that problem if it wasn't for you. On the subject of the touch button, is the Adafruit_GFX_button is include in the Adafruit_GFX library? because i'm looking for the "button_simple" example but i can't find it

Thanks a lot !
Arcadia117

Button_simple.ino is a MCUFRIEND_kbv example.