3.5inch RPi LCD (G)
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
产品介绍
产品简介
3.5inch RPi LCD (G) 配备320 × 480分辨率的电阻触摸屏,支持顶针通信和 GH1.25 11PIN 连接线两种连接方式,并提供树莓派、ESP32、Pico、Arduino等的示例资料。
产品特性
- 320 × 480 分辨率,262K 彩色,能清晰地显示彩色图片
- 触摸屏透过率高,响应快,寿命长
- 内置 ST7796S 驱动芯片和XPT2046电阻触控芯片,使用SPI接口通信,不占用过多接口引脚资源
- 支持顶针通信和 GH1.25 11PIN 连接线两种连接方式
- 采用黑色沉金工艺,美观耐用
- 提供树莓派、树莓派 Pico、ESP32 以及 Arduino 平台的完整例程和开发资料
接口介绍
产品尺寸
产品参数
参数名称 | 参数 |
供电电压 | 5V |
逻辑电压 | 3.3V |
屏幕类型 | IPS |
通信接口 | SPI |
控制芯片 | Display :ST7796S |
Touch :XPT2046 | |
分辨率 | 320(H) x 480(V) |
显示尺寸 | 49.36 (H) x 73.84 (V) mm |
产品尺寸 | 56.00(H)x 85.00(V) mm |
Raspberrypi使用教程
硬件连接
这款产品支持两种连接方式连接到树莓派使用
方法一:通过顶针连接树莓派
方法二:通过杜邦线连接树莓派
功能引脚 | BCM编码 | Board物理引脚序号 |
TP_IRQ | 17 | 11 |
TP_CS | 7 | 26 |
LCD_BL | 18 | 12 |
LCD_RST | 27 | 13 |
LCD_DC | 22 | 15 |
LCD_CS | 8 | 24 |
SCLK | 11 | 23 |
MOSI | 10 | 19 |
MISO | 9 | 21 |
GND | GND | 6 |
VCC | 5V | 4 |
开启SPI接口
在终端输入以下语句:
sudo raspi-config nonint do_spi 0
Python 环境
- 安装库
sudo apt-get update sudo apt-get install python3-pip sudo apt-get install python3-pil sudo apt-get install python3-numpy sudo apt-get install python3-spidev sudo apt-get pip install smbus2
- 下载运行示例程序
wget https://www.waveshare.net/w/upload/9/9b/3inch5_RPi_LCD_G_RPI.zip unzip 3inch5_RPi_LCD_G_RPI.zip cd 3inch5_RPi_LCD_G_RPI sudo python ./main.py
Bookworm系统桌面显示
安装驱动模块
- 确定当前内核版本
uname -a
此命令将输出完整的内核版本信息。例如,在 Raspberry Pi 5 上执行该命令,可能会得到如下输出:
Linux raspberrypi 6.6.51+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt3 (2024-10-08) aarch64 GNU/Linux
这表明此系统的内核版本号是6.6.51+rpt-rpi-2712,使用的是64位ARM(AArch64)架构。
- 下载安装st7796驱动模块
# 第一步:下载并进入Waveshare-st7796s驱动文件夹 wget https://www.waveshare.net/w/upload/4/49/Waveshare-st7796s.zip unzip Waveshare-st7796s.zip cd Waveshare-st7796s
# 第二步:cd到对应内核版本号文件目录 # 如上面例子则运行下面指令 cd 6.6.51/64/rpi-2712-RPi5
# 复制对应版本的st7796s.ko到当前系统 sudo cp st7796s.ko /lib/modules/$(uname -r)/kernel/drivers
# 确保模块在开机时被加载,将模块名添加到 /etc/modules 文件中: sudo nano /etc/modules
# 在末尾添加 st7796s
sudo depmod -a
- 配置驱动设备树
cd wget https://www.waveshare.net/w/upload/2/2d/Waveshare35g.dtbo sudo cp Waveshare35g.dtbo /boot/overlays/
对于Rpi4 & Rpi5
配置驱动文件
需要先参考此处步骤#安装驱动模块
- 编辑config.txt配置文件
sudo nano /boot/firmware/config.txt
dtparam=i2c_arm=on dtparam=i2c_arm_baudrate=50000 dtparam=spi=on dtoverlay=Waveshare35g,fps=60,speed=48000000,rotate=90,penirq=17 hdmi_force_hotplug=1 max_usb_current=1 hdmi_group=2 hdmi_mode=87 hdmi_cvt 480 320 60 6 0 0 0 hdmi_drive=2
创建屏幕配置文件
创建98-spi-screen.conf文件
sudo nano /etc/X11/xorg.conf.d/98-spi-screen.conf
添加下面参数到98-spi-screen.conf文件内
Section "Device" Identifier "SPI Screen" Driver "fbdev" Option "fbdev" "/dev/fb0" EndSection
注:整个流程操作完成之后。 如果不显示。 修改"/dev/fb0" 为 "/dev/fb1" 之后再重启看看
切换为X11
sudo raspi-config nonint do_wayland W1
校准电阻触摸屏
在终端运行以下语句:
sudo apt-get install xserver-xorg-input-evdev sudo cp -rf /usr/share/X11/xorg.conf.d/10-evdev.conf /usr/share/X11/xorg.conf.d/45-evdev.conf sudo apt-get install xinput-calibrator sudo nano /usr/share/X11/xorg.conf.d/99-calibration.conf
在99-calibration.conf文件中增加以下语句:
Section "InputClass" Identifier "calibration" MatchProduct "ADS7846 Touchscreen" Option "Calibration" "3932 300 294 3801" Option "SwapAxes" "1" Option "EmulateThirdButton" "1" Option "EmulateThirdButtonTimeout" "1000" Option "EmulateThirdButtonMoveThreshold" "300" EndSection
重启后生效
对于所有树莓派版本
此方法必须是基于bookworm-lite版本操作,64位 lite、32位 lite
配置驱动文件
需要先参考此处步骤#安装驱动模块
- 编辑config.txt配置文件
sudo nano /boot/firmware/config.txt
dtparam=i2c_arm=on dtparam=i2c_arm_baudrate=50000 dtparam=spi=on dtoverlay=Waveshare35g,fps=60,speed=48000000,rotate=90,ts_rotate_90 hdmi_force_hotplug=1 max_usb_current=1 hdmi_group=2 hdmi_mode=87 hdmi_cvt 480 320 60 6 0 0 0 hdmi_drive=2
下载必要的软件
- 安装xorg服务
sudo apt-get install --no-install-recommends xserver-xorg -y sudo apt-get install --no-install-recommends xinit -y
- 安装桌面管理器
sudo apt install lightdm -y
- 安装树莓派官方GUI
sudo apt install raspberrypi-ui-mods -y
- 安装git
sudo apt install git -y
- 安装浏览器(可选)
sudo apt install chromium-browser -y
- 安装音乐播放器(可选)
sudo apt install vlc -y
下载运行驱动
打开树莓派终端,执行:
sudo apt install libraspberrypi-dev -y sudo apt-get install unzip -y sudo apt-get install cmake -y sudo wget https://www.waveshare.net/w/upload/6/66/Rpi-fbcp.zip sudo unzip ./Rpi-fbcp.zip cd rpi-fbcp/ sudo rm -rf build sudo mkdir -m 777 ./build cd ./build sudo cmake .. sudo make -j4 sudo install fbcp /usr/local/bin/fbcp
设置自启动startx与fbcp
- 打开Bash shell文件,如果没有则自己创建一个
sudo nano ~/.bashrc
把以下代码加到文件末尾
if [ "$(cat /proc/device-tree/model | cut -d ' ' -f 3)" = "5" ]; then # rpi 5B configuration export FRAMEBUFFER=/dev/fb1 startx 2> /tmp/xorg_errors else # Non-pi5 configuration export FRAMEBUFFER=/dev/fb0 startx 2> /tmp/xorg_errors fi
- 创建并编辑一个自启动fbcp服务文件
sudo nano /etc/systemd/system/fbcp.service
在文件内添加服务配置
[Unit] Description=Framebuffer Copy for Raspberry Pi After=network.target [Service] ExecStartPre=/bin/sleep 20 ExecStart=/usr/local/bin/fbcp Restart=always User=root Group=root [Install] WantedBy=multi-user.target
重新加载 systemd 配置
sudo systemctl daemon-reload
服务启用开机自启动
sudo systemctl enable fbcp.service
测试启动服务
sudo systemctl start fbcp.service
校准电阻触摸屏
在终端运行以下语句:
sudo apt-get install xserver-xorg-input-evdev sudo cp -rf /usr/share/X11/xorg.conf.d/10-evdev.conf /usr/share/X11/xorg.conf.d/45-evdev.conf sudo apt-get install xinput-calibrator sudo nano /usr/share/X11/xorg.conf.d/99-calibration.conf
在99-calibration.conf文件中增加以下语句:
Section "InputClass" Identifier "calibration" MatchProduct "ADS7846 Touchscreen" Option "Calibration" "3932 300 294 3801" Option "SwapAxes" "1" Option "EmulateThirdButton" "1" Option "EmulateThirdButtonTimeout" "1000" Option "EmulateThirdButtonMoveThreshold" "300" EndSection
设置CLI自动登录
sudo raspi-config nonint do_boot_behaviour B2 sudo raspi-config nonint do_wayland W1 sudo reboot
Note1:确保树莓派的用户名为pi否则无法正常自动登录
Note2:设置上述所有配置后,系统每次重启期间都会变久一点,SSH也需要等待一会儿才能进入;
Bullseye系统桌面显示
安装驱动模块
- 确定当前内核版本
uname -a
此命令将输出完整的内核版本信息。例如,在 Raspberry Pi 5 上执行该命令,可能会得到如下输出:
Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux
这表明此系统的内核版本号是6.1.21,使用的是64位ARM(AArch64)架构。
- 下载安装st7796驱动模块
# 第一步:下载并进入Waveshare-st7796s驱动文件夹 wget https://www.waveshare.net/w/upload/4/49/Waveshare-st7796s.zip unzip Waveshare-st7796s.zip cd Waveshare-st7796s
# 第二步:cd到对应内核版本号文件目录 # 如上面例子则运行下面指令 cd 6.1.21/64/
# 复制对应版本的st7796s.ko到当前系统 sudo cp st7796s.ko /lib/modules/$(uname -r)/kernel/drivers
# 确保模块在开机时被加载,将模块名添加到 /etc/modules 文件中: sudo nano /etc/modules
# 在末尾添加 st7796s
sudo depmod -a
- 配置驱动设备树
cd wget https://www.waveshare.net/w/upload/2/2d/Waveshare35g.dtbo sudo cp Waveshare35g.dtbo /boot/overlays/
配置驱动文件
需要先参考此处步骤#安装驱动模块
- 编辑config.txt配置文件
sudo nano /boot/config.txt
dtparam=i2c_arm=on dtparam=i2c_arm_baudrate=50000 dtparam=spi=on dtoverlay=Waveshare35g,fps=60,speed=48000000,rotate=90,penirq=17 hdmi_force_hotplug=1 max_usb_current=1 hdmi_group=2 hdmi_mode=87 hdmi_cvt 480 320 60 6 0 0 0 hdmi_drive=2
下载运行驱动
打开树莓派终端,执行:
sudo apt install libraspberrypi-dev -y sudo apt-get install unzip -y sudo apt-get install cmake -y sudo wget https://www.waveshare.net/w/upload/6/66/Rpi-fbcp.zip sudo unzip ./Rpi-fbcp.zip cd rpi-fbcp/ sudo rm -rf build sudo mkdir -m 777 ./build cd ./build sudo cmake .. sudo make -j4 sudo install fbcp /usr/local/bin/fbcp
设置自启动fbcp
- 打开rc.local文件
sudo nano /etc/rc.local
把以下代码加到exit 0前,注意一定要添加"&" 后台运行,否则可能会出现系统不能启动的情况。
sleep 20 fbcp &
校准电阻触摸屏
在终端运行以下语句:
sudo apt-get install xserver-xorg-input-evdev sudo cp -rf /usr/share/X11/xorg.conf.d/10-evdev.conf /usr/share/X11/xorg.conf.d/45-evdev.conf sudo apt-get install xinput-calibrator sudo nano /usr/share/X11/xorg.conf.d/99-calibration.conf
在99-calibration.conf文件中增加以下语句:
Section "InputClass" Identifier "calibration" MatchProduct "ADS7846 Touchscreen" Option "Calibration" "3932 300 294 3801" Option "SwapAxes" "1" Option "EmulateThirdButton" "1" Option "EmulateThirdButtonTimeout" "1000" Option "EmulateThirdButtonMoveThreshold" "300" EndSection
重启生效
资料
原理图
程序
数据手册
软件
FAQ
售后
联系人:吴工
EMAIL:3005496359@qq.com
电话:0755-83043099
QQ:3005496359
微信:扫下方二维码添加