Minimal ESP32 PlatformIO TFT display example using Adafruit ST7735
This example code is for the KMR-1.8 SPI display (128x160px) and provides a minimal example using theAdafruit-ST7735 library that toggles the screen from black to white repeatedly. You can use this as a check if your hardware works correctly.
Hardware connection
Note that you can use any pin number on the ESP32 ; if you use other pins, ensure to change them in the code
- Connect
A0orDC(whichever one exists on your board) toD23on the ESP32 board. - Connect
SCL(which is actually SPISCK- the pin labeledSCKis just connected to the SD card!) toD14on the ESP32 board. - Connect
SDA(which is actually MOSI - the pin labeled MOSI is just connected to the SD card!) toD12on the ESP32 board. - Connect
CStoD27on the ESP32 board. - Connect
RESETtoD22on the ESP32 board. - Connect
LED-toGNDon the ESP32 board. - Connect
VCCto3V3on the ESP32 board. - Connect
LED+to3V3on the ESP32 board. - Connect
Vccto3V3on the ESP32 board.
Do not connect any pin to VIn or 5V. This can easily damage your display!

PlatformIO source code
st7735_minimal_example.cpp
#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
constexpr int Pin_LCD_CS = 27;
constexpr int Pin_LCD_DC = 23;
constexpr int Pin_LCD_RST = 22;
constexpr int Pin_LCD_SCLK = 14;
constexpr int Pin_LCD_MISO = 12;
constexpr int Pin_LCD_MOSI = 13;
Adafruit_ST7735 lcd(Pin_LCD_CS, Pin_LCD_DC, Pin_LCD_MOSI, Pin_LCD_SCLK,
Pin_LCD_RST);
void setup() {
lcd.initR(); // Init ST7735S chip, black tab
lcd.enableDisplay(true); // Enable display
}
void loop() {
delay(500);
lcd.fillScreen(ST7735_BLACK);
delay(500);
lcd.fillScreen(ST7735_WHITE);
}platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit GFX Library@^1.11.5
adafruit/Adafruit ST7735 and ST7789 Library@^1.10.0Check out similar posts by category:
Arduino, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow