Zonnestroompanelen in Nederland

duurzaamheid achter de meter

(31) 1.8 inch 128*160 pixel SPI TFT wiring to an ESP32 microcontroller

by Floris Wouterlood – The Netherlands – October 22, 2021

Summary
An 1.8″ diagonal 128*160 pixel color display holds the middle between the tiny 0.96” TFT and OLED displays and the big 3.5” screens with 320*480 pixels. This feature, and its affordability, makes this display attractive for a scala of applications. Combined with an ESP32 microcontroller there is an abundance of cheap processing power and memory to experiment freely with this type of display. There are 65.536 colors to choose from; resolution is sufficient to display graphics, pictures or short animations. Here we wire an 1.8″, 128*160 pixel TFT display with ST7735S controller to an ESP32 microcontroller board and we run an animation.

figure 1. Wiring diagram: ESP32-WROOM-32 board, 1.8” 128*160 SPI ST7735 TFT display.

Pin mapping: VCC, GND and LED
The TFT breakout board at hand has 8 pins (figure 1) of which 5 serve the SPI interface. The three non-SPI pins are marked VCC, GND and LED.
Pins VCC and GND are obvious. Note that the display shown here is a 3.3V specimen. Pin VCC is therefore connected to 3.3V of the ESP32. GND is connected to GND. The pin marked LED serves the backlight of the display. Left unconnected the screen stays dark. Connected to the 3.3V pin of the ESP32 one gets full backlight. If connected to pin 32 of the ESP32, the backlight can be switched on or off, while the intensity can be regulated via pulse width modulation (PWM).

Pin mapping: five SPI pins
We are using conventional pin mapping: SCL (clock) and SDA (data, on other displays named MOSI) connect to pins D18 and D23 of the ESP32, respectively. A0 is connected to pin D2, RST (reset) to pin D4 and CS (chip select) to pin D15 of the ESP32.

Library: TFT_eSPI
The TFT’s controller is a ST7735S chip which is perfectly supported by Bodmer’s TFT_eSPI library. Bodmer’s library can be used with several microcontroller/display controller combinations. TFT_eSPI acts as a kind of two-stage rocket. Both stages need to be edited before launch cn commence.

first stage: locate and edit the file User_Setup_Select.h. This is an ascii file. In this file, create a line referring to your specific Setup_xxxx.h file, e.g.

#include <User_Setups/Setup_WROOM32_ST7735_128x160_TFT.h>

second stage: in the folder User_Setups either find an appropriate example or use the template file, edit it to suit your specific microcontroller/display controller combination and save under the name referred to previously. Note: this file should be located in the folder User_Setups.

content of Setup_WROOM32_ST7735_128x160_TFT.h
Note: The original for this Setup_xxxx is the SetupX_Template.h that can be found in the folder User_Setups in the TFT_eSPI ensemble. The template is fulI of commented lines of which I removed the non-essential because we are dealing with our own particular combination of the ESP32 microcontroller and ST7735 graphical controller and nothing else.

// Setup_WROOM32_ST7735_128x160_TFT.h #################################################
//
// Section 1. Call up the right driver file and any options for it
//
// ################################################

#define ST7735_DRIVER // Define additional parameters below for this display
#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue

// ################################################
//
// Section 2. Define the pins that are used to interface with the display here
//
// ################################################

#define TFT_BL 32 // LED back-light control pin
#define TFT_BACKLIGHT_ON HIGH // Level to turn ON back-light (HIGH or LOW)

#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS 15 // Chip select control pin
#define TFT_DC 2 // Data Command control pin
#define TFT_RST 4 // Reset pin (could connect to RST pin)

// ################################################
//
// Section 3. Define the fonts that are to be used here
//
// ################################################

#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font
#define LOAD_FONT2 // Font 2. Small 16 pixel high font
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font
#define LOAD_FONT6 // Font 6. Large 48 pixel font
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font
#define LOAD_FONT8 // Font 8. Large 75 pixel font
#define LOAD_GFXFF // FreeFonts.
#define SMOOTH_FONT

// ################################################
//
// Section 4. Other options
//
// ################################################

#define SPI_FREQUENCY 27000000
#define SPI_READ_FREQUENCY 20000000
#define SPI_TOUCH_FREQUENCY 2500000

Downloadable sketch

WROOM32_ST7735_runner.ino

The sketch is packed in a ZIP file. The display in Figure 1 shows one of the 12 frames that make up this ‘running man’ animation.