BPI-Centi-S3 正面配有 1.9 英寸 TFT LCD 彩屏,分辨率为 170×320,驱动芯片为 ST7789V3,通过 8 位并行接口连接 ESP32-S3。
ST7789 C 模块驱动程序已集成在工厂固件中,来自:
russhughes/st7789s3_esp_lcd,采用 MIT 许可证。
感谢 russhughes 开源该项目。编译方法和全部 API 说明请参阅其 GitHub README。
在本地文件夹中新建 main.py,将以下代码复制到文件中并保存。
在当前窗口中按
ctrl + S快捷键保存文件。
""" BPI-Centi-S3 170x320 ST7789 display """
import st7789
from machine import freq
def config(rotation=0, options=0):
return st7789.ST7789(
170,
320,
15, 14, 13, 12, 11, 10, 9, 8,
wr=6,
rd=7,
reset=3,
dc=5,
cs=4,
backlight=2,
power=2,
rotation=rotation,
options=options)
freq(240_000_000) # Set esp32s3 cpu frequency to 240MHz
tft = config(rotation=1, options=0)
tft.init() # Initialize
tft.fill(st7789.RED)
tft. show(True)
tft.deinit() # Deinitialize the display or it will cause a crash on the next run
使用 mpbridge 将文件同步到开发板。
当同步完成后, BPI-Centi-S3 屏幕将全屏呈红色。
可将 ST7789 的初始化和配置代码放入单独的 Python 脚本文件,再从其他代码或 REPL 中导入使用,从而提高代码复用性。
新建独立配置文件 tft_config.py,将以下代码复制到文件中并保存。
""" BPI-Centi-S3 170x320 ST7789 display """
import st7789
from machine import freq
def config(rotation=0, options=0):
return st7789.ST7789(
170,
320,
15, 14, 13, 12, 11, 10, 9, 8,
wr=6,
rd=7,
reset=3,
dc=5,
cs=4,
backlight=2,
power=2,
rotation=rotation,
options=options)
freq(240_000_000) # Set esp32s3 cpu frequency to 240MHz
将 main.py 修改为以下代码:
""" BPI-Centi-S3 170x320 ST7789 display """
import st7789
import tft_config
tft = tft_config.config(rotation=1, options=0)
tft.init()
tft.fill(st7789.RED)
tft. show(True)
tft.deinit() # Deinitialize the display or it will cause a crash on the next run
使用 mpbridge 将文件同步到开发板。
稍后我们可以像这样简单地导入和初始化屏幕。