Raspberry pi bluetooth speaker
This project shows how to connect a Bluetooth speaker to your Raspberry Pi or Pi 400 and offers troubleshooting advice.
Getting Bluetooth speakers to connect and play nicely with Raspberry Pi has not been without its problems in the past with some speakers. Fortunately in December 2020 the Raspberry Pi OS received an important update to smooth the experience with Audio and Bluetooth.
This project will show you how to take advantage of the new features and successfully connect your speakers. If you still have problems, there is advice on troubleshooting.
A UE Boom2 speaker was used in the example but any Bluetooth speaker that conforms to the Advanced Audio Distribution Profile (A2DP) profile should work.
1. Get your Pi ready
The procedure to connect Bluetooth speakers is different for Raspberry Pi OS Desktop (Full) version and Lite versions.
Since the December 2020 update, Raspberry Pi OS now defaults to using PulseAudio as its audio server. This improves audio management and makes connecting Bluetooth speakers more reliable.
Open a Terminal window and enter the following commands.
sudo apt update sudo apt full-upgrade
sudo apt install pulseaudio-module-bluetooth
sudo usermod -a -G bluetooth pi
After restart, your system will be ready to connect to Bluetooth audio.
2. Desktop connection
This section applies only to Desktop users.
- Turn on your Bluetooth speaker and put into pairing mode. On the UE Boom there’s a small button that needs to be held down for 6 seconds. Check your speaker’s manual to find out how to do this.
- Left-click the Bluetooth icon in the top right of the screen and select Add Device.
- Right-click the Speaker icon in the top right of the screen.
- Select Audio Outputs and your speaker should be listed.
- Select the Speaker and wait for the device to connect.
Your device should be connected and any audio will now be routed to it.
3. Lite connection
- Turn your speaker on and put it into pairing mode.
- Open Terminal or an SSH session and issue the following command to start PulseAudio:
systemctl --user start pulseaudio
If bluetoothctl will not start up check your user has been added to the Bluetooth group – see step 1.
Your Bluetooth speaker should be listed with its 48-bit MAC address.
- Pair and trust the speaker. Type the first few characters of the address and use Tab to complete it.
pair XX:XX:XX:XX:XX:XX trust XX:XX:XX:XX:XX:XX
After a few seconds your speaker should connect and any audio will now be routed to that device.
4. Testing
You can test the speaker by playing a 16 bit Wav format file. These can be found online by performing a search in your favourite search engine.
You should hear the audio file being played from your speaker!
5. Troubleshooting
If your speaker is still silent, make sure the volume is turned up, go back to Terminal and start bluetoothctl.
This will list out all the information about your speaker. The screen below shows that the UE Boom is paired, trusted and connected. If any of these indicate “no” then issue the command again and look for any errors.
If you still have problems then deleting PulseAudio’s temporary directories in Terminal can help:
sudo rm -Rf .config/pulse /tmp/pulse-*
Followed by restarting PulseAudio:
systemctl --user restart pulseaudio
Summary
In the past Bluetooth speakers have been difficult to connect to Raspberry Pi but the addition of PulseAudio as the audio server has improved the situation. Hopefully you have been able to follow this guide and successfully connect your Bluetooth speaker.
There are some applications and games that still don’t work with Bluetooth speakers because they directly access the sound system, notably SonicPi.
Like what you read? Why not show your appreciation by giving some love.
From a quick tap to smashing that love button and show how much you enjoyed this project.