树莓派
0 ) 起步
以下
vim没有则用vi或者nano代替
- 推荐
64GB 以上的 TF 卡和带开关的电源适配器 - 烧录树莓派,建议选择
Linux,具体推荐:树莓派官方系统
指示灯
树莓派 4B指示灯状态,详情点击- 若无
TF卡,绿灯会每隔几秒闪4下;正常插入卡后,会先闪4下,然后读卡时快速闪动 - 系统异常,绿灯长闪;进入了系统后,绿灯微亮低频闪烁
- 红灯是电源指示灯,长亮正常
- 若无
树莓派 4B之前的型号有所不同,详情点击
开启 SSH 服务
注意:三种方法任选其一,第一种方法进去后建议使用后两种,确保长期开启。
- 将
SD卡插入电脑创建ssh文件(新系统默认关闭ssh),建议同时创建无线配置文件wpa_supplicant.conf开机后,
wpa_supplicant.conf文件会自动转移到/etc/wpa_supplicant目录下;ssh文件会转化为开启ssh服务的指令后被删除。若要更改配置,下次要重新添加文件 - 输入
raspi-config,选择Interfacing Options->SSH,打开SSH模块 - 命令开启
sudo systemctl enable ssh & systemctl start ssh
网络连接
- 网线连接电脑,共享网络(
Windows:控制面板-查看网络状态和任务-属性-共享-全勾-连接以太网),由电脑分配网段 - 网线连接路由器,跟电脑同一网段
- 无线连接,跟电脑同一网段,在根目录创建
wpa_supplicant.confcountry=CN ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="无线网络名称(ssid)" // key_mgmt=WPA-PSK // 非必要,使用 WEP 则为 NONE psk="wifi密码" } arp -a查询树莓派地址,电脑分享网络一般是192.168.137.x
无屏幕连接
远程连接
ssh连接,然后sudo apt-get install xrdp tightvncserver(不起效就先卸载,再重装)- 输入
raspi-config,选择Interfacing Options->VNC,打开虚拟网络控制台(Virtual Network Console)模块 Windows中运行mstsc,输入地址用户连接即可
换源
armv7l,更换软件镜像源/etc/apt/sources.listdeb https://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ bullseye main non-free contrib rpi # deb-src https://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ bullseye main non-free contrib rpi # deb [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/raspbian/multiarch/ bullseye mainaarch64使用Debian软件源,确保安装sudo apt install apt-transport-https ca-certificates后,更换软件镜像源/etc/apt/sources.list# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware # deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware- 更换系统镜像源
/etc/apt/sources.list.d/raspi.listdeb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bookworm main - 更新升级软件
sudo apt update sudo apt dist-upgrade -y - 在
apt 2.1.9及以后的版本中的HTTP Pipelining特性与Nginx服务器疑似存在一定的不兼容问题,可能导致高带宽从镜像站下载大量软件包(例如系统升级)时出现偶发的Connection reset by peer错误(详见 Debian bug #973581)。目前,用户可以通过关闭HTTP Pipelining特性解决此问题。- 使用
apt命令时加上-o Acquire::http::Pipeline-Depth=0参数 - 或使用
echo "Acquire::http::Pipeline-Depth \"0\";" > /etc/apt/apt.conf.d/99nopipelining加入apt系统配置
- 使用
桌面
安装桌面环境 sudo apt-get install raspberrypi-ui-mods,其他桌面
安装 KDE Plasma
sudo apt update && sudo apt full-upgrade -y
sudo apt install tasksel -y
sudo tasksel # 左右选择,空格确定,KDE 桌面安装
sudo apt install lightdm -y # 安装显示管理器
# 别忘了在 raspi-config 中启用桌面
# 查看日志
ls .xorgxrdp.*.log | tail -1 | xargs tail -f
# rdp 服务重启
sudo /etc/init.d/xrdp restart
1 ) 摄像头
推荐
CSI(Camera Serial Interface,摄像头串行接口)摄像头
- 查看设备确认识别
ls -al /dev | grep video,一般CSI 摄像头是vedio0,USB 摄像头是vedio1 - 输入
raspi-config,选择Interfacing Options->Camera,打开相机模块
32 位推荐 MJPG-streamer
- 安装依赖模块
sudo apt install subversion libjpeg62-turbo-dev imagemagick camake git - 克隆源码
sudo git clone https://github.com/jacksonliam/mjpg-streamer.git & cd mjpg-streamer/mjpg-streamer-experimental - 编译
make all & make install - 启动摄像头
USB摄像头./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"CSI摄像头./mjpg_streamer -i "./input_raspicam.so" -o "./output_http.so -w ./www"
- 查看视频流
http://<树莓派 IP>:8080/?action=stream或http://<树莓派 IP>:8080/javascript_simple.html - 查看切片截图
http://<树莓派 IP>:8080/?action=snapshot - 关闭
steamer,sudo killall -TERM mjpg_streamer
64 位推荐 Motion
- 安装
motion,sudo apt install motion -y - (可选)添加开机自启动
sudo vim /etc/rc.local,在exit 0行之前添加一行motion - 修改运行配置,使之后台运行,
sudo vim /etc/default/motion确保start_motion_daemon=yes - 修改并确认
motion以下配置,sudo vim /etc/motion/motion.conf# 是否守护(后台)开启 daemon on # 分辨率 width 800 height 600 # 帧率 framerate 60 # 视频流端口 stream_port 8081 # 视频流码率,新版已经没有 stream_maxrate 60 # 是否只允许本机查看视频流 stream_localhost off # 画面自动调整亮度,0 关闭,1 偏亮,2 偏暗,3 偏亮但增加对比度 #auto_brightness 3 # 增益(Gain)、快门速度(Shutter Speed)、白平衡(White Balance)、动态平衡(Dynamic Range)、帧速率(Frame Rate)、亮度(Brightness)、对比度(Contrast)、饱和度(Saturation)、曝光时间(Exposure Time)、ISO 感光度 #video_params "Gain, Automatic"=1, "White Balance, Automatic"=4, saturation=50, contrast=100, exposure=100 # 0 不启用权限控制,2 表示启用,查看视频监控时需要输入用户名和密码 stream_auth_method 0 stream_authentication username:password # 视频监控总控制页面的端口号 webcontrol_port 8080 # 是否只允许本机查看控制页 webcontrol_localhost off - 启动服务,
sudo systemctl start motion & motion,只修改了配置使用sudo systemctl deamon-reload,重启服务使用sudo systemctl restart motion - 查看监控总页
http://localhost:8080,远程使用http://<树莓派 IP>:8080 - 查看监控页
http://localhost:8081,远程使用http://<树莓派 IP>:8081 - 关闭
motion,sudo killall -TERM motion
设置自启动
motion这种启动语句简短的可直接在/etc/rc.local末的exit 0前添一行motion,而mjpg_streamer这种冗长的建议统一管理。
- 新建自启动管理目录
sudo mkdir ~/.config/autostart - 新建文件
sudo vim ~/.config/autostart/videoStart.shcd ~/mjpg-streamer/mjpg-streamer-experimental/ ./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -p 8080 -w ./www" -d /dev/video0 -f 30 -r 1280x720 - 新建文件
sudo vim ~/.config/autostart/my.desktop[Desktop Entry] Type=shell Exec=~/.config/autostart/videoStart.sh Terminal=false StartupNotify=true