使用 Adafruit ST7735 的最小 ESP32 PlatformIO TFT 显示示例

此示例代码适用于 KMR-1.8 SPI 显示器(128x160px),提供了使用 Adafruit-ST7735 库反复在黑色和白色之间切换屏幕的最小示例。你可以用此来检查硬件是否正常工作。

硬件连接

注意你可以在 ESP32 上使用任何引脚号;如果你使用其他引脚,确保在代码中更改它们

不要将任何引脚连接到 VIn5V。这很容易损坏你的显示器!

ESP32 连接到面包板上的 KMR-1.8 SPI 128x160px ST7735R TFT 显示器

PlatformIO 源代码

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.0

Check out similar posts by category: Arduino, PlatformIO