Taha Azzaoui

Pairing bluetooth headphones with bluetoothctl


Alright, bluetooth headphones have always been a pain to setup in Linux. Here are some notes I compiled when I was first setting mine up. I did this on arch (I use arch btw), but the process is probably the same on other distros.

Getting the client

  1. Start by grabbing BlueZ along with its utils

    sudo pacman -S bluez bluez-utils

  2. Next, we’ll need a Bluetooth client. Blueman is pretty minimal and easy to use, so we’ll go with that

    sudo pacman -S blueman

Kernel Support

Make sure the btusb module is loaded

lsmod | grep btusb

Quick side note: the source code for this driver is pretty well commented and worth browsing

Configuring the Client

  1. Start the Bluetooth service

    sudo systemctl start bluetooth.service

  2. Start the client


    You’ll then be greeted with a prompt. We’ll interact with it as follows

    [bluetooth]# power on

    [bluetooth]# agent on

    [bluetooth]# default-agent

    Now we’ll scan for a device. Now’s the time to put the device in pairing mode

    [bluetooth]# scan on

    Output: [NEW] Device 00:18:09:9B:A1:DD MDR-XB650BT

    Now copy the MAC Address of the device and pair with it as follows

    [bluetooth]# pair 00:18:09:9B:A1:DD

    Once we’re paired with the device, we can connect to it like so

    [bluetooth]# connect 00:1D:43:6D:03:26

    Once we’re connected, turn off scanning mode and exit

    [bluetooth]# scan off

    [bluetooth]# exit

Scripting this process

Obviously I’m too lazy to do this manually every time I want to connect to my headphones. Here’s a one-liner that I stuck in my bashrc to do this for me:

echo -e "power on\nagent on\ndefault-agent\nconnect 00:1D:43:6D:03:26" | bluetoothctl

Quick note on sound quality

I ran into some issues with poor sound quality using an old pair of headphones. This turned out to be a problem with high fidelity playback. A quick fix was to simply switch to A2DP

List the audio cards on your system

pacmd list-cards

Make note of the card number of your Bluetooth device and substitute it in the command below to make the switch

pacmd set-card-profile <card #> a2dpsink

Finally, make sure the device is recognized

pacmd set-sink-volume 0 0