1. 背景
项目中使用树莓派 3B+ 外加 zigbee 芯片实现设备与设备之间的通信,但是最初使用的时候,树莓派的串口总显示通信异常。
2. 原因
树莓派3的蓝牙与串口是冲突的,只能二选一,系统默认选择的蓝牙,现在需要关闭蓝牙
3. 解决方法
参考:树莓派3 UART(串口)不可用的解决方法 https://www.jianshu.com/p/b828214c6573
4. 后将解决方法及项目所需环境设置写成 BASH 脚本,有需要自取
#! /bin/bash myFile = "/etc/apt/sources.list.backup" if [ ! -f "$myFile" ]; then cp /etc/apt/sources.list /etc/apt/sources.list.backup echo deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib > /etc/apt/sources.list echo deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib >> /etc/apt/sources.list fi myFile = "/etc/apt/sources.list.d/raspi.list.backup" if [ ! -f "$myFile" ]; then cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.backup echo deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui > /etc/apt/sources.list.d/raspi.list fi apt update apt upgrade -y # # 安装必须工具 #apt-get install redis-server -y apt-get install supervisor -y apt-get install python3-dev python3-pip -y apt-get install git -y apt-get install vim -y apt-get install sqlite3 -y apt-get install screen -y apt-get install python3-venv -y apt-get install demjson -y apt-get install hbmqtt -y apt-get install pyserial-asyncio==0.4 -y apt-get install aio-pika -y # # 禁用蓝牙服务 systemctl disable hciuart myFile="/boot/config.txt.backup" if [ ! -f "$myFile" ]; then cp /boot/config.txt /boot/config.txt.backup echo -e >> /boot/config.txt echo -e >> /boot/config.txt echo dtoverlay=pi3-disable-bt >> /boot/config.txt fi # 加载看门狗 myFile="/boot/config.txt.backup" if [ ! -f "$myFile" ]; then cp /boot/config.txt /boot/config.txt.backup echo -e >> /boot/config.txt echo -e >> /boot/config.txt echo dtparam=watchdog=on >> /boot/config.txt fi apt-get install watchdog -y # 修改配置 myFile="/etc/watchdog.conf.backup" if [ ! -f "$myFile" ]; then cp /etc/watchdog.conf /etc/watchdog.conf.backup echo -e >> /etc/watchdog.conf echo -e >> /etc/watchdog.conf echo watchdog-device = /dev/watchdog >> /etc/watchdog.conf echo max-load-1 = 24 >> /etc/watchdog.conf echo temperature-sensor = /sys/class/thermal/thermal_zone0/temp >> /etc/watchdog.conf echo max-temperature = 75000 >> /etc/watchdog.conf fi update-rc.d watchdog defaults /etc/init.d/watchdog start # 解除端口占用 myFile="/boot/cmdline.txt.backup" if [ ! -f "$myFile" ]; then cp /boot/cmdline.txt /boot/cmdline.txt.backup echo console=serial1,115200 console=tty1 root=PARTUUID=738a4d67-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait > /boot/cmdline.txt fi cp supervisor/ngrok.conf /etc/supervisor/conf.d/ngrok.conf