Raspberry Pi 4开发环境搭建

本文介绍Raspberry Pi 4开发环境搭建。

1.软件工具

1)镜像下载

下载地址:

Operating system images – Raspberry Pi

我的树莓派是4B,这里下载的Raspberry Pi OS (64-bit),Release date: May 3rd 2023版本的。

2)烧录软件下载

烧录软件可以使用官方的下载工具Raspberry Pi Imager,下载地址:

Raspberry Pi OS – Raspberry Pi

当然,也可以用Win32DiskImager(Windows环境下),Etcher软件,我这里用的是Etcher。接下来就是使用烧录软件将镜像文件烧录到SD卡,比较简单,这里就不介绍了。

2.软件源修改

官方的软件源下载比较慢,这里修改为国内镜像源,以阿里镜像源为例:

sudo nano /etc/apt/sources.list

注释掉原来的源,添加:

deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
sudo nano /etc/apt/sources.list.d/raspi.list

注释掉原来的源,添加:

deb http://mirrors.aliyun.com/raspberrypi/ buster main ui

3.Qt软件安装

项目中要用到Qt,这里采用直接在树莓派上开发的方法,需要在树莓派上搭建Qt开发环境。

sudo apt-get update
sudo apt install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools
sudo apt-get install qtcreator
sudo apt-get install qtdeclarative5-dev qtmultimedia5-dev libqt5multimedia5-plugins libqt5serialport5-dev libgles2-mesa-dev libqt5sql5-mysql

安装完Qt后,正常来说,Qt Creator自动识别工具链,是可以正常编译的,但是,我的提示没有安装clang(其实已经安装),设置环境变量:

sudo nano /etc/profile

末尾添加:

export PATH=/usr/lib/llvm-11/bin:$PATH

就可以正常编译了。

4.禁用开机LOGO

sudo nano /boot/cmdline.txt

将splash修改为:logo.nologo

5.GUI应用程序自启动

cd ~/.config
mkdir autostart
nano autostart.desktop

增加:

#file start

[Desktop Entry]

Type=Application

Exec=your application absolute path

#file end

your application absolute path替换成你的GUI应用程序所在位置即可。

4.烧录

程序部署到目标机上后,需要量产,这时候就需要提取目标机镜像,再烧录到其他空白SD卡上。

1)提取

将SD卡插入读卡器,在主机(Ubuntu 18.04)上运行指令:

sudo dd if=/dev/<sdx> of=/<path>/<file_name.img> status=progress

2)瘦身

备份的镜像文件大小和SD卡容量一样的,考虑到不同SD卡容量有差异,且文件太大,效率比较低,可以给镜像文件瘦身。这里采用国外别人写的脚本(pishrink.sh)。

sudo <path>/PiShrink-master/pishrink.sh -Z <path>/<file_name.img> <path>/<file_name_reduce_size.img>

接下来,就可以拿“file_name_reduce_size.img”去烧录其他SD卡了。

总结,本文介绍了Raspberry Pi 4开发环境搭建及相关软件的安装。

猜你喜欢

转载自blog.csdn.net/propor/article/details/132323428