ESP32 SPI TFT display

I had this tiny TFT display laying around from another project and thought that is a good start to play with my new ESP32 module.

I knew that the interface to the display is SPI and the driver chip is an ILI9163. The screen resolution is 128×128 pixel.





The hardware connection:

For the connection to the ESP32 I chose the default VSPI pins on my ESP32 module.

  • MOSI -> GPIO23
  • MISO -> GPIO19 (not used as the communicationto the display is one way only)
  • SCLK -> GPIO18
  • SS (CS) -> GPIO5

In addition the display needs a DC line to switch between command and data communication

  • DC -> GPIO19 (Yes! I chose the same GPIO as for MISO, as I said MISO is not used!)

Other pins of the display are for the power supply (+5V and GND), RST and LED.

  • RST is to reset the display. I don’t use that pin, instead a software reset of the display is initiated when the TFT_eSPI is initialized.
  • LED pin can be used to switch the display on/off, a feature that I don’t use as well.

The display itself is powered with 5V, but the communication lines are already 3.3V compatible, so there is no level shifter necessary.

Display connection schematics



The software library

To communicate with the display one can either write everything from scratch or use a library that contains all the low-level communication and offers a Cpp class that can be used from the application. As I usually try to not reinvent the wheel, I was looking for a library that supports this type of display. There are many libraries available, but most of them are not (yet) fully compatible with the ESP32. I decided to go with Bodmers TFT_eSPI library, as it was designed to work with the ESP8266 already and needed only a small change to work fine with the ESP32. I made this changes (and of course contributed them to the original library with a pull request.)

The library is designed to work with many different display types. Originally it was necessary to create a include file that specifies the display type, GPIO pins and fonts to be used in a specific application. But thanks to atanisoft there is an easier solution (in case you use PlatformIO/Atom or PlatformIO/Visual Studio Code). The required parameters can be defined in the platformio.ini file specific for each project and there is no more need to create a header file for each display or connection configuration as build flags. Here is how the platformio.ini file looks like with the parameter definitions:



The software to use the display

To use the library, of course we need to include the header file

Then we need to add the class

And then we need to initialize the connection in our void setup() routine

That’s all, now you can use the functions of the library to clear the screen, fill it with text or squares or circles. Here is a short overview of the available functions:

I don’t want to list all of them here, check out the TFT_eSPI repository for more information and explanations how to use the library.

The only function I missed was how to draw an icon (or small bitmap) that is stored as an array. Luckily the TFT_eSPI examples include this as well. I extracted the drawIcon() function from there.

The icons are stored as const unsigned short arrays in a header file. Here is an extract of how the header file looks like:

There are applications available that can convert BMP or PNG files into these kind of arrays. Arrays containing FLASH images can be created with UTFT library tool ImageConverter565.exe. You can find it easily with a search in your browser.


Leave a Reply

Your email address will not be published. Required fields are marked *

Free Link Directory