Fixed: Connect Bluetooth Headphones with your Raspberry PI
Last Updated on
For a while I has been struggling in getting my Raspberry Pi connected to bluetooth headphones. This was with the idea to use in future projects available home assistants (like Google Assistant or Amazon Alexa) via bluetooth headphone on a Raspberry PI OS Lite installation.
My tests have been frustrated by common issues not well documented in the web. So I started to follow many guides untill I reached a configuration that simply works. Main issues has been related to Bluetooth service errors on startup and connection breaking.
Solution came out with fixes from different online articles, being partcularly important the tricks from https://www.sigmdel.ca/michel/ha/rpi/bluetooth_n_buster_01_en.html and http://youness.net/raspberry-pi/bluetooth-headset-raspberry-pi.
According to youness.net article, with the time there has been some changes in managing audio connection with Bluetooth. Raspberry PI OS uses BlueZ as Bluetooth stack:
- BlueZ deals with pure Bluetooth tasks (pairing/connection/…)
- So, BlueZ needs additional SW components for audio management
- First Linux audio manager that comes to mind is ALSA
- But, BlueZ (>= v5.0) doesn’t support ALSA anymore
- Instead, BlueZ is now using PulseAudio (>= 5.0)
- And, PulseAudio still uses ALSA
So, the chain changes should be the following:
Before: BlueZ → ALSA
Now: BlueZ → PulseAudio → ALSA
The following guide will help you to correctly connect bluetooth headphones with your Raspberry PI (any model with integrated bluetooth module).
What We Need
I suggest adding to your shopping chart all needed hardware, so that at the end you will be able to evaluate overall costs and decide if continuing with the project or removing them from shopping chart. So, hardware will be only:
- Raspberry PI with its power supply
- a micro SD card
- Bluetooth Headphones (I used a very old model, so it should work with newer ones)
Check hardware prices with following links:
Step-By-Step Guide
Install OS
We’ll start from standard Raspberry PI OS Lite installation with WiFi and ssh enables. So every command within the following paragraphs will be issued via ssh remote connection.
Be sure to have your OS up to date:
sudo apt-get update sudo apt-get upgrade
Adding Pi To Bluetooth Users
This fix helps to use audio files from default pi user, without having to elevate privileges for each bluetooth action. Simply use the following command to add pi user to bluetooth group:
sudo usermod -G bluetooth -a pi
Now logout/login or reboot to have this change running:
sudo reboot now
Install Bluealsa and Pulseaudio Module
This module will be useful later to interface
sudo apt-get install bluealsa pulseaudio
SAP Driver Initialization Failure
The first issue comes from SAP (SIM Access Profile) driver initialization. If you check bluetooth service starting status:
sudo systemctl status bluetooth.service
you should find the following:
● bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2020-01-06 21:15:56 GMT; 2min 57s ago Docs: man:bluetoothd(8) Main PID: 424 (bluetoothd) Status: "Running" Tasks: 1 (limit: 2200) Memory: 2.7M CGroup: /system.slice/bluetooth.service └─424 /usr/lib/bluetooth/bluetoothd Jan 06 21:15:56 raspberrypi systemd[1]: Starting Bluetooth service... Jan 06 21:15:56 raspberrypi bluetoothd[424]: Bluetooth daemon 5.50 Jan 06 21:15:56 raspberrypi systemd[1]: Started Bluetooth service. Jan 06 21:15:57 raspberrypi bluetoothd[424]: Starting SDP server Jan 06 21:15:57 raspberrypi bluetoothd[424]: Bluetooth management interface 1.14 initialized Jan 06 21:15:57 raspberrypi bluetoothd[424]: Sap driver initialization failed. Jan 06 21:15:57 raspberrypi bluetoothd[424]: sap-server: Operation not permitted (1) Jan 06 21:15:57 raspberrypi bluetoothd[424]: Failed to set privacy: Rejected (0x0b)
The “Sap driver initialization failed.” notices that someting is going wrong on startup. This can be fixed simply stopping the SIM profile loading. Edit “/lib/systemd/system/bluetooth.service” file to add “–noplugin=sap” option near “ExecStart=/usr/lib/bluetooth/bluetoothd” configuration:
sudo nano /lib/systemd/system/bluetooth.service
and make sure that your appear like the following (just adding –noplugin=sap as mentioned above):
[Unit] Description=Bluetooth service Documentation=man:bluetoothd(8) ConditionPathIsDirectory=/sys/class/bluetooth [Service] Type=dbus BusName=org.bluez ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=sap NotifyAccess=main #WatchdogSec=10 #Restart=on-failure CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE LimitNPROC=1 ProtectHome=true ProtectSystem=full [Install] WantedBy=bluetooth.target Alias=dbus-org.bluez.service
Now reboot
sudo reboot now
Privacy Setting Rejected Failure
Once rebooted, a new check on bluetooth service status shows that the third error is still occurring. Command:
sudo systemctl status bluetooth.service
should give you:
● bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2020-01-06 21:38:05 GMT; 3min 9s ago Docs: man:bluetoothd(8) Main PID: 424 (bluetoothd) Status: "Running" Tasks: 1 (limit: 2200) Memory: 2.7M CGroup: /system.slice/bluetooth.service └─424 /usr/lib/bluetooth/bluetoothd --noplugin=sap Jan 06 21:38:04 raspberrypi systemd[1]: Starting Bluetooth service... Jan 06 21:38:05 raspberrypi bluetoothd[424]: Bluetooth daemon 5.50 Jan 06 21:38:05 raspberrypi systemd[1]: Started Bluetooth service. Jan 06 21:38:05 raspberrypi bluetoothd[424]: Starting SDP server Jan 06 21:38:05 raspberrypi bluetoothd[424]: Excluding (cli) sap Jan 06 21:38:05 raspberrypi bluetoothd[424]: Bluetooth management interface 1.14 initialized Jan 06 21:38:05 raspberrypi bluetoothd[424]: Endpoint registered: sender=:1.6 path=/org/bluez/hci0/A2DP/SBC/Source/1 Jan 06 21:38:05 raspberrypi bluetoothd[424]: Endpoint registered: sender=:1.6 path=/org/bluez/hci0/A2DP/SBC/Source/2 Jan 06 21:38:05 raspberrypi bluetoothd[424]: Failed to set privacy: Rejected (0x0b)
A simple restart of bluetooth service solves this problem, but solution is only temporary untill a new reboot comes. The solution for this is editing “/lib/systemd/system/bthelper@.service” file to add the “ExecStartPre=/bin/sleep 2” configuration. For this solution credits go to Ben Windsow on https://github.com/RPi-Distro/pi-bluetooth/issues/8#issuecomment-480270680. So open the above file:
sudo nano /lib/systemd/system/bthelper@.service
and make it the same as the following:
[Unit] Description=Raspberry Pi bluetooth helper Requires=bluetooth.service After=bluetooth.service [Service] Type=simple ExecStartPre=/bin/sleep 2 ExecStart=/usr/bin/bthelper %I
Reboot again and now everything should be ok with sudo systemctl status bluetooth.service.
Check That Pulseaudio Is Running
One of most common issues is that when attempting to connect bluetooth headphones Pulseaudio is not running. So, before proceding to bluetooth pairing, please check that it is running.
Type the following command:
ps aux | grep pulseaudio
If this command returns the following output:
pi@raspberrypi:~ $ ps aux | grep pulseaudio pi 538 0.0 0.0 7348 504 pts/0 S+ 22:01 0:00 grep --color=auto pulseaudio
then you must manually launch pulseaudio:
pulseaudio --start
so that you should see the correct status from ps aux | grep pulseaudio command:
pi@raspberrypi:~ $ ps aux | grep pulseaudio pi 544 4.3 1.8 181592 17720 ? Sl 22:02 0:00 pulseaudio --start pi 564 0.0 0.0 7348 488 pts/0 S+ 22:02 0:00 grep --color=auto pulseaudio
Pair Bluetooth Device
Finally, we can try that everything really works. Let’s configure bluetooth (note that I don’t use sudo because pi has been added to bluetooth group). First of all, consider that my headphones address is 00:25:DB:78:86:98, but in your case will depend on your hardware.
Set in pairing mode your bluetooth headphones according to their user guide. Go to the terminal.
Command:
bluetoothctl
Expected output:
pi@raspberrypi:~ $ bluetoothctl Agent registered [bluetooth]#
Command:
power on
Expected output:
[bluetooth]# power on Changing power on succeeded
Command:
agent on
Expected output:
[bluetooth]# agent on Agent is already registered
Command:
default-agent
Expected output:
[bluetooth]# default-agent Default agent request successful
Command:
scan on
Expected output:
[bluetooth]# scan on Discovery started [CHG] Controller B8:27:EB:23:73:DF Discovering: yes [NEW] Device 00:25:DB:78:86:98 BTC7
First row is RPI on board Controller. My headphones are these listed in second row.
Command (remember to change my Headphones addres with your one from following command to the end!!!):
pair 00:25:DB:78:86:98
Expected output:
[bluetooth]# pair 00:25:DB:78:86:98 Attempting to pair with 00:25:DB:78:86:98 [CHG] Device 00:25:DB:78:86:98 Connected: yes [CHG] Device 00:25:DB:78:86:98 UUIDs: 00001108-0000-1000-8000-00805f9b34fb [CHG] Device 00:25:DB:78:86:98 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb [CHG] Device 00:25:DB:78:86:98 ServicesResolved: yes [CHG] Device 00:25:DB:78:86:98 Paired: yes Pairing successful [CHG] Device 00:25:DB:78:86:98 ServicesResolved: no [CHG] Device 00:25:DB:78:86:98 Connected: no
Command:
trust 00:25:DB:78:86:98
Expected output:
[bluetooth]# trust 00:25:DB:78:86:98 [CHG] Device 00:25:DB:78:86:98 Trusted: yes Changing 00:25:DB:78:86:98 trust succeeded
Command:
connect 00:25:DB:78:86:98
Expected output:
[bluetooth]# connect 00:25:DB:78:86:98 Attempting to connect to 00:25:DB:78:86:98 [CHG] Device 00:25:DB:78:86:98 Connected: yes Connection successful [CHG] Device 00:25:DB:78:86:98 ServicesResolved: yes
Now you Bluetooth headphones are connected!
Test Your Headphones
From terminal, play audio example files (remember to use your headphones address intead of mine!):
aplay -D bluealsa:DEV=00:25:DB:78:86:98,PROFILE=sco /usr/share/sounds/alsa/Front_Center.wav
You can also record your own test:
arecord -D bluealsa:DEV=00:25:DB:78:86:98,PROFILE=sco test.wav
and listen it
aplay -D bluealsa:DEV=00:25:DB:78:86:98,PROFILE=sco test.wav
to check both audio transmission and reception.
Now you should be able to correctly connect your bluetooth headphones with your Raspberry PI.
Enjoy!




don’t think you need pulseaudio here
bluealsa is able to connect without pulse.
Also both working together is not recommended
I ran through these instructions and at the end i get no sound.
Not sure what to do at this point.
Hi Douglas.
Bluetooth is really hard to work in Raspbian Lite and results can change from device to device. I’m going to write you to try more help in troubleshooting.
I have never been able to get sound out of 2 different RPi 3s via BT now and have tried everything I can find online for the last two years now.
I am beginning to disbelieve it works for anybody.
Multiple different speakers always pair, and then connect, and are able to be seen from the pi but no sound ever comes out of the speakers.
There must be another mixer setting, or switch to enable BT output.
….Larry
Hi Larry,
thank you for your feedback. With my CellularLine bluetooth headset I also had to work hard to make it working. Some keys which gave me results:
– check pulseaudio is working: even if installed, pulseaudio could be not running. Once started, verify that its process is alive
– bluetooth pairing seems to be working easily in Rasbpian Lite. But check – when you connect a device – that it remains connected
– aplay worked to me with sco profile and a wav file previously recorded with same library and “arecord” command. so try this way first. If your device is an “output only” one, try downloading a wav file or let me know to generate one and make it available to you in my download area
A different solution is listed in Gus comment. You can also try this one.
If you have still problems, feel free to mail me (my contacts are in my Info page)
Thanks for your reply.
I did some noise out of the speaker using the PROFILE=A2DP in the aplay command line. The .wav file sounded like it was playing at about 1/10 speed, and the .mp3 file did output some random noise. This indicates most things are working, so far.
Every other attempt no sound will come out of the speaker. Today I have rechecked pulseaudio is running but still no sound. Using A2DP or SCO I get silence until after about 45 seconds I get aplay kicking back with
aplay: main:828: audio open error: no such device
The speaker still hasn’t reported “disconnecting Bluetooth” at that point so the connection is still valid from the speaker’s point of view. Pulseaudio is still showing running in the ps list.
This is the same results I got many times with the Alexa speaker also. They pair, connect and everything seems OK but will never produce sound.
I wrote some pythin3 code to open a socket via BT and the speaker reports paired, and connected. Same thing with it. After trying many methods with Alexa and GH “right out of the book”, I assumed those brands would not allow other brands to interoperate with them.
This tiny speaker I am using now connects and plays music from my Samsung S7, and my laptop, just fine. Something is missing on these RPi methods yet. Maybe I need to connect up a monitor and KB for a RPi desktop trial to prove it isn’t just a Raspbian command line thing
**SIGH**
If you are receiving some sound (even if a simple noise), this is a good signal: this means that bluetooth is paired and connected. This also could mean that in this moment you could have a simple coding problem. So, your next test it the one you are going to do: try with a deskop version able to let you have also more advanced music applications (like the famous vlc player) which are more likely to have a complete library for media decoding.
Another trik: in terminal, you should be able to use “alsamixer” command, which enables a terminal console to manage volume for your audio devices.
Thanks. The alsamixer only shows analogue devices, namely just one.
The noise indicates the volume is loud enough. I’ll have to make a bench setup to get a monitor and kb on this Rpi. I would even be happy just to use a simple earphone jack speaker for this application but having trouble finding one of them too. They have incorporated video into the same jack making it non-standard.
With xrdp you can control your Raspbian Desktop from Windows Remote Desktop, installing it in headless mode (without monitor and keyboard). Please try this guide: https://peppe8o.com/install-raspbian-buster-desktop-in-your-raspberry-pi-with-optional-remote-desktop/
Awesome post thank you. I followed it and I have a few suggestions for improvements after having tried (and retried on a brand new SD card) the steps myself:
1- I started with a fresh Pi Zero W, with a brand new Raspbian Lite (buster) installation
2- I didn’t have to install PulseAudio. BlueAlsa alone worked. I skipped the section “Check That Pulseaudio Is Running” altogether
3- For convenience, I created a file .asoundrc in my home directory for convenience, it included a profile called “bluealsa” that I referred to from the media players command line (see below)
# Bluetooth headset
defaults.bluealsa {
interface “hci0” # host Bluetooth adapter
# device “AA:00:A7:00:B8:D4” Vidonn – doesnt support A2DP! Commenting out
device “D0:8A:55:08:FC:BE”
profile “a2dp”
}
4- I learned that “SCO” and “A2DP” refer to the possible ‘services’ that your bluetooth audio device supports. If you have a speaker or high end headphones, they likely support A2DP . If they’re simple telephone headsets (like my Vidonn bone conduction headphones) they do not support A2DP but rather SCO (which is optimized for VOIP calls). They’re called “profiles”, replace SCO with A2DP where necessary. -o alsa:bluealsa
5- aplay expects a wav file, not an mp3 file 🙂 I jumped from my seat when aplay started playing the encoded data found in the mp3 file into my headphones (it was all noise)
6- for omxplayer to be able to play over bluetooth you need to call it like the following (I wanted omxplayer because I needed to play video, not just audio). “bluealsa’ here refers to the name of the profile created inside the ~/.asoundrc file like I described above: omxplayer
Thanks. I followed your instructions, then my Jabra BT2080 works fine on my pi3 B+.
I skipped chapter “Check That Pulseaudio Is Running”. Pulseaudio is not necessary here.
AWESOME!! Thanks a lot for this post. It worked for me.
Thank you, Gama, for your feedback!
pi@raspberrypi:~ $ sudo systemctl status bluetooth.service
● bluetooth.service – Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset
Active: active (running) since Sun 2020-06-28 11:36:45 EDT; 2min 34s ago
Docs: man:bluetoothd(8)
Main PID: 607 (bluetoothd)
Status: “Running”
Tasks: 1 (limit: 4915)
Memory: 2.1M
CGroup: /system.slice/bluetooth.service
└─607 /usr/lib/bluetooth/bluetoothd –noplugin=sap
Jun 28 11:36:45 raspberrypi bluetoothd[607]: Bluetooth daemon 5.50
Jun 28 11:36:45 raspberrypi systemd[1]: Started Bluetooth service.
Jun 28 11:36:45 raspberrypi bluetoothd[607]: Starting SDP server
Jun 28 11:36:45 raspberrypi bluetoothd[607]: Excluding (cli) sap
Jun 28 11:36:45 raspberrypi bluetoothd[607]: Bluetooth management interface 1.14
Jun 28 11:36:45 raspberrypi bluetoothd[607]: Endpoint registered: sender=:1.24 p
Jun 28 11:36:45 raspberrypi bluetoothd[607]: Endpoint registered: sender=:1.24 p
Jun 28 11:37:03 raspberrypi bluetoothd[607]: Endpoint registered: sender=:1.45 p
Jun 28 11:37:03 raspberrypi bluetoothd[607]: Endpoint registered: sender=:1.45 p
Jun 28 11:37:03 raspberrypi bluetoothd[607]: RFCOMM server failed for Headset Vo
##########################
RFCOMM server failed for Headset Vo
##########################
Everything went smooth until very last step, then I got the error mentioned above.
Any ideas about this issue?
Hi joseph. Your error seems to be truncated. Please check with journalctl -xe for complete error label
Hello! Thanks for the article. I have been following youness’s article but still not successful.
So my main question is DOES THIS WORK WITH HFP PROFILE HEADPHONES? Because all the Pulseaudio related articles talk about using ofono with hfp profiles, which is proving to be another headache. Please let me know if it works.
Thanks
Hi Ebrahim. I’ll try to test it as soon as possible. Bluetooth world has a number of different hardware and profiles so huge that procedures working with some hardware could have issue with different hardware.
In the meanwhile, you could try with a Raspberry PI OS Desktop installation, so having other packages that could visually help you.