preface
In the last video we talked about how to connect a camera, but this time we’re going to learn how to connect a Raspberry PI to a Bluetooth device.
To prepare
- Raspberry pie
zero wh
a - One Bluetooth headset
Bluetooth connection
1. Install the software
sudo apt-get install pulseaudio pulseaudio-module-bluetooth bluez bluez-firmware
Copy the code
PulseAudio is a sound server, a background process that accepts sound input from one or more audio sources (processes or input devices) and then redirects the sound to one or more slots (sound cards, remote network PulseAudio services, or other processes).
apt-get install mplayer
Copy the code
MPlayer is a lightweight player with small software, fast startup, and very little memory and CPU consumption.
2. Add an authentication user
adduser root pulse-access
adduser pi pulse-access
Copy the code
3. Modify the configuration file
a. /etc/dbus-1/system.d/bluetooth.conf
vim /etc/dbus-1/system.d/bluetooth.conf
Copy the code
Add the following before
<policy user="pulse">
<allow send_destination="org.bluez"/>
</policy>
Copy the code
b. /etc/pulse/system.pa
vim /etc/pulse/system.pa
Copy the code
Add the following at the end of the file
### Bluetooth Support
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
load-module module-bluetooth-policy
.endif
Copy the code
c. /etc/pulse/default.pa
vim /etc/pulse/default.pa
Copy the code
Add auth-anonymous=1 to load-module module-native protocol-tcp.
load-module module-native-protocol-tcp auth-anonymous=1
Copy the code
D. Add the pulseAudio-service file
vim /etc/systemd/system/pulseaudio.service
Copy the code
Write the following:
[Unit]
Description=Pulse Audio
[Service]
Type=simple
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1
[Install]
WantedBy=multi-user.target
Copy the code
4. Enable the service
A. Restart the service
systemctl daemon-reload
Copy the code
B. Restart the Bluetooth service
systemctl restart bluetooth.service
Copy the code
C. Start pulseAudio
systemctl start pulseaudio.service
Copy the code
D. Pulseaudio starts automatically upon startup
systemctl enable pulseaudio.service
Systemctl disable pulseAudio. Service
Copy the code
E. Check the bluetooth process status
systemctl status bluetooth.service
Copy the code
5. Connect a Bluetooth headset
Enter the Bluetooth console
sudo bluetoothctl
Copy the code
[bluetooth]$ power on # open
[bluetooth]$ agent on # agent
[bluetooth]$ default-agent # default proxy
[bluetooth]$ scan on # Scan nearby Bluetooth devices
[NEW] Device 70:1C:E7:69:C0:DE huawei
[bluetooth]$ pair 70:1C:E7:69:C0:DE # Pairing (bluetooth address behind)
[bluetooth]$ trust 70:1C:E7:69:C0:DE # Trust bluetooth devices
[bluetooth]$ connect 70:1C:E7:69:C0:DE # Connect a Bluetooth device
[bluetooth]$ scan off # disable scan
[bluetooth]$ exit # exit
[bluetooth]$ power off # Disconnect
Copy the code
6. Mplayer plays music
Play the music
Mplayer is running. Mp3Copy the code
Control sound volume
mplayer -af volume=-10 *.mp3
# Volume can range from -200 to +60, where -200 is silent and +60 is noise
mplayer -softvol -softvol-max 10 *.mp3
Use -softvol first to enable the soft sound card, then use -softvol-max to limit the maximum volume of the soft sound card. Here we're going to set the maximum volume to 10% of the default volume, so it's going to be very quiet.
mplayer -af volume=-10 -softvol -softvol-max 200 *.mp3
# Let's combine the first two methods. We can make the default volume not equal to 100%, and it works on startup.
Copy the code
The raspberry PI system controls sound volume
alsamixer
Copy the code
reference
The PI raspberrypi3 comes with a bluetooth speaker and Mopidy
Mplayer volume control in detail