Please select an option to see content specific to your location and shop online.

Project

Set up a Bluetooth Speaker with a Raspberry Pi

For the December 2020 release of Pi OS

Scroll down

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.

  • Update the operating system.
sudo apt update

sudo apt full-upgrade
  • Remove any previous Alsa Bluetooth profile loader.
sudo apt purge bluealsa
  • Install PulseAudio Bluetooth profile loader.
sudo apt install pulseaudio-module-bluetooth
  • For Lite users, add pi user to bluetooth group.
sudo usermod -a -G bluetooth pi
  • Reboot.

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.

Bluetooth menu

  • Select your speaker from the Devices dialogue

bluetooth device

  • Click Pair and wait for pairing to complete.
  • Click OK.

bluetooth pair-success

  • 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.

audio output

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
  • Now start the bluetoothctl interface which has its own special prompt:
bluetoothctl

bluetoothctl

If bluetoothctl will not start up check your user has been added to the Bluetooth group – see step 1.

  • Start a scan with the command:
scan on

Your Bluetooth speaker should be listed with its 48-bit MAC address.

  • Turn scanning off once the speaker is discovered:
scan off

  • 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

 

  • Now connect to the speaker:
connect 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.

  • Open Terminal and change directory to where the sound file is located (Music in our case):
cd Music
  • Use the built-in command-line audio player:
paplay <wav filename>

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.

bluetoothctl
  • Then enter the following command:
info XX:XX:XX:XX:XX:XX

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.

Raspberry Pi OS update information https://www.raspberrypi.org/blog/new-raspberry-pi-os-release-december-2020/

 

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.