【FireBeetle 2 ESP32 C6 开发板】+ 驱动 DFR0664 IPS LCD
<div class='showpostmsg'>## Previously1. [【FireBeetle 2 ESP32 C6】+ 开箱及更新 Circuitpy 固件](https://bbs.eeworld.com.cn/thread-1281496-1-1.html)
1. [【FireBeetle 2 ESP32 C6 开发板】+ 使用 Web Workflow 开发](https://bbs.eeworld.com.cn/thread-1281597-1-1.html)
1. [【FireBeetle 2 ESP32 C6 开发板】+ 测试使用板载 core modules](https://bbs.eeworld.com.cn/thread-1282655-1-1.html)
# 驱动 DFR0664 TFT 显示屏
(https://wiki.dfrobot.com.cn/_SKU_DFR0664_2.0_240x320_LCD) 采用 ST7789V 驱动芯片,其分辨率为320x240,采用 SPI 通信方式,并板载 SD 卡槽,可以轻松的从 SD 卡中读取全彩色位图。模块提供了两种接线方式,一种为普通排针接线方式;另一种为GDI(General Display interface)接口
<p style="text-align:center;">
<img src="https://img.dfrobot.com.cn/wiki/none/bbc55593d232a10fced56ab97637f646.jpg" alt="Example Image" style="transform: rotate(0deg);">
<img src="https://img.dfrobot.com.cn/wiki/none/e9c85a9059f0d664795f9b67f807c001" alt="Example Image" style="transform: rotate(270deg);">
</p>
## 引脚说明
|标号 | 名称| 功能描述|
| ------------ | ------------ | ------------ |
| 1| VCC| 电源正极|
| 2| GND| 电源负极|
| 3| SCLK| 时钟|
| 4| MOSI| 数据(主机发送从机接收)|
| 5| MISO| 数据(主机接收从机发送|
| 6| CS| 屏幕片选|
| 7| RES| 复位|
| 8| DC| 数据/命令|
| 9| BL| 背光。背光设定了默认值,用户不用连接背光引脚也可点亮;此外,连接背光引脚,输入高电平(1)是将背光亮度调到最大,输入低电平(0)是关闭背光|
| 10| SDCS| SD卡片选|
## CircuitPython Displayio Quickstart
### 导入 cpy 库
需要从 adafruit-circuitpython-bundle 获取驱动库 `adafruit_st7789.mpy` 和 显示库(整个目录) `adafruit_display_text`,导入至板卡的 lib 目录,具体步骤可以参考上一章
### 示例代码
实现了背景及上层画布的绘制和文本的显示。
> 引脚说明
> rst 引脚我没有赋值,因为 GDI 接口连到了板卡的 IO14 引脚,但是 circuitpython 并没有初始化该引脚,所以无法使用
> bl 引脚在 GDI 接口中连到了板卡的 IO15 引脚,和板载 LED 脚位共用,后续使用需要注意一下
```python
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
This test will initialize the display using displayio and draw a solid green
background, a smaller purple rectangle, and some yellow text.
"""
import board
import busio
import terminalio
import displayio
# Starting in CircuitPython 9.x fourwire will be a seperate internal library
# rather than a component of the displayio library
try:
from fourwire import FourWire
except ImportError:
from displayio import FourWire
from adafruit_display_text import label
from adafruit_st7789 import ST7789
# led = digitalio.DigitalInOut(board.LED)
# led.direction = digitalio.Direction.OUTPUT
# Release any resources currently in use for the displays
displayio.release_displays()
# spi = board.SPI()
spi = busio.SPI(board.D23, MOSI=board.D22, MISO=board.D21)
tft_cs = board.D1
tft_dc = board.D8
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs""", reset=board.D14""")
display = ST7789(display_bus, width=320, height=240, rotation=90)
# Make the display context
splash = displayio.Group()
display.root_group = splash
color_bitmap = displayio.Bitmap(320, 240, 1)
color_palette = displayio.Palette(1)
color_palette = 0x00FF00# Bright Green
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(280, 200, 1)
inner_palette = displayio.Palette(1)
inner_palette = 0xAA0088# Purple
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
splash.append(inner_sprite)
# Draw a label
text_group = displayio.Group(scale=3, x=57, y=120)
text = "Hello World!"
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
text_group.append(text_area)# Subgroup for text scaling
splash.append(text_group)
while True:
pass
```
### 效果展示
## 驱动 SD 卡
DFR0664 板载了 SD 卡槽,和 LCD 共用 SPI 驱动
### 导入 cpy 库
需要从 adafruit-circuitpython-bundle 获取驱动库 `adafruit_sdcard.mpy
`,并导入至板卡的 lib 目录
### 示例代码
挂在 SDCard 到 /sd 目录,遍历打印该目录文件
```python
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
This test will initialize the display using displayio and draw a solid green
background, a smaller purple rectangle, and some yellow text.
"""
import os
import time
import board
import digitalio
import displayio
import busio
import sdcardio
import storage
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
displayio.release_displays()
spi = busio.SPI(board.D23, MOSI=board.D22, MISO=board.D21)
sdcard = sdcardio.SDCard(spi, board.D18)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
def print_directory(path, tabs=0):
for file in os.listdir(path):
stats = os.stat(path + "/" + file)
filesize = stats
isdir = stats & 0x4000
if filesize < 1000:
sizestr = str(filesize) + " by"
elif filesize < 1000000:
sizestr = "%0.1f KB" % (filesize / 1000)
else:
sizestr = "%0.1f MB" % (filesize / 1000000)
prettyprintname = ""
for _ in range(tabs):
prettyprintname += " "
prettyprintname += file
if isdir:
prettyprintname += "/"
print('{0:<40} Size: {1:>10}'.format(prettyprintname, sizestr))
# recursively print directory contents
if isdir:
print_directory(path + "/" + file, tabs + 1)
print("Files on filesystem:")
print("====================")
print_directory("/sd")
while True:
time.sleep(0.5)
led.value = not led.value
```
### 显示效果
运行之后可以直接通过 web workflow 的文件目录访问,非常方便
## sd 卡导入字库和图片显示
### 导入 cpy 库
需要从 adafruit-circuitpython-bundle 获取图片库 `adafruit_imageload`,字体库 `adafruit_bitmap_font`,并导入至板卡的 lib 目录
### 示例代码
从 sd 卡导入字体库和图片,显示
```python
# SPDX-FileCopyrightText: 2024 id.loda
# SPDX-License-Identifier: MIT
import board
import busio
import digitalio
import displayio
import sdcardio
import storage
import terminalio
import time
# Starting in CircuitPython 9.x fourwire will be a seperate internal library
# rather than a component of the displayio library
try:
from fourwire import FourWire
except ImportError:
from displayio import FourWire
from adafruit_display_text import label
from adafruit_st7789 import ST7789
from adafruit_bitmap_font import bitmap_font
import adafruit_imageload
# Release any resources currently in use for the displays
displayio.release_displays()
spi1_bus = busio.SPI(board.D23, MOSI=board.D22, MISO=board.D21)
display_bus = FourWire(spi1_bus, command=board.D8, chip_select=board.D1)
display = ST7789(display_bus, width=320, height=240, rotation=90)
sdcard = sdcardio.SDCard(spi1_bus, board.D18)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
# Make the display context
splash = displayio.Group()
display.root_group = splash
color_bitmap = displayio.Bitmap(320, 240, 1)
color_palette = displayio.Palette(1)
color_palette = 0x000000 # 0xF8F8FF# Ghost White
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
# 180 * 125
with open("/sd/resources/pic/test_image.png", "rb") as f:
blinka_bitmap, blinka_palette = adafruit_imageload.load(f, bitmap=displayio.Bitmap, palette=displayio.Palette)
blinka_sprite = displayio.TileGrid(blinka_bitmap, pixel_shader=blinka_palette, x=140, y=115)
splash.append(blinka_sprite)
# 160 * 56
with open("/sd/resources/pic/ee.bmp", "rb") as f:
eeworld_bitmap, eeworld_palette = adafruit_imageload.load(f, bitmap=displayio.Bitmap, palette=displayio.Palette)
eeworld_sprite = displayio.TileGrid(eeworld_bitmap, pixel_shader=eeworld_palette, x=0, y=20)
splash.append(eeworld_sprite)
# Set text, font, and color
font = bitmap_font.load_font("/sd/resources/font/opposans_m_12.pcf")
# Create the text label
lable_area_fw = label.Label(
font, x=10, y=96, text="FireBeetle 2 ESP32 C6", scale=1, color= 0x191970
)
lable_area_id = label.Label(
font, x=10, y=128, text="ID.LODA", scale=1, color=(0, 191, 255)
)
splash.append(lable_area_fw)
splash.append(lable_area_id)
while True:
time.sleep(0.5)
# led.value = not led.value
```
### 运行效果
# 总结
circuitpython 提供了比较丰富的库,可以方便的绘制转换需要的资源。但是没有继承类似与 emwin、lvgl 等成熟的图形库。
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>应该是可以玩玩从 SD 卡中读取字体库和图片来显示的东西了</p>
<p>楼主分享的技术内容非常详实,开阔了眼界,有机会一定实践下</p>
chejm 发表于 2024-5-24 12:26
楼主分享的技术内容非常详实,开阔了眼界,有机会一定实践下
<p>可以,circuitpython 的库还是比较好上手的</p>
Jacktang 发表于 2024-5-24 07:24
应该是可以玩玩从 SD 卡中读取字体库和图片来显示的东西了
<p>可以玩,circuitpython 的库还是比较完善的,我最后示例就是用的 sd 库的图片和字库,很方便</p>
页:
[1]