用于 RGB 显示器的 CircuitPython 库。
项目描述
介绍
从https://github.com/adafruit/micropython-adafruit-rgb-display到 Adafruit CircuitPython的显示驱动程序端口,用于 Adafruit 基于 SAMD21 和其他 CircuitPython 板。
此 CircuitPython 驱动程序当前支持使用以下显示驱动程序芯片的显示器:HX8353、HX8357、ILI9341、S6D02A1、ST7789、SSD1331、SSD1351 和 ST7735(包括变体 ST7735R 和 ST7735S)。
依赖项
此驱动程序取决于:
请确保 CircuitPython 文件系统上的所有依赖项都可用。这可以通过下载 Adafruit 库和驱动程序包轻松实现。
对于枕头示例,您需要运行 CPython。这意味着在 Linux、Window 或 Mac 上使用单板计算机(例如 Raspberry Pi)或使用芯片(例如 FT232H)。CircuitPython 不支持 PIL/pillow(python 成像库)!
为了提高性能,请考虑安装 NumPy。
从 PyPI 安装
在 Raspberry Pi 等受支持的 GNU/Linux 系统上,您可以从 PyPI本地安装驱动程序。为当前用户安装:
pip3 install adafruit-circuitpython-rgb-display
要在系统范围内安装(在某些情况下可能需要这样做):
sudo pip3 install adafruit-circuitpython-rgb-display
要在当前项目的虚拟环境中安装:
mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-rgb-display
使用示例
2.2”, 2.4”, 2.8”, 3.2” TFT
import time
import busio
import digitalio
from board import SCK, MOSI, MISO, D2, D3
from adafruit_rgb_display import color565
import adafruit_rgb_display.ili9341 as ili9341
# Configuration for CS and DC pins:
CS_PIN = D2
DC_PIN = D3
# Setup SPI bus using hardware SPI:
spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO)
# Create the ILI9341 display:
display = ili9341.ILI9341(spi, cs=digitalio.DigitalInOut(CS_PIN),
dc=digitalio.DigitalInOut(DC_PIN))
# Main loop:
while True:
# Clear the display
display.fill(0)
# Draw a red pixel in the center.
display.pixel(120, 160, color565(255, 0, 0))
# Pause 2 seconds.
time.sleep(2)
# Clear the screen blue.
display.fill(color565(0, 0, 255))
# Pause 2 seconds.
time.sleep(2)
1.14” TFT 与树莓派 4
使用 1.14”接线,这里是工作代码:
import time
import busio
import digitalio
from board import SCK, MOSI, MISO, CE0, D24, D25
from adafruit_rgb_display import color565
from adafruit_rgb_display.st7789 import ST7789
# Configuration for CS and DC pins:
CS_PIN = CE0
DC_PIN = D25
RESET_PIN = D24
BAUDRATE = 24000000
# Setup SPI bus using hardware SPI:
spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO)
# Create the ST7789 display:
display = ST7789(
spi,
rotation=90,
width=135,
height=240,
x_offset=53,
y_offset=40,
baudrate=BAUDRATE,
cs=digitalio.DigitalInOut(CS_PIN),
dc=digitalio.DigitalInOut(DC_PIN),
rst=digitalio.DigitalInOut(RESET_PIN))
# Main loop: same as above
while True:
# Clear the display
display.fill(0)
# Draw a red pixel in the center.
display.pixel(120, 160, color565(255, 0, 0))
# Pause 2 seconds.
time.sleep(2)
# Clear the screen blue.
display.fill(color565(0, 0, 255))
# Pause 2 seconds.
time.sleep(2)
文档
这个库的 API 文档可以在Read the Docs上找到。
有关构建库文档的信息,请查看本指南。
贡献
欢迎投稿! 在帮助这个项目保持受欢迎之前,请阅读我们的行为准则。