adafruit 5 color tft display quotation
Displays are one of the best ways to provide feedback to users of a particular device or project and often the bigger the display, the better. For today’s tutorial, we will look on how to use the relatively big, low cost, ILI9481 based, 3.5″ Color TFT display with Arduino.
This 3.5″ color TFT display as mentioned above, is based on the ILI9481 TFT display driver. The module offers a resolution of 480×320 pixels and comes with an SD card slot through which an SD card loaded with graphics and UI can be attached to the display. The module is also pre-soldered with pins for easy mount (like a shield) on either of the Arduino Mega and Uno, which is nice since there are not many big TFT displays that work with the Arduino Uno.
This ease of using the module mentioned above is, however, one of the few downsides of the display. If we do not use the attached SD card slot, we will be left with 6 digital and one analog pin as the module use the majority of the Arduino pins. When we use the SD card part of the display, we will be left with just 2 digital and one analog pin which at times limits the kind of project in which we can use this display. This is one of the reasons while the compatibility of this display with the Arduino Mega is such a good news, as the “Mega” offers more digital and analog pins to work with, so when you need extra pins, and size is not an issue, use the Mega.
To easily write code to use this display, we will use the GFX and TFT LCD libraries from “Adafruit” which can be downloaded here. With the library installed we can easily navigate through the examples that come with it and upload them to our setup to see the display in action. By studying these examples, one could easily learn how to use this display. However, I have compiled some of the most important functions for the display of text and graphics into an Arduino sketch for the sake of this tutorial. The complete sketch is attached in a zip file under the download section of this tutorial.
As usual, we will do a quick run through of the code and we start by including the libraries which we will use for the project, in this case, the Adafruit GFX and TFT LCD libraries.
With this done, the Void Setup() function is next. We start the function by issuing atft.reset() command to reset the LCD to default configurations. Next, we specify the type of the LCD we are using via the LCD.begin function and set the rotation of the TFT as desired. We proceed to fill the screen with different colors and display different kind of text using diverse color (via the tft.SetTextColor() function) and font size (via the tft.setTextSize() function).
Next is the void loop() function. Here we basically create a UI to display the youtube subscribe button, using some of the same functions we used under the void setup() function.
The Adafruit library helps reduce the amount of work one needs to do while developing the code for this display, leaving the quality of the user interface to the limitations of the creativity and imagination of the person writing the code.
It appears some TFT displays have the red and blue pixel elements swapped. This is rather odd because the default colour order is the same as the Adafruit libraries for that display.
Anyway, I have updated the master library driver files for the HX8357D display to permit the colour order to be defined in the setup file. By default the colour order is RGB (as in Adafruit libraries) but this can be changed to BGR. The Setup_15 header has been updated with the following two lines:
It appears some TFT displays have the red and blue pixel elements swapped. This is rather odd because the default colour order is the same as the Adafruit libraries for that display.
Anyway, I have updated the master library driver files for the HX8357D display to permit the colour order to be defined in the setup file. By default the colour order is RGB (as in Adafruit libraries) but this can be changed to BGR. The Setup_15 header has been updated with the following two lines:
The way things appear on displays is by pixels being set on/off or to some level of colours. To display a picture it"s really just an x,y rectangular grid of pixels so, in the simplest form you go across the x"s and down the y"s setting each pixel in turn.
Most LCD libraries have functions like set_pixel(x,y) and for graphics displays there"s a strong chance there is a bitblt(x,y,data) which takes a pointer to your array and arranges to blit the pixels to the display at the starting x,y position. Internally the library probably uses the same routine to blit characters of a font (just small rectangular pictures after all) to the display and at an even higher level there"s probably lcd_choose_font() and lcd_print_string(). One chooses which set of rectangles might be blitted and the other works along a string of character looking up the right "picture" for each character in the string and blits each in turn to the output moving the destination X value on by the width of the character just output each time.
When you have that and when you have massaged the BMP data into the same pixel format as the display uses you are ready to lcd_blit() that array onto the screen.
PS when I google the name of this display I see a mention on Adafruit (always a good sign as there"s a fair bet the works been done and done well!). It leads to:
But that is going to need the MikroC compiler methinks - it as an odd scheme where you pick things like TFT support in the project settings. I doubt the licence on the 4K eval copy allows you to steal their TFT library code (even if you could make it work with a real C compiler!).