Zonnestroompanelen in Nederland

duurzaamheid achter de meter

(28) ESP32-WROOM-32 and ILI9341 TFT display – an interesting match

by Floris Wouterlood – The Netherlands – March 1, 2021

Compared with an Arduino Uno the ESP32-WROOM microcontroller board earns the label ‘mighty & fast platform’. The ESP32 features an impressive 32-bit dual core microprocessor with a long list of features. Most interesting to explore are its 520 kB RAM to store program instructions and 4 MB flash memory, depending on the specific chip. The microprocessor runs 32 bit instructions at 40 MHz (specifications by the manufacturer). That’s a lot more and a lot faster than what the Uno performs. And because ESP32 microcontrollers are supported by the Arduino IDE after a board support update they are programmable in the familiar Arduino environment. Existing Arduino sketches can via the expanded Arduino IDE be ‘ported’ to the ESP32 platform.
The current project deals with display support. First a test bench is constructed with pin headers to accommodate the ESP32 microprocessor board and a TFT display equipped with a single row of pins. On this bench an ESP32-WROOM-32 DEV board is mounted together with a 320*240 SPI TFT display with ILI9341 controller. Sketches lean on Bodmer’s TFT_eSPI library. Examples supplied by Bodmer’s library are of great help and inspiration. The demo sketches attached to this post are an adaptation of Bodmer’s rainbow circular scale gauge (fig 1) and Muybridge’s galloping horse, Sallie Gardner (fig. 5).

figure 1. Test bench featuring an ESP32-WROOM-32 board and a 2.8 inch diagonal 320*240 TFT display with ILI9341 controller and SPI interface. The display shows Bodmer’s circular rainbow gauge scale. Both devices are mounted on pin headers soldered to the soldering prototyping board.

ILI9143 controlled TFT displays
ESP32 microcontroller boards support larger displays. Here we connect a 320*240 TFT display with a SPI pin-out. The back of the TFT display with its single row of pins is shown in figure 2.

figure 2. Back of a SPI TFT with pin-out connection table.

The display shown in figures 1 and 2 has a touch screen. The pins supporting ‘touch’ as well as the pins connecting the SD card reader are not connected: we concentrate on displaying text, variables, graphics and fast sequences of bitmaps (‘image frames”). The ILI9341 controller is fast and, in combination with an ESP32, performs very good.

Test bench
To create order where wire chaos threatens a test bench was constructed. The concept here is that components should always be replaceable. A breadboard is fine, yet it runs a risk in a test situation to become overwhelmed with jumper wires, resistors, sensors and the like to such a degree that the test environment becomes confused. Moreover, loose wires and poor pin connections often cause malfunctions that divert attention away from testing components.
The base for the current bench is a 12×8 cm double-sided soldering board featuring 42*30 holes. On this board four rows of 18-pin female pin headers are soldered to accommodate the 36-pin ESP32 microcontroller board, one 14-pin female pin header to accommodate the TFT display pins and two 2-pin female pin headers that may serve as auxiliary 3.3V power supply and GND to external equipment connected to the bench. The table in Figure 2 documents the wiring between the ESP32 and the display pin header. The rows of pin headers parallel to the ESP32 parallel pin provide on-bench access to the ESP32 pins (figure 1, 3).

Wiring diagram
Figure 3 shows the pin-to-pin wiring on the test bench for a 36-pin ESP32-WROOM-32 connected to a TFT display with SPI connector. The display at hand uses the SPI serial protocol and needs six wires to take care of: LED, SCK, SDI, D/C, RST, and CS. In addition there is GND and power (this TFT is a dedicated 3V3 device).

figure 3: wiring diagram for the test bench.

figure 4: back of the test bench with wiring soldered to the pin headers. Thick red wire = 3.3V; thick black wire = GND.

Note on using the TFT_eSPI library
The electronic engineer operating under the name ‘Bodmer’ has created an extensive library that supplies C++ functions in support of display of text and primitive functions on SPI-TFT displays with various controllers in conjunction with an ESP32 microprocessor.

Workflow with the TFT_eSPI library is organized in a different way than with other graphical display libraries. A main difference is that the TFT display’s controller is defined in a custom user setup file that is saved in the library folder. How to proceed with a workflow once you have installed the library via Sketch→ Include Library→ Manage Libraries is as follows:

  • Locate with your favorite file manager in your Arduino library folder the folder named ‘TFT_eSPI’.
  • Open that folder, locate the folder ‘User_Setups’ and open that folder. ‘User_Setups’ contains a series of predefined Setup.h files.
  • Open an appropriate Setup.h file with a text editor and uncomment the lines dealing with your specific TFT controller.
  • Save this file under an appropriate name in the User_Setup folder. In my case I used ‘ Setup_FW_WROOM32_ILI9341_TFT_018_OK.h’ to indicate the specific microcontroller and display
  • Edit the file ‘User_Setup_Select.h’, that is, add a line pointing at your personal User_setup file. In my case I added: #include User_Setups/Setup_FW_WROOM32_ILI9341_TFT_018_OK.h
  • and comment out all other lines pointing to special User_Setup.h configurations

Although this sounds quite complex the result is that now there exists a user setup file that is specific for the combination of the particular microprocessor and TFT controller being used, here an ESP32-WROOM32 that provides output to an ILI9341 controlled TFT display.

The effects for your sketch and on compilation are the following:

For your sketch:

  • You don’t have to make a ‘constructor’ such as required with many libraries, e.g. those that support OLEDs and 128*64 graphical LCDs. You can concentrate on the instructions governing your application.

On compilation:

  • TFT_eSPI automatically consults ‘User_Setup_Select.h’ whether there exists in the User_Setups folder a specific configuration folder for your microprocessor/TFT combination.
  • If so, the compiler follows the instructions set out in this specific setup file.

Implication of this way of dealing with the wealth of available microprocessor boards and TFT controllers:

  • Whenever you implement the TFT_eSPI library with a different microcontroller board/ TFT controller combination you must create a new specific setup file for this combination and create a line in ‘User_Setup_Select.h’ that points at the newly created specific setup.h file.

The TFT_eSPI approach of using specific setup files differs from the ‘classical’ approach set by the Adafruit_GFX.h library. Consider the specific setup.h as an extended ‘constructor’ file.

Test bench at work
Figure 1 shows the test bench at work with the first sketch provided with this post. The combination is: board definition in the Arduino IDE: “ESP32DevModule”; display is a 2.8 inch ILI9341 SPI display. Running is the sketch ESP32_WROOM_ILI9341_rainbow_scale.ino. The circular rainbow scale was introduced as ‘ring meter’ by Bodmer in an Instructables post*. Its core instructions are in Adafruit_GFX library convention and can easily be transferred to TFTs with other controller chips. For example, I am successfully using Bodmer’s circular rainbow scale with an Arduino Nano – ILI9481 TFT combination that displays circulation temperatures in floor heating loops**.

figure 5: Test bench running the sketch ‘ESP32_WROOM_TFT_eSPI _ILI9341_Muybridge_Sallie.ino’.

ESP32 microprocessors are so powerful and offer program memory in such an abundance that I was tempted to port my ‘Muybridge’s Sallie Gardner – galloping horse’ animation to the current workbench configuration. The original galloping horse animation consists of 10 bitmap frames each 96*64 pixels, created to be run with microcontrollers of the Arduino Uno – Nano family, and to be displayed on a 128*64 LCD, various OLEDs or TFT displays. As the ESP32s are much more powerful than the Uno I prepared frames in larger formats: 144*96 pixels and 240*160 pixels. One frame in the 144*96 format has a file size of 1,728 bytes; in 240*160 file size is 4,800 bytes. To my surprise the 144*96 format sketch runs on an Arduino Uno. The sketch fills 90% of the Uno’s program memory (29,114 bytes) and the horse gallops fairly. The 240*160 format is too big to fit in the Uno’s program memory. An ESP32, by contrast, loads the 240*160 format without problem. However, while with the ESP32 the 144*96 animation horse gallops fiercely the 240*160 performs poor: frame changes and frame buildup become visible. Hence we stick here with the 144*96 format.

The test bench at work with the second demo sketch is shown in figure 5. The race horse, named ‘Sallie Gardner’ and its jockey gallop happily along in this 144*96 pixel image frame sketch. Frame speed is maximal. There is no annoying delay in between two frames. As I reduced the delay in between the display of successive frames to zero milliseconds the horse can’t and won’t run faster.

Downloadable sketches:

There are two sketches:

ESP32_WROOM_TFT_eSPI_ILI9341_rainbow_scale.ino: a counter that drives the circular rainbow scale (as illustrated in figure 1).
ESP32_WROOM_TFT_eSPI _ILI9341_Muybridge_Sallie.ino: the galloping horse at 144*96 pixels (as illustrated in figure 5).

sketches are packed in a ZIP file


*Bodmer – Arduino Analogue ‘ring’ Meter on Colour TFT Display – Instructables com, March 17, 2015
url: https://www.instructables.com/Arduino-analogue-ring-meter-on-colour-TFT-display/

**Nokia 5510 84*48 LCD and the ESP8266 Wemos D1 mini microcontroller board – Floris Wouterlood – January 15, 2021

url: Thesolaruniverse.wordpress.com – January 15, 2021

***Stop-motion of Eadward Muybridge’s galloping horse on Arduino 128*64 LCD, OLED and various TFT displays – Floris Wouterlood, May 23, 2020

Arduino project 39 – deze website