Control bluetooth devices with the linux terminal on a Raspberry Pi
You want to control bluethooth devices using your Raspberry Pi but do not have access to a graphical user interface.

Desktop environments allow us to connect bluetooth devices with little effort but what if you are running a headless Raspberry Pi? This post lists the commands needed to scan for and connect to bluetooth devices.

Connect to your Pi remotely

If you do not have direct access to the Pi then you can still connect to it using the ssh command1:

ssh pi@1.2.3.4

Note that 1.2.3.4 refers to the local ip address of the Raspberry Pi you want to connect to, change accordingly.

Install the required packages

You will need the command bluetoothctl to make this work. First update the Raspberry Pi:

sudo apt update && sudo apt upgrade

Then install the required packages:

sudo apt install bluetooth pi-bluetooth bluez

It could be that some of these are already available and that only the bluetooth package needs to be installed.

Check the bluetooth service

Make sure that the Raspberry Pi is running the bluetooth service:

sudo systemctl status bluetooth

This should inform you that the service is active (running) in green.

If it is not running then the service needs to be enabled and started:

sudo systemctl enable bluetooth
sudo systemctl start bluetooth

Use the bluetoothctl command

You can now start using bluetoothctl.

To actively search for Bluetooth devices that you can connect to, use the scan command:

bluetoothctl scan on

This will scan for nearby devices. Make sure that the device that you want to connect to is in ‘paring’ mode.

All Bluetooth devices are labeled as Device followed by their respective Media Access Control (MAC) addresses, a unique identifier for a device on a network. The MAC address follows the format XX:XX:XX:XX:XX:XX. Bluetoothctl also displays the name of the device. In my case it found the device that I wanted to connect to:

Device FC:69:47:7C:9D:A3 Rockbox Bold S

Note: If you can’t find the Bluetooth device you are looking for, make sure that it is discoverable.

Now that you have a list of Bluetooth devices you can connect to, use the MAC address to connect to a particular device.

The simplest way to connect with a Bluetooth device is to pair it using the pair command.

bluetoothctl pair FC:69:47:7C:9D:A3

Note: Remember to replace the MAC address FC:69:47:7C:9D:A3 used in this guide with the respective MAC address of your device.

If the device you are connecting to has a GUI interface it might display a prompt asking you to accept the connection. The system may also ask you to confirm the pairing on your Pi. You can do so by typing yes in the command line.

For devices that are already paired with your Pi, you can simply connect to them in the future using the connect command as follows:

bluetoothctl connect FC:69:47:7C:9D:A3

You can then check if it works by downloading a sound and playing it:

wget http://www.freespecialeffects.co.uk/soundfx/sirens/police_s.wav
aplay police_s.wav

If all went well the Pi will play the sound of a police siren.

Bonus: Turn your Pi into a little internet radio

sudo apt install mplayer

Search for the URL2 of your favorite radio station and start chilling out:

mplayer https://mp3channels.webradio.antenne.de/chillout

image info

Header photo by Vietnam Photographer: https://www.pexels.com/photo/black-and-white-marshall-speaker-13981272/


  1. If you are using a Windows computer to connect remotely then you will need to use something like Putty↩︎

  2. This can be tricky but searching for .m3u files should do the job. Such files are basically text files and contain one or more URLs. A starting point may be InternetRadio↩︎


Last modified on 2023-07-01

Comments Disabled.