This example code is for the KMR-1.8 SPI display (128x160px) and provides a minimal example using the Adafruit-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
A0
orDC
(whichever one exists on your board) toD23
on the ESP32 board. - Connect
SCL
(which is actually SPISCK
– the pin labeledSCK
is just connected to the SD card!) toD14
on the ESP32 board. - Connect
SDA
(which is actually MOSI – the pin labeled MOSI is just connected to the SD card!) toD12
on the ESP32 board. - Connect
CS
toD27
on the ESP32 board. - Connect
RESET
toD22
on the ESP32 board. - Connect
LED-
toGND
on the ESP32 board. - Connect
VCC
to3V3
on the ESP32 board. - Connect
LED+
to3V3
on the ESP32 board. - Connect
Vcc
to3V3
on the ESP32 board.
Do not connect any pin to VIn
or 5V
. This can easily damage your display!
PlatformIO source code
#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); }
[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.0