ST7789 驱动库提供显示 JPG 图片的方法,对初学者非常友好。
jpg(jpg_filename, x, y)
在给定的 x 和 y 坐标(图像的左上角)处绘制 JPG 文件。
此方法需要额外的 3100 字节内存作为其工作缓冲区。
选择任意图片,将其裁剪为 320 × 170 像素或更小的尺寸。
各种智能终端设备和各种操作系统中都有大量可选的图片编辑工具,您可以使用自己喜欢的工具进行编辑。
可使用免费的在线图片编辑工具 Pixlr X。
将裁剪后的图片放入本地 MicroPython 工作目录并重命名为 pic_1.jpg,再参考 如何使用 VS Code 和 mpbridge 工具 将其上传到 MicroPython 设备。
此处准备了裁剪后的图像。
在 main.py 脚本中使用 jpg 方法。
""" BPI-Centi-S3 170x320 ST7789 display """
import st7789
import tft_config
import gc
def main():
try:
tft = tft_config.config(rotation=1)
tft.init()
tft.jpg("pic_1.jpg", 0, 0)
tft. show()
gc. collect()
except BaseException as err:
err_type = err.__class__.__name__
print('Err type:', err_type)
from sys import print_exception
print_exception(err)
finally:
tft.deinit()
print("tft deinit")
main()
上传 main.py 后,复位设备即可在屏幕上看到图片。
再准备几张尺寸合适的 JPG 图片,即可编写循环,让 BPI-Centi-S3 像幻灯片一样循环播放图片。
""" BPI-Centi-S3 170x320 ST7789 display """
import st7789
import tft_config
import gc
import time
pic_list = ["pic_1.jpg", "pic_2.jpg", "pic_3.jpg", "pic_4.jpg", "pic_5.jpg"]
def main():
try:
tft = tft_config.config(rotation=1)
tft.init()
while True:
for pic in pic_list:
tft.jpg(pic, 0, 0)
tft.show()
gc.collect()
time.sleep(1)
except BaseException as err:
err_type = err.__class__.__name__
print('Err type:', err_type)
from sys import print_exception
print_exception(err)
finally:
tft.deinit()
print("tft deinit")
main()