Adding a Bluetooth Speaker to Linux

Off the Beat: Bruce Byfield's Blog

Jan 25, 2017 GMT
Bruce Byfield

These days, support for various technologies under Linux can often be taken for granted. An exception is Bluetooth, whose configuration remains arcane, as I found when trying to add a Bluetooth speaker to my workstation. My efforts were dogged by outdated information, and sometimes lack of information, but the audio improvement added by a high-end speaker made the effort more than worth my time.

As you might expect, the best time to add support for any Bluetooth device is during a fresh installation. However, adding Bluetooth after installation is also possible. It consists of four steps: enabling general Bluetooth support, pairing the speaker with the computer, configuring the computer to use the speaker, and automating the re-connection to the speaker when you login. Most of the same steps are also relevant to setting up Bluetooth printers, keyboards, and other devices.

Adding Bluetooth Support
Even if your computer lacks Bluetooth support, adding it is as simple as buying a USB Bluetooth adapter for $15-35. Although few USB adapters will list Linux support, being USB, they should work without any problem.

Once you insert the USB adapter, check that you have all the packages required. On Debian, those packages are bluetooth, pulseaudio, pulseaudio-module-bluetooth, and pavucontrol. Broadcom Bluetooth devices will also need bluez-firmware, which will require the non-free section of your repository. Package names may vary depending on the distribution, but should be close enough to Debian's that you can figure out which the packages you need. Basically, the ones listed here are those that supply basic Bluetooth support and utilities, plus those for enabling sound using pulseaudio.

On a Systemd machine, you can check that Bluetooth is running with the command  systemctl status bluetooth. If it is not, then systemctl start Bluetooth will start it. On a machine using Init, check with /etc/init.d/bluetooth status, and, if necessary, start it with /etc/init.d/bluetooth start. You may need to restart Bluetooth and Pulse Audio first, or reboot.

With Bluetooth support enabled, you are ready to configure. Both GNOME and KDE have Bluetooth configuration tools, and you can add Blueman on other desktops. If you prefer, you can use bluetoothctl interactive from the command line on any desktop. The exact commands depend on which tool you are using, but with a little imagination you can probably figure out which do what.

The first step is to pair the speaker with the computer -- in other words, to link them together. Set the speaker to scan for other Bluetooth. The exact action may vary depending on the speaker; for example, my Ultimate Ears Boom 2 (UE Boom 2) requires that you press the Plus volume button on the side and the Bluetooth button on the top together for three seconds. The Bluetooth button will flash white for about a minute, signalling it is ready to pair.

Now you need to do the same for your machine, making it temporarily visible to other Bluetooth devices, setting it to scan for the speaker, and then pairing it with the speaker. From the bluetoothctl command prompt, these steps mean using list to get the ID for the computer (or Controller, as bluetoothctl calls it) using the list sub-command, and the ID for the speaker (or Device). Set the computer with discoverable on, then connect with the speaker using pair SPEAKER ID.

If necessary,  use the help sub-command to look for other options. The sub-command pair-devices will tell you that the speaker and computer are paired, while trust SPEAKER ID will preserve the pairing between reboots.

Similarly, in KDE's System Setting Bluetooth window, get the computer ID from the Adapter pane, then select Enable KDE Bluetooth integration and Add Device to scan and pair. Select the device in the window, and click Details to check that it is paired, and to make the pairing trusted. Ignore the mis-identification of your speaker as headphones; it will not affect configuration in any way.[]
Note that Bluetooth can be finicky. Whichever interface you use, you may need to try several times before pairing -- and then, for no apparent reason, it might suddenly start working properly. Similarly, while both your computer and speaker may have a human-friendly name, you must use the Mac Address in bluetoothctl.

When you have succeeded in pairing, make your computer invisible, so that you don't leave an open back door in your system for intruders. In bluetoothctl, that means running the sub-command discoverable off. Similarly, in KDE, switch to the Adapter pane and set your computer to Hidden.

Setting sound
The final step is to configure your system to use the speaker. On any desktop, you can use pavucontrol (PulseAudio Volume Control), but on KDE you can also use Phonon. Both pavulcontrol and Phonon work similarly: you need to select the speaker to be used for different purposes. Probably, your existing sound card and on-board sound will be listed.

However, in Phonon in particular, be sure that, when you set the various categories under Audio Playback, such as Notifications, Games, and Video to use the speaker, that you also set the top level in Audio Playback as well. You will know that you have forgotten this step if your web browser lacks sound.

Another hint: maximize pavulcontrol and Phonon when working with them. As the latest added device, your speaker is probably at the bottom of the list of playback devices, and otherwise could be easily missed.

Automatic Setup
At this point, your speaker is functional, but has to be re-connected with each login. Re-connection is a matter of a few clicks, but you can automate with a two line Bash script to send instructions to bluetoothctl:

#echo -e 'connect SPEAKER-ID' | bluetoothctl

Set the script to autostart as you login to your desktop.

However, for some reason, gdm, kdm, and lightspeed all seem to unconnect the speaker as they log you in to the desktop. However, this glitch can be easily overcome by not turning the speaker until about halfway through the login, although I am experimenting with delaying the running of the command to fine-tune the script. In any case, when you turn the speaker on, it automatically re-connects, so the inconvenience is minimal.

In the same way, your speaker may be like mine, and turn off as a power and battery-saving policy after ten minutes or so. For most speakers, there is no way around this feature. But, now that the speaker is configured, re-connection is simple. In KDE, for example, the active Bluetooth utility sits in the Notification Area, allowing you to re-connect in seconds. Personally, I consider this shortcoming minor, considering the quality of sound it allows.

Discovering these procedures was the work of an evening. During those several hours, I kept feeling as though I had time-travelled to the bad old days before the turn of the millennium, when every stage of Linux configuration was a struggle. Once you know the steps, installing other Bluetooth speakers or devices is straightforward, but the struggle is to find current documentation. That is why I have written this set of instructions -- so no one else needs to go through the trials and errors that I did.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More