Hello and welcome to today's post.
Our low-cost 1.8 inch SPI TFT display allows to show information in colour with a resolution of 128 x 160 pixels.
Thanks to the SPI interface, the ST7735 controller chip, and the wide range of Arduino IDE libraries, it is very easy to implement in your own projects.
Microcontrollers with ESP-32 can also control the TFT display via SPI. But for this you need a manually adapted library for the ESP32. Otherwise the installation is quite simple.
We have already shown you how to install the ESP32 via the Arduino IDE board manager in the article "Installing ESP32 via the board manager". So we assume that the current board definitions for the ESP32 are already installed.
Installation of the library
To be able to control the display, we use the library "TFT_ESPI" by Bodmer. This library is not part of the Arduino basic installation, but can be found in a few steps over the Library manager be installed in the Arduino IDE.
About the menu "sketch" -> "Incorporate the library" -> "Manage libraries ..."Let's open the library manager. Alternatively, you can Key combination "Ctrl" + "Shift" + "I" use.
In the search field of the library manager we enter "TFT_eSPI", and install "TFT_eSPI by Bodmer" in the current version.
In order for the library to work with our ESP32, we have to manually adjust the following file once.
To do this, we open under Windows with the file manager in the Sketchbook directory. You can find this in the preferences of the Arduino IDE. In this folder is the subfolder libraries. There in turn is the folder TFT_eSPI and in it the file User_Setup.h, which we open with a text editor of our choice.
If you can't find the file right away, you can also open a sample sketch and then select "Open sketch folder (CTRL+K)" from the "Sketch" menu. You will then be in the "Examples" subfolder of the TFT eSPI library. In the file manager you then only have to go back to the above-mentioned parent folder.
With a right click on the file we open the context menu and select the option "open with..." and then as program e.g. "Notepad".
In the file a variety of setting options are offered.
A "//" at the beginning of a line is a comment line. All unnecessary lines must be commented out and in the important lines the "//" at the beginning of the line must be removed.
I have already done this work for you. So you can replace the content of User_Setup.h with the following code:
Then of course we still have to save the changes.
Wiring the display with the ESP32
In the file just edited, we have determined which PIN takes over which function. In order for this configuration to work, the display must be connected to the ESP32 as follows:
Try sample sketches
In the Arduino IDE we now make sure that we have selected the module "ESP32 Dev Module" in the menu "Tools" under "Board:".
Now we can go to the menu "File" -> "Examples" -> "TFT_eSPI" -> "160x128" and call an example sketch and load it on our ESP32 without any further changes or configuration.
Here is a photo of the Pong_V3.ino example sketch in action:
We hope today's article will help you to start up the TFT display on the ESP32 and wish you a lot of fun while building it.