树莓派5适配ST7789屏幕

网上大部分教程不适配的原因

树莓派5用了新的库,不能用Rpi.GPIO,而是使用libgpiod库来操控IO引脚
Python上用的库不变


本章将涉及:GPIO库SPI功能
特别感谢微雪的教程,基本上我成功的案例都是依照上面的:https://www.waveshare.net/wiki/1.3inch_LCD_Module#Python
本教程需要连接github,需要提前准备梯子代理

最近我买了一块ST7789屏幕,来自淘宝锋泰电子科技园,才24块,应该是最便宜的了
而且带编码器旋钮和按键,方便操控
在这里插入图片描述在这里插入图片描述

设备接线图

在这里插入图片描述

操作方法

硬件准备

去系统配置里打开SPI的硬件功能(因为树莓派的硬件功能要单独打开)

sudo raspi-config

选择 Interfacing OptionsSPIYes 启用 SPI。

sudo reboot

然后重启树莓派


进入自己的目录,准备写代码

以下分为 C语言python 两种方法

C语言:

安装驱动库
  • 树莓派5和BCM2835库wiringPi库等原先的GPIO库不兼容
    这两个库直接操作BCM2835芯片寄存器,但树莓派5的 BCM2712芯片架构不同,导致无法获取寄存器地址
    (报错 RuntimeError: Cannot determine SOC peripheral base address)。
  • 官方推荐使用 libgpiod库
    通过Linux内核驱动GPIO,无需直接访问寄存器
lgpio库

在设备上用make编译C语言库

wget https://github.com/joan2937/lg/archive/master.zip
unzip master.zip
cd lg-master
sudo make install 
# 更多的可以参考官网:https://github.com/gpiozero/lg
下载微雪例程
sudo apt-get install unzip -y
sudo wget https://www.waveshare.net/w/upload/8/8d/LCD_Module_RPI_code.zip
sudo unzip ./LCD_Module_RPI_code.zip
cd LCD_Module_RPI_code/RaspberryPi/
编译例程
cd c	#进入C语言例程
sudo make clean
sudo make -j 8
运行程序

根据不同尺寸的屏幕,输入命令:

sudo ./main 0.96 # 0.96寸屏幕
sudo ./main 1.14 # 1.14寸屏幕
sudo ./main 1.28 # 1.28寸屏幕
sudo ./main 1.3  # 1.3寸屏幕
sudo ./main 1.47 # 1.47寸屏幕
sudo ./main 1.54 # 1.54寸屏幕
sudo ./main 1.8  # 1.8寸屏幕
sudo ./main 2    # 2寸屏幕
sudo ./main 2.4  # 2.4寸屏幕

在这里插入图片描述

Python:

安装驱动库

python使用spidev库

sudo apt update
sudo apt install python3-pip
sudo apt install python3-pil
sudo apt install python3-numpy
sudo apt install python3-spidev
下载微雪例程
sudo apt-get install unzip -y
sudo wget https://www.waveshare.net/w/upload/8/8d/LCD_Module_RPI_code.zip
sudo unzip ./LCD_Module_RPI_code.zip
cd LCD_Module_RPI_code/RaspberryPi/
运行程序
cd python/example
ls -l
# 运行不同尺寸的例程
sudo python 0inch96_LCD_test.py # 0.96 寸屏幕
sudo python 1inch14_LCD_test.py # 1.14 寸屏幕
sudo python 1inch28_LCD_test.py # 1.28 寸屏幕
sudo python 1inch3_LCD_test.py  # 1.3 寸屏幕
sudo python 1inch47_LCD_test.py # 1.47 寸屏幕
sudo python 1inch54_LCD_test.py # 1.54 寸屏幕
sudo python 1inch8_LCD_test.py  # 1.8 寸屏幕
sudo python 2inch_LCD_test.py   # 2 寸屏幕
sudo python 2inch4_LCD_test.py  # 2.4 寸屏幕

Python主要用spidev库和gpiozero
spidev库操控SCL时钟脚和SDA数据脚通过SPI协议快速写入图像信息
gpiozero库操控RST(重置),DC(命令/数据模式切换),BL(亮度)引脚
详细参考工程路径下:lg-master/LCD_Module_RPI_code/RaspberryPi/python/lib/lcdconfig.py


如果遇到反色问题
可以参见我另一篇教程:用ST7789屏幕导致负片(反色)的问题
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值