ElectronicZoologyfield notes from the garage
Display • ESP32 • TFT_eSPI

How to use the
ST7789 240x240 display
with ESP32

Display: ST7789 - 240x240 TFT
Board: ESP32 Dev Board (38-pin)
✓ Confirmed Working

Overview

The ST7789 is a 240x240 TFT display driven over SPI. It is the square equivalent of the GC9A01 and uses the same pin layout. Many modules use the same breakout board form factor.

This page covers the User_Setup_Select.h config to drive it with TFT_eSPI. Once configured, use the How to set up TFT_eSPI with ESP32 - test sketch to confirm it is working.

Wiring

Display PinESP32 PinNotes
VCC3.3V or 5VCheck your module - most accept both
GNDGND
SCL / SCLKGPIO 18SPI clock
SDA / MOSIGPIO 23SPI data
DCGPIO 2Data / command select
CSGPIO 15Chip select
RSTGPIO 4Reset
MISOGPIO 19Optional

If your module has a BL (backlight) pin, tie it to 3.3V.

Config

1. Open User_Setup_Select.h

Open ~/Arduino/libraries/TFT_eSPI/User_Setup_Select.h. Comment out the default line and uncomment Setup24:

//#include <User_Setup.h>           // comment this out
#include <User_Setups/Setup24_ST7789.h>  // uncomment this

2. Edit the pins in Setup24

Open ~/Arduino/libraries/TFT_eSPI/User_Setups/Setup24_ST7789.h. The default uses NodeMCU-style pins - replace the active pin defines with these:

Comment outUncomment / add
#define TFT_CS -1#define TFT_CS 15
#define TFT_DC PIN_D1#define TFT_DC 2
#define TFT_RST PIN_D4#define TFT_RST 4

Also uncomment the ESP32 MOSI/SCLK/MISO lines already present in the file:

#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
Only one line uncommented in User_Setup_Select.h at a time. When switching displays, comment this line out and uncomment your next display. Close and reopen Arduino IDE after saving either file.

Notes

Display is blank but no errors

The ST7789 can be sensitive to the RST pin. Confirm GPIO 4 is wired to RST and not floating.

Image offset or wrong size

Some ST7789 modules are 240x280 or 170x320. If the image is cropped or offset, update TFT_WIDTH and TFT_HEIGHT in Setup24 to match your actual display resolution.