Technology-树莓派系统安装和蓝牙开发

树莓派系统安装

开启 SSH

1
2
3
4
5
6
7
8
9
10
11
插入SD卡
df -h
diskutil unmount /dev/disk2s1(对应的那个SD卡)
unzip 2019-09-26-raspbian-buster.zip
sudo dd bs=16m if=2019-09-26-raspbian-buster.img of=/dev/rdisk2(注意有个r,字母数字不能搞错)
重新插拔SD卡
在SD卡分区里面创建一个名为 “ssh” 空文件
编辑/boot/config.txt文件
hdmi_safe=1
hdmi_force_hotplug=1
config_hdmi_boost=4

SSH 登录

1
2
3
ssh pi@192.168.1.19
sudo passwd pi
修改密码

安装接口库

1
2
3
4
5
sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools
sudo raspi-config -> Interfacing Options -> I2C -> Enabled -> YES
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple board adafruit-blinka adafruit-circuitpython-ads1x15
supervisord -c /opt/fsr/supervisord.conf

安装和配置蓝牙

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
sudo apt-get remove -y vim-common
sudo apt-get install -y vim
sudo apt-get install -y bluez minicom
sudo apt-get install -y bluez-utils
sudo apt-get install -y pi-bluetooth bluez-firmware blueman
sudo vi /etc/systemd/system/dbus-org.bluez.service
修改
ExecStart=/usr/lib/bluetooth/bluetoothd -C --noplugin=sap
ExecStartPost=/usr/bin/sdptool add SP
保存
sudo vi /etc/dbus-1/system.d/bluetooth.conf
修改
<policy context="default"> <allow send_destination="org.bluez"/>
</policy>
保存
sudo usermod -G bluetooth -a pi
sudo reboot
sudo hciconfig hci0 name "raspberry"
sudo hciconfig hci0 down
sudo hciconfig hci0 up
sudo hciconfig hci0 piscan
sudo sdptool add SP
bluetoothctl discoverable yes
#sudo rfcomm watch hci0
#右上角蓝牙 -> TURN ON -> Make Discoverable

安装辅助库

1
2
3
sudo apt-get install libbluetooth-dev
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pybluez
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pybleno

配置蓝牙

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sudo systemctl status bluetooth
sudo /etc/init.d/bluetooth restart
sudo bluetoothctl
sudo vi /etc/hostname
#修改蓝牙新名称
sudo vi /etc/hosts
#修改127.0.0.1 后面主机名
discoverable yes
scan on
devices
power on
agent on
pair XX:XX:XX:XX:XX:XX
confirm passkey XXX:yes
trust XX:XX:XX:XX:XX:XX
connect XX:XX:XX:XX:XX:XX