Skip to content

Instantly share code, notes, and snippets.

@JdaieLin
Last active March 6, 2021 19:42
Show Gist options
  • Save JdaieLin/9c38e0cc4c57247db505d8577d1bda79 to your computer and use it in GitHub Desktop.
Save JdaieLin/9c38e0cc4c57247db505d8577d1bda79 to your computer and use it in GitHub Desktop.
Install waveshare 1.3 LCD HAT on Raspbian

在树莓派上点亮微雪1.3寸LCD HAT所需的安装步骤,重新梳理了一下安装顺序。

使用最新Raspbian镜像,联网进行安装。

安装 WiringPi

cd ~
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build

检查是否安装成功

gpio -v

安装bcm2835函数库

cd ~
wget http://www.waveshare.net/w/upload/d/d8/Bcm2835-1.45.tar.gz
tar zvxf Bcm2835-1.45.tar.gz
cd bcm2835-1.45
./configure
make
sudo make check
sudo make install

安装python相关函数库

sudo apt-get update
sudo apt-get install python-dev
sudo apt-get install python-smbus
sudo apt-get install python-serial
pip install RPi.GPIO
pip install spidev
pip install python-imaging

添加模块到/etc/modules

sudo nano /etc/modules
# append following two lines to the end
# 将以下两行添加至文件结尾
i2c-bcm2708
i2c-dev

修改系统配置

sudo raspi-config
# Enter Interfacing Options, turn on SPI, I2C, Serial
# 进入Interfacing Options,开启SPI, I2C, Serial

获取demo程序

cd ~
wget http://www.waveshare.net/w/upload/c/c9/1.3inch_LCD_HAT.tar.gz
tar zxvf 1.3inch_LCD_HAT.tar.gz

运行demo程序(bcm2835,可测试按键是否可用)

cd ~
cd 1.3inch_LCD_HAT/bcm2835/
sudo ./lcd_1in3 

安装到这里已经可以正常使用屏幕

若希望用1.3寸屏幕来显示桌面的话,还需要以下配置步骤:

启用fbtft模块

sudo nano /etc/modules
## 在启动模块中添加:
## 注意:如果加了这三个模块,启动后屏幕会被Framebuffer接管。若之后想运行前面的demo或者其他屏幕程序,需要注释这几个模块,重启树莓派之后才能正常运行
spi-bcm2835
flexfb
fbtft_device

配置fbtft

## 新建fbtft配置文件
sudo nano /etc/modprobe.d/fbtft.conf

## 复制以下内容到文件中(注意这里是两行options开头)
options fbtft_device name=flexfb gpios=reset:27,dc:25,cs:8,led:24 speed=40000000 bgr=1 fps=60 custom=1 height=240 width=240
options flexfb setaddrwin=0 width=240 height=240 init=-1,0x11,-2,120,-1,0x36,0x70,-1,0x3A,0x05,-1,0xB2,0x0C,0x0C,0x00,0x33,0x33,-1,0xB7,0x35,-1,0xBB,0x1A,-1,0xC0,0x2C,-1,0xC2,0x01,-1,0xC3,0x0B,-1,0xC4,0x20,-1,0xC6,0x0F,-1,0xD0,0xA4,0xA1,-1,0x21,-1,0xE0,0x00,0x19,0x1E,0x0A,0x09,0x15,0x3D,0x44,0x51,0x12,0x03,0x00,0x3F,0x3F,-1,0xE1,0x00,0x18,0x1E,0x0A,0x09,0x25,0x3F,0x43,0x52,0x33,0x03,0x00,0x3F,0x3F,-1,0x29,-3

## 退出文件编辑,重启树莓派
sudo reboot

## 重启后查看fbtft是否启动,看看设备列表中是否有fb1,有的话则启动成功
ls /dev

将fb0的内容复制到fb1上

## 安装编译工具软件
sudo apt-get install cmake git

## 安装fbcp
cd ~
git clone https://github.com/tasanakorn/rpi-fbcp
cd rpi-fbcp/
mkdir build
cd build/
cmake ..
make
sudo install fbcp /usr/local/bin/fbcp

## 设置开机启动
sudo nano /etc/rc.local

## 在exit 0之前添加一行:(注意结尾要加&)
fbcp&

## 更改桌面尺寸
sudo nano /boot/config.txt

## 在文件末尾添加:(display_rotate可自行更改控制显示方向)
hdmi_force_hotplug=1
hdmi_cvt=300 300 60 1 0 0 0
hdmi_group=2
hdmi_mode=1
hdmi_mode=87
display_rotate=1

## 注意此处修改了hdmi的输出格式,会造成树莓派hdmi无法正常输出至外接显示器。想要正常显示需要恢复/boot/config.txt文件。

## 重启后就可以看到微型的迷你桌面
## 如果需要使用其他程序控制屏幕,可回到/etc/modules文件,删除模块后重启。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment