How To Connect Bluetooth Headset Or Speaker To Raspberry Pi 3
This post is no more updated, read my two new posts:
Connect Bluetooth Headset To Raspberry Pi 3 (A2DP & HSP)
This post will show you how to connect a Bluetooth headset (microphone/speakers) to your Raspberry Pi, it is a sum up of several weeks I’ve spent trying to find a stable solution.
I took time to mention relevant and exhaustive information, so you don’t need to go through all Google results and workarounds that I already read and tested with no success.
If you are here for curiosity, know that the post is quite long, so make yourself comfortable.
Let’s start first with some important information:
- Raspbian 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
Again…
Before: BlueZ → ALSA
Now: BlueZ → PulseAudio → ALSA
Q: What does this mean in command-line?
All BlueZ tutorials and tips where you see ALSA commands (aplay, arecord,…) are now useless.
That’s not all the story:
- PulseAudio (5.0) supported only A2DP profile
- Later, it added also a native support of HSP profile (>=v6.0)
- And for HFP, you have to use another module: oFono
Again…
A2DP: BlueZ → PulseAudio (5+) → ALSA
HSP: BlueZ → PulseAudio (6+) → ALSA
HFP: BlueZ → oFono → PulseAudio (6+) → ALSA
For those who don’t know the difference between A2DP/HSP/HFP:
A2DP, Advanced Audio Distribution Profile, for high audio quality, as normal speakers.
E.g. Music streaming
HSP, Headset Profile, the device exchanges in/out audio and some basic AT commands.
E.g. VoIP call
HFP, Hands-Free Profile, the device acts as a phone, so it exchanges audio in/out and telephony commands.
E.g. Hands-Free mode in car
I’ll do it in that incremental order, A2DP, then HSP, and last HFP.
After this long synopsis, let’s put the pieces together.
Step 0: Start with a clean base
I recommend starting with a fresh Raspbian Jessie, in order to avoid any existing configuration files, the need to purge packages, …etc.
Update/upgrade it:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get autoremove
sudo reboot
Check the versions of packages:
dpkg -l pulseaudio
Version: 5.0-13
WARNING: Raspbian repository is still using PulseAudio 5
dpkg -l bluez
Version 5.23-2+rpi2
WARNING: Raspbian repository is now using Bluez 5
These small details can save you lot of time.
Raspbian Jessie out-of-box supports only A2DP with PulseAudio.
Bluez/PulseAudio link is done by the module pulseaudio-module-bluetooth (apt-get it if needed)
sudo apt-get install pulseaudio-module-bluetooth
At this line we have everything to set up A2DP profile connection.
Step 1: Connect the Bluetooth headset (A2DP)
Most of the time GUI Bluetooth tools will do it, but regarding all the core changes I mentioned above for each layer, I personally don’t advice you to use anyone , I tested Blueman, BlueDevil… not only it will not work, but you will not get any information or logs about the errors.
So I will show you how to do it using bluetoothctl (part of BlueZ)
Tip: Use dedicated console for Bluetooth and keep it open.
Start:
bluetoothctl
Turn on Bluetooth controller:
power on
Start the agent:
agent on
Request default agent:
default-agent
Turn on the headset, for mine I press and hold till I see the white blinking LED.
Start the scan:
scan on
After some seconds, you will see the headset name and MAC address
Pair it:
pair xx:xx:xx:xx:xx:xx
Trust it:
trust xx:xx:xx:xx:xx:xx
Connect it:
connect xx:xx:xx:xx:xx:xx
If, at this stage, the headset is still connected, you are very lucky.
If the headset is disconnected right after connection, this is the “normal problem”.
Q: How to know that the headset is disconnected:
Mine emits 2 short beeps. You can also see it in the console:
[CHG] Device xx:xx:xx:xx:xx:xx Connected: no
Check current processes running PA instances
ps aux | grep pulseaudio
pi 924 0.0 0.0 1912 92 ? S 09:35 0:00 /bin/sh /usr/bin/start-pulseaudio-x11
pi 27871 0.0 0.1 4280 1848 pts/0 S+ 11:02 0:00 grep –color=auto pulseaudio
Great, the problem is that no PulseAudio daemon is running, so start one:
pulseaudio --start
(In other cases, the problem can be the opposite, you will find that PulseAudio was started and monopolized by other services. I’ll talk about this later at the end of the post)
Now try again to connect the headset, it should work this time.
Let’s go back to PulseAudio, display current sound cards.
pacmd list-cards
You’ll find two, the built-in one of Raspberry Pi, and the headset one:
bluez_card.xx_xx_xx_xx_xx_xx
Two things to know about PulseAudio:
- Sinks: The audio outputs.
- Sources: The audio inputs.
To see them:
pacmd list-sinks
pacmd list-sources
We want that the headset becomes default sink:
pacmd set-default-sink bluez_sink.xx_xx_xx_xx_xx_xx
Download and play a sound, you will hear it from the headphone!
wget http://youness.net/wp-content/uploads/2016/08/h2g2.ogg -P /tmp/
paplay /tmp/h2g2.ogg
“In the beginning, the Universe was created. This made a lot of people very angry, and has been widely regarded as a bad move.”
– The Hitchhiker’s Guide to the Galaxy
Step 2 (Ongoing): Connect the Bluetooth headset (HSP)
As said before, HSP profile is supported with PulseAudio 6 and newer.
The only solution that I see here is to build PulseAudio from Git sources.
ONGOING WORK:
I’m currently trying to build PulseAudio by following official instructions here:
https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/Developer/PulseAudioFromGit/
As soon as I do it properly, I’ll post it.
If you did it, please share your steps 🙂
Update: 08/10/2016
I’m able to build PulseAudio from sources with some limitations, see below instructions:
FYI, I tried Arch Linux ARM, don’t waste your time, Bluetooth support is NOK too..
I choose to build the version 6 to avoid unwanted new features that may need extra work and dependencies.
This method was done with the latest Raspbian Jessie Lite (2016-09-23). This version comes without pre-installed PulseAudio, but if you are using the default Raspbian image or the one installed with NOOBS, purge it:
sudo apt-get purge pulseaudio
Start as usual by updating/upgrading the system:
sudo apt-get update
sudo apt-get upgrade
Download the sources from Freedesktop.org:
wget https://freedesktop.org/software/pulseaudio/releases/pulseaudio-6.0.tar.xz
Unzip and go to the directory:
tar xvf pulseaudio-6.0.tar.xz
cd pulseaudio-6.0
Run bootstrap script:
./bootstrap.sh
I will sum up here all errors I encountered (in case people search them by copy/paste):
./bootstrap.sh: line 46: intltoolize: command not found
configure: error: Unable to find libltdl version 2. Makes sure you have libtool 2.4 or later installed.
configure: error: *** sys/capability.h not found. Use --without-caps to disable capabilities support
No package 'json-c' found
No package 'sndfile' found
So install all above libraries:
sudo apt-get install intltool libtool libcap-dev libjson0-dev libsndfile1-dev
The script should now ends correctly, and in the command line you can see a table of the configuration done, with enabled/disabled parts. On my side: udev, bluez5, ofono, native-headset, alsa, X11, systemd, … were not enabled, so I installed additional libraries:
sudo apt-get install libudev-dev libsbc-dev libbluetooth-dev libx11-xcb-dev libasound2-dev libsystemd-dev libsamplerate0-dev
Re-do the ./ bootstrap, now missing parts are enabled.
Then, make and install PA6 (this will take some time, take a coffee).
sudo make
sudo make install
sudo ldconfig
The last command to avoid some errors of shared libs not found.
After this you can start PA daemon:
pulseaudio -D
or
pulseaudio --start
Check if it is running:
ps aux | grep pulse
Start another command line window and connect your headset like explained for A2DP before.
Go back to the first command line and window check existing audio cards:
pacmd list-cards
Your headset should be here as second card (bluez_card.xx_xx_xx_xx_xx_xx)
You can see all information, including supported profiles (a2dp_sink, headset_head_unit)
You can see also that now your headset has a source (microphone)
One annoying bug is that pulseaudio daemon will be terminated some seconds after connecting the headset, to avoid this, change the daemon configuration:
sudo nano /etc/pulse/daemon.config
Uncomment (remove the ; in) the line and put negative value (-1):
exit-idle-time = -1
Ctrl+X, y, Enter.
Start again Pulseaudio daemon.
At this step, I can listen to audio with A2DP profile, meaning Pulse Audio is well installed.
However, when I switch to HSP, I hear nothing, here I’m still searching for the rootcause.
If you find the solution before me, please post it.
~To be completed~
Step 3 (Not yet started): Connect the Bluetooth headset (HFP)
To be done after step 2.
Good news is that oFono will be compatible.
sudo apt-get install ofono
dpkg -l ofono
Version 1.15-2
~To be completed~
Step 4 (Not yet): Create autorun script
It will be very useful to create a script that make all above things, to be done.
~To be completed~
Misc
- I didn’t edit any configuration file, like default.pa of PulseAudio…etc.
- I didn’t enable any module, but maybe you will have to, if they are not auto-loaded by PulseAudio.
- I didn’t stop any PulseAudio instance, but maybe depending on your distribution, you will have to
pulseaudio --kill
andpulseaudio --start
(I saw a problem with GDM), and sometimes disable the autospawn:yes that creates PulseAudio daemon if no one is started. - This tutorial will work for many other Linux distributions that have the same Bluetooth issue.
Configuration
- Raspberry Pi 3
- Phillips SHB5600
If you have any question or remark, feel free to comment.
Good luck.
Credits:
Audio sound from :http://www.moviesoundclips.net/sound.php?id=96
Hey,
Thanks for the guide. I have the Pi3 and my Bluetooth speaker would work fine out of the box untill ran rpi-update and it broke my bluetooth connectivity. My speaker would connect and stay connected but would not be detected as a speaker. Don’t know why. I’m not that linux savvy. I think this pacmd set-default-sink bluez_sink.xx_xx_xx_xx_xx_xx , did the trick because I was using the BT gui to connect.
Anyways, thanks to your guide I was able to get my pi 3 to play audio via Bluetooth again. My problem now is the speaker only stayed connected for about an hour then it stopped playing. Actually the speaker was still connected but the audio stopped passing through the bt speaker and defaulted to the line out of the rpi. Again , I have no idea why.
I’d appreciate if you could help me out with that.
Hi,
I didn’t see this issue before, but I’m supposing that it is:
1- The Bluetooth connection that is not stable due to the SW.
2- Some timeout parameter that needs to be disabled.
If I find the exact cause I’ll let you know it here.
> “my Bluetooth speaker would work fine out of the box untill ran rpi-update and it broke my bluetooth connectivity…”
I found your problem. Why do people confuse `sudo rpi-update` with `sudo apt-get update && sudo apt-get -y upgrade`? They’re completely and utterly different. The former is only used by people who develop hardware drivers and need the `next` branch of the firmware rather than the supported `master` branch.
Yes, I’ve never used the rpi-update since I’m using the “stable” branch not the ongoing upgrade.
I like your writeup so far. I spent weeks myself arriving to where you are. I gave up on trying to build PA6. I hope you can get through it and post the solution. I’m hoping some Linux gurus will likely figure it out and get it onto the Jessie distro soon and save us (i.e. you) all the trouble.
Hi Eric,
I’m able to compile PA 6, I can also see my headset as HSP/HFP device, but PA daemon is unstable and stops after some seconds, still trying to improve it.
I’m also trying ArchLinux since it has newest packages (PA 9!), but it comes lightweight and needs several setups…
Hi,
I think coincidence has it that as you were updating Step 2 today, I was going through the same hassle… I am stuck in the same point as you: able to hear sound with the A2DP profile but, the HSP/HFP remains silent. I’ll keep digging and keep you updated in case I find something.
Thanks for putting this together,
Catalin
Hi Catalin,
Thanks for the feedback, I was afraid to be alone with this situation or to have a problem in my PA build.
Let’s stay in touch in case we find a solution for this.
Youness
Hello,
I am facing same problem for pi3 board. I am not able to hear sound in my bluetooth headset in HSP profile(A2DP works for me). I am using PA version 7.xx. Please let me know if any solution is found.
Thanks,
Mohan
The solution is to use Bluetooth USB dongle.
Hi Youness,
Thanks for reply,
As you told I am using bluetooth CSR 4.0 dongle(disabled built-in bluetooth), inside pacmd when i try to set headset_head_unit(to select HSP/HFP) I am getting below error
Failed to set card profile to ‘headset_head_unit’
Any suggestions?
Thanks in advance.
Mohan
Hi Mohan,
Did you select the correct card? (By its name or its index)
Hi,
I changed default.pa to point headeset=auto, and it is working now.
Thanks,
I tried both, index and name, HSP/HFP was working, suddenly it stopped working for hsp/hfp profile.
What i noticed is that in bluetoothctl if you run
info XX:XX:XX:XX:XX:XX (the address of your headset)
and
show (to get the information of the controller)
The UUIDs are identical in all of the cases, except Headset. Is the same in your case? Is this important? (I actually have no idea what UUIDs are and what are they used for… my linux knowledge started with me buying the RPI some months ago… 😀 )
Actually one is Headset: UUID starting with 0x1108 and the other is Headset AG: (Audio Gateway) UUID starting with 0x1112
The first 8 caracters in UUID are different and I think that it is normal, I have these UUID:
UUID: Headset
UUID: Audio Sink
UUID: A/V Remote Control Target
UUID: Advanced Audio Distribu..
UUID: A/V Remote Control
UUID: Handsfree
UUID: PnP Information
Hello.
Thank you for your great TUTO.
Step 1 was perfectly reproduced on my pi .
But after following step 2 instructions, I’m not able to connect anymore to my Bluetooth device : connect function under bluetoothctl returns bluez failed. It did not before installing pulseaudio6.
Do you have any idea please ? It seems that with the purge of previous pulseaudio (5.X) , the module pulseaudio-module-bluetooth was remove too, and is not installed with the build of pulseaudio 6. I can install it, because it will reinstall pulseaudio (5.x) too.
Thank you very much.
Hi Julien,
Maybe you’re right, I didn’t see this case of module removed by purge.
You can simulate the install with this:
sudo apt-get -s install pulseaudio-module-bluetooth
If it installs only the module then do it.
And check that you have PulseAudio running:
ps aux | grep pulse
Good luck.
Thank you very much for your answer. But i think i miss someting : even with a the Raspbian Jessie Lite (2016-09-23) which comes without pre-installed PulseAudio, i get the error when trying to connect under bluetoothctl:
Failed to connect: org.bluez.Error.Failed
(pairing is ok and pulseaudio is running)
With previous version (pulseaudio 5) it was working.
It’s very strange if you are using the same Raspbian like me…
If pairing is OK, the only problem I can see is PulseAudio stops working and you think it is still running.
Hello,
sorry i just saw we were using different HW : you are perfomring on a PI 3 with the integrated bluetooth and im on a pi zero with an usb bluetooth dongle.
Maybe it explains the difference.I spent the night on it, without any success. It’s a shame.
I can’t help much I didn’t use the Zero yet…
Try to see if Jessie Lite has what you need for USB-Bluetooth adapter (bluez-utils?)
Check also this : https://www.raspberrypi.org/learning/robo-butler/bluetooth-setup/
Hey buddy. I think you ran into the same issue as me and it is because of the part where he installed the different libraries for the bootstrap.sh. There is a line that has a bunch of missing info. In the tutorial it is written
“sudo apt-get install libudev-dev libsbc-dev libbluetooth-dev libx11-xcb-dev libasound2-dev
instal libsystemd-dev libsamplerate0-dev”
but it should be written
“sudo apt-get install libudev-dev libsbc-dev libbluetooth-dev libx11-xcb-dev libasound2-dev
sudo apt-get install libsystemd-dev libsamplerate0-dev”
This fixed my problem and it was the same thing that is happening to you apparently.
Hello,
I try to connnect the bluetooth headset by using bluez.
But I don’t want to GUI interface, only want to connect the headset on terminal.
So I used the some command as following.
1) Scan BT headset
# hcitool scan
BT headset : 11:22:33:44:55:66
2) connect the headset to my rpi3
# hcitool cc 11:22:33:44:55:66
# hcitool auth 11:22:33:44:55:66
# hcitool enc 11:22:33:44:55:66 0000
But I can’t see connected headset.
How to connect BT headset by using hcitool and hciconfig?
I recommend that you do it with bluetoothctl (as explained in the post) instead of hcitool or hciconfig.
Hi,
I have similar problem with Raspberry Pi 3: Failed to connect: org.bluez.Error.Failed. I’m using the build-in bluetooth module and cannot connect my device. IMO this is problem with pulseaudio and now I’m trying to remove version 6. Could you help with that? I recently started to use Raspberry and not sure what must I remove to uninstall pulseaudio.
Also I’m planning downgrade of blueZ to version 4.x because it supports HSP.
Hi,
I think you just need to (re)start PulseAudio daemon.
Try this:
pulseaudio –kill
pulseaudio –start
And try after to connect your headset.
Hi,
I tried that multiple times, but the result is the same.
Hi,
Can I use make uninstall to remove the installed pulseaudio?
Of course you can sudo make uninstall in PulseAudio folder. But I’m not 100℅ sure it will remove all things. If you still have the installation logs. Note the directories created (in usr/ local/ …) and remove them manually.
Hi,
I tried to execute “sudo make uninstall” but the output is “make: *** No rule to make target ‘uninstall’. Stop.” Could you help me with the uninstallion, maybe the script has another target for removal?
You can try remove related folders in /usr/local/ (bin, lib…etc.)
In my case I simply burn an fresh Raspbian version, my microSD has nothing valuable except Pulse Audio.
Hi,
I am in the same situation. Trying to get pulseaudio works with HSP profile but I have taken a slightly different approach. So, I have actually rebuilt BlueZ from 5.23 to 5.37. After skimming through the changelog of BlueZ from 5.23-5.37, I have noticed that BlueZ patched a few bugs for A2DP and also the D-Bus interface. Instead of Pulseaudio 6, I have manually built PulseAudio 8.
The reason I chose BlueZ5.37 and PulseAudio8 is because my labtop is using Linux Mint Mate and both A2DP and HSP works! Yeah! So, I am trying to go from this approach. At the moment, its still not working though… but will keep you updated!
You’re in the good way to do it, keep me informed 🙂
Thank you so much guys , :'( i though i was alone in this world until i see this page
I was trying all this stuff for months , i try it on desktop and it work, i try even all the available PI OS and never worked , i end up to use arch linux and a compiled ofono / pulse-audio but you should activate some configurations , example : pre-compiled ofono package has not Bluetooth module activate and you should recompiled with that argument (something like that).
I can make calls but the sound is just not working what the hell is missing.
The main purpose of this page is to say that your are not alone with this Bluetooth issue.
I tried quickly Arch Linux but didn’t find any help online to make it working. I’m staying with Raspbian and I think we will get a correct update by next year.
Hi Youness,
i have the same issue here, A2DP works fine, but HSP does not work. I have not found any solutation yet 🙁
@Yahya: afaik HSP should work without oFono, at least this is what the changelog for PulseAudio6 says: https://www.freedesktop.org/wiki/Software/PulseAudio/Notes/6.0/ (native HSP with Bluez5)
Yevgeniy
[…] pi3上测试自己编译高版本的pulseaudio,参考: http://youness.net/raspberry-pi/bluetooth-headset-raspberry-pi […]
Thank you for this, it was quite helpful. My only suggestion is rather than manually compiling pulseaudio 6, if you add Debian backports you can just apt-get install the packages. This avoids dependency hell with things like pulseaudio-module-bluetooth.
First add GPG keys for the backports:
gpg –keyserver pgpkeys.mit.edu –recv-key 8B48AD6246925553
gpg –keyserver pgpkeys.mit.edu –recv-key 7638D0442B90D010
gpg -a –export 8B48AD6246925553 | sudo apt-key add –
gpg -a –export 7638D0442B90D010 | sudo apt-key add –
Then follow directions here to add to your apt sources:
https://backports.debian.org/Instructions
You should now see 7.x versions when you do this:
apt-cache policy pulseaudio
Now add packages:
apt-get install pulseaudio=7.1-2~bpo8+1 pulseaudio-module-x11=7.1-2~bpo8+1 pulseaudio-module-bluetooth=7.1-2~bpo8+1 libpulse0=7.1-2~bpo8+1 pulseaudio-utils=7.1-2~bpo8+1 libpulsedsp=7.1-2~bpo8+1
Finally back to your tutorial:
dpkg -l pulseaudio
Should show 7.1-2~bpo8+1.
Thanks Robert. I’ve already tried this but I missed the gpg keys.
I will add to your method that you need (sudo apt-get update) after adding jessie-backport to source.list in order to update the packages list.
Additionally, you don’t think that we need more than packages you listed? like dbus package.
Not sure yet re: dbus – I have the audio output working now via the pulseaudio 7.x packages. I’m down a different rabbithole now to compile a cli softphone (pjsua) so I can try a full-duplex phone call. Still working on that one.
I purged pulseaudio 5 and did your steps, but I couldn’t connect the headset (I got the error “Failed to connect: org.bluez.Error.Failed”).
In pulseaudio logs I don’t understand why I still see bluez4-util.c, I suspect that current version of dbus in Raspberry Pi is still using it… Anyway lot of rabbit holes to explore ^^
Did anyone success in bluetooth mic working, I have upgraded now to pulseaudio 7 and has HSP enabled but still mic is not working only speaker is working good.
Not yet here, and I didn’t see anyone who did it…
Unsure how active this board is, but I followed the guide and cannot get my bluetooth headset to connect. I can get all the way through pair and trust, but it will not connect. What am I doing wrong?
Thanks
Satch
Can you give more details? Do you see any error code?
Hey All —
A colleague and I have been following this article (and many others on the internet) closely in order to get A2DP & HFP/HSP working on Raspberry Pi. We’ve finally collected enough information from the various corners of the internet, obscure release notes and testing to put together a full end-to-end workflow to get both A2DP SRC and HFP/HSP AG working (that is playing music/voice from Raspberry Pi to a compatible headset).
Some info: I have tested A2DP with a Nokia headset which supposedly supports A2DP & HSP. I tested HFP/HSP with a small in-ear Nokia earpiece which supports both HSP & HFP.
The steps in this article are very close to the correct working steps, though there are a number of things you must check.
In our use case we started with the Raspbian Jessie Lite Image found here: https://www.raspberrypi.org/downloads/raspbian/
I flashed it onto an SD, inserted into Raspberry Pi and booted the pi. I did a number of things to make it more accessible for me: (enable SSH, set localization, set keyboard settings, etc). So I was working from a very minimal image with very little changes.
NOTE: At this point there should be _no_ installation of PulseAudio present.
I then performed the following steps:
– apt-get update
– apt-get upgrade
– wget https://freedesktop.org/software/pulseaudio/releases/pulseaudio-6.0.tar.xz
– tar xvf pulseaudio-6.0.tar.xz
– apt-get -y install intltool libtool libcap-dev libjson0-dev libsndfile1-dev libudev-dev libsbc-dev libbluetooth-dev libx11-xcb-dev libasound2-dev libsystemd-dev libsamplerate0-dev libspeexdsp-dev libdbus-1-dev
– cd pulseaudio-6.0 && ./configure –disable-x11 –disable-bluez4 && make -j 8 && make install && ldconfig
– apt-get install pulseaudio-module-bluetooth
That last step makes _no_ sense to me, but it IS required. The version of PulseAudio in the default raspbian repo is 5.0. That last apt-get is going to install pulseaudio 5.0, along with required dependencies. When you build pulseaudio from source and install it, its going to install into: /usr/local/…
while the apt-get is going to install pulseaudio 5.0 in /usr/…
Next I installed ofono:
apt-get install ofono
NOTE: The ordering of things above is sort of strange, I’m sure other orders work but I am writing my exact steps in case the order does end up mattering.
Next you’ll want to add your user(s) to the pulse-access group:
adduser pulse-access
In my case the user is the default pi.
Now we need to make some config changes. Note that the configs stored in “/usr/etc…” are not going to be used. The version we installed from source is going to look at: “/usr/local/etc…” so we will be modifying files found there.
sudo nano /usr/local/etc/pulse/default.pa
Find the line “load-module module-bluetooth-discover” and change to: “load-module module-bluetooth-discover headset=auto”
Add the following line to the very bottom of the file:
load-module module-switch-on-connect only_from_unavailable=false
Save and exit default.pa
sudo nano /usr/local/etc/pulse/daemon.conf
Find the line: ; exit-idle-time = 20. Remove the semicolon and change the 20 to -1 (this will make sure pulseaudio doesn’t exit while you setup your device).
Save and exit daemon.conf
Another thing which _may_ matter which I have not tested (I plan to soon) is loading the snd-aloop module. I currently have the following command issued upon boot (via init.d):
modprobe snd-aloop
At this point I would reboot the system as we are done with configuration. Again, NOTE: that modprobe snd-aloop may need to be done every boot. You can try it out and see if its not needed, I plan to do so soon.
After reboot we need to make sure that ofonod and pulseaudio are both running. It is very important to run both pulseaudio and ofonod in user-mode not root. This means you should be logging into your machine as non-root. I logged in as pi.
First, lets make sure both pulseaudio and ofonod are stopped.
sudo killall pulseaudio
sudo killall ofonod
Then we want to start both:
I like to check that the correct version of pulseaudio is being picked up. You can check with:
pulseaudio –version
if it prints pulseaudio 6.0 then we are good.
Issue the following two commands to get both pulseaudio and ofonod running:
pulseaudio –start
ofonod
Both should be running in the background now. Next we need to pair and connect our headphones/headset. You can swap between a2dp and hsp/hfp on headphones which support both modes. In my testing I made sure that I used A2DP-enabled headphones for A2DP tests and HFP-only headset for HFP test. I need to test with some dual-profile headphones and report back on commands to swap.
Lets pair and connect your bluetooth device. Put your bluetooth device in discoverable/pairable mode. Then run bluetoothctl
When in bluetoothctl issue the following commands:
pairable on
discoverable on
scan on
agent on
default-agent
Wait for your headphones to be discovered then type:
pair (NOTE: bluetoothctl supports tab-complete on commands and MAC addresses to save some time).
After pairing is done:
connect
Connection should work! If it doesn’t, check again that pulseaudio is still running (ps axg | grep pulse) and that ofono is still running (ps axg | grep ofono). Also ensure they are run from the non-root account.
If the connection succeeds, go play some music using whatever. I used aplay to play a .wav file I copied onto my raspberry pi. I heard A2DP audio on my A2DP headset and terrible quality music on my HSP/HFP headset 🙂
There’s a lot of steps here and a lot of overlap with the instructions in the main post. I may have missed something. If you can report back your experience I’d be happy to follow up.
-Keaton
Hi Keaton,
Thanks a lot for your feedback, just to confirm my understanding, now you can use the microphone of your headset?
If this is correct, so it means we are lucky to find a method that is not based on official release notes… I taught we can make HSP with only PulseAudio6… But anyway, I’ll try your steps ASAP and let you know if it works for me.
Thanks again.
—
Youness
Hey,
I ran out of time at work to validate the HSP Mic in functionality. I will try it out on Monday ASAP as it is the last piece of Bluetooth functionality I need.
I see no clear reason why it wouldnt work at this point. Then again I’ve said that about quite a few things re: BlueZ & Raspbian.
Keaton
Actually I reread my original reply and I have some modifications to make. Firstly, ofono is _not_ required, unless you wish to use HFP functionality. PulseAudio 5.0 supports a2dp and PulseAudio 6.0 supports HSP out of the box. Ofono is required to get HFP working. The main difference here is HFP has telephony controls (dial a call, accept a call, hangup, etc). In my particular use-case I just need audio over SCO/eSCO so HSP is sufficient. I was having trouble getting the full HFP stack through ofono working, so I am no longer using it. HSP should support both directions of traffic just using PulseAudio.
So, I’d modify the above instructions to ignore ofono.
Also, if your headphones support both HSP and A2DP, PulseAudio is going to default to one or the another (for my speakers I tested it defaulted to HSP). You can change this with:
pactl list cards
// Read the list to find your bluez_… entry. You can see the available profiles near the bottom of the entry. You can then change the profile with:
pactl set-card-profile CARD_NUMBER PROFILE
example:
pactl set-card-profile 2 a2dp_sink
Hi Keaton,
I tried your steps, but I get the same result, sound OK in A2DP, no sound in HSP.
I have some comments for your steps:
– No need to use Ofono.
– No need to install pulseaudio-module-bluetooth, it is included in PulseAudio sources.
– headset=auto in default.pa in optional (HSP is native option)
For your information, my headset supports ONLY HSP profile.
If on your side you can hear sound through HSP (with the mono quality), so it means it depends on the headset model…. Can you confirm that it’s working on your side?
When you display card information with:
pacmd list-cards
Do you see for the profile:
headset_head_unit?
OR
headset_audio_gateway?
Thanks.
Hey,
Yeah, I was incorrect about requiring ofono. Originally we had intended to support HFP (HSP audio + phone operations) but we decided we didn’t care enough to get it working.
I know that pulseaudio-module-bluetooth is in the PA sources, I wrote in my original comment that the step makes no sense. However I tested it very carefully and found that the apt-get install step is required. Not specifically for that module, but most likely one of its dependencies (there are quite a few). From a fresh image if I omit that step, A2DP does not work. Very baffling to me personally.
headset=auto is definitely required. If I remove this line and restart PA, my HSP no longer works correctly. I know that it _shouldn’t_ be required, but for me at least it was definitely required.
I have tested HSP on a Nokia BH104, and a set of speakers (Big Jam Box). For A2DP I tested against Nokia BH 503 headphones and again on the Big Jam Box speakers.
I am listening to some awful mono quality music on my BH 104 right now. pactl list cards shows:
headset_head_unit as my profile. It also shows 1 sink 1 source.
Mic In is working correctly with no additional setup. Volume is a bit low and the mic on this particular bluetooth headset is a pile of garbage, but I can hear myself when playing back the wav file I saved with: arecord
Thanks,
Keaton
Hi Keaton,
I’ve been trying to connect an HFP only headset to raspberry through ofono but have had no success. Can you confirm that such setup has been working for you? Actually, there is a comment here https://bugs.freedesktop.org/show_bug.cgi?id=73325#c55 which says that oFono is not supposed to work that way, it can connect to a phone via HFP profile to act as a headset…
Any details very much appreciated!
Hi Mike,
What you said is officially pointed in PulseAudio 6.0 notes: https://www.freedesktop.org/wiki/Software/PulseAudio/Notes/6.0/
“The oFono backend…connecting a headset to the PC doesn’t work.”
Youness,
Have you tested?
Tested what?
I still have no sound in HSP mode. No solution seems working for the moment for the microphone.
You rock buddy,
After sifting through all the crap google gave me, i just needed your “pulseaudio –start” above (Ripper!!)
Cheers
Glen20
That’s the purpose of this big thread 🙂 You’re welcome.
Installing PulseAudio from jessie-backport solve my problem.
A2DP and HSP both works.
sudo nano /etc/apt/sources.list
### add this line at last
deb http://ftp.debian.org/debian jessie-backports main
gpg –keyserver pgpkeys.mit.edu –recv-key 8B48AD6246925553
gpg –keyserver pgpkeys.mit.edu –recv-key 7638D0442B90D010
gpg -a –export 8B48AD6246925553 | sudo apt-key add -gpg -a –export 8B48AD6246925553 | sudo apt-key add –
gpg -a –export 8B48AD6246925553 | sudo apt-key add –
gpg -a –export 7638D0442B90D010 | sudo apt-key add -gpg -a –export 7638D0442B90D010 | sudo apt-key add –
gpg -a –export 7638D0442B90D010 | sudo apt-key add –
sudo apt-get update
sudo apt-get autoremove
sudo apt-get autoremove pulseaudio pulseaudio-utils -y
sudo apt-get autoremove pulseaudio-module-bluetooth pulseaudio-module-x11 pulseaudio-module-zeroconf -y
sudo apt-get autoremove install paman pavucontrol pavumeter -y
sudo apt-get autoremove install libpulse0 libpulsedsp
sudo apt-get -t jessie-backports install pulseaudio pulseaudio-utils -y
sudo apt-get -t jessie-backports install pulseaudio-module-bluetooth pulseaudio-module-x11 pulseaudio-module-zeroconf -y
sudo apt-get -t jessie-backports install libpulse0 libpulsedsp
sudo apt-get -t jessie-backports install paman pavucontrol pavumeter -y
dpkg -l | grep -v deinstall | grep PulseAudio
ii paman 0.9.4-1+b1 armhf PulseAudio Manager
ii pavucontrol 2.0-3 armhf PulseAudio Volume Control
ii pavumeter 0.9.3-4+b1 armhf PulseAudio Volume Meter
ii pulseaudio 7.1-2~bpo8+1 armhf PulseAudio sound server
ii pulseaudio-module-bluetooth 7.1-2~bpo8+1 armhf Bluetooth module for PulseAudio sound server
ii pulseaudio-module-x11 7.1-2~bpo8+1 armhf X11 module for PulseAudio sound server
ii pulseaudio-module-zeroconf 7.1-2~bpo8+1 armhf Zeroconf module for PulseAudio sound server
ii pulseaudio-utils 7.1-2~bpo8+1 armhf Command line tools for the PulseAudio sound server
sudo nano /etc/pulse/daemon.config
exit-idle-time = -1
pulseaudio –k
pulseaudio -D
Can you please tell me more about your headset? And how did you change the profile to headset_head_unit?
Thank you.
Hi Youness,
Thank you for sharing this.
Not sure about HSP, but HFP works with Pulseaudio 7 when used with this program: https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=96979
I am however not able to get Pulseaudio 7 to start separately without the program. It could be that some config files are missing.
Cheers,
Patrik
Hi Patrick,
I already tested this project, and yes I couldn’t start PulseAudio outside the program. Let me check it again this weekend and tell you if I find a solution.
Hi Youness,
I’ve gone through your instruction and got the follow. It looks that HSP is enabled which i consider (if i’m wrong please correct me) as both the output and input are available. However there was no sound available in/out. Any idea?
What i’ve got:
2 card(s) available.
index: 0
name:
driver:
owner module: 6
properties:
alsa.card = “0”
alsa.card_name = “bcm2835 ALSA”
alsa.long_card_name = “bcm2835 ALSA”
device.bus_path = “/devices/virtual/sound/card0”
sysfs.path = “/devices/virtual/sound/card0”
device.string = “0”
device.description = “bcm2835 ALSA”
module-udev-detect.discovered = “1”
device.icon_name = “audio-card”
profiles:
output:analog-mono: Analog Mono Output (priority 200, available: unknown)
output:analog-stereo: Analog Stereo Output (priority 6000, available: unknown)
off: Off (priority 0, available: unknown)
active profile:
sinks:
alsa_output.0.analog-stereo/#0: bcm2835 ALSA Analog Stereo
sources:
alsa_output.0.analog-stereo.monitor/#0: Monitor of bcm2835 ALSA Analog Stereo
ports:
analog-output: Analog Output (priority 9900, latency offset 0 usec, available: unknown)
properties:
index: 1
name:
driver:
owner module: 25
properties:
device.description = “RB-T7”
device.string = “00:15:13:53:93:BA”
device.api = “bluez”
device.class = “sound”
device.bus = “bluetooth”
bluez.path = “/org/bluez/hci0/dev_00_15_13_53_93_BA”
bluez.class = “0x002540”
bluez.alias = “RB-T7”
device.icon_name = “audio-card-bluetooth”
profiles:
headset_head_unit: Headset Head Unit (HSP/HFP) (priority 20, available: unknown)
a2dp_sink: High Fidelity Playback (A2DP Sink) (priority 10, available: unknown)
off: Off (priority 0, available: yes)
active profile:
sinks:
bluez_sink.00_15_13_53_93_BA/#1: RB-T7
sources:
bluez_sink.00_15_13_53_93_BA.monitor/#1: Monitor of RB-T7
bluez_source.00_15_13_53_93_BA/#2: RB-T7
ports:
unknown-output: Bluetooth Output (priority 0, latency offset 0 usec, available: unknown)
properties:
unknown-input: Bluetooth Input (priority 0, latency offset 0 usec, available: unknown)
properties:
Hi Buya,
I have the same thing like you. I can see HSP microphone and speakers but there is no sound. Other people reported that they have sound so I think it is a problem in PulseAudio or the brand of speaker…
Youness,
Thank you for all the work you’ve done here! Appreciated!
Thanks for the prompt reply, too!
Buya
Your’e welcome, I keep updating this topic each time I find news so maybe one day I’ll post a final solution 🙂
Hi Youness,
Really nice tutorial.
I am a NOOB and I am trying to connect my JBL Go BT speaker to my RPI3. I want my speaker to connect at a certain time and have it play a livestream… As a radio alarm clock… Not sure if it will ever work but I like to try.
Currently I am able to connect my RPI to my BT speaker through bluetoothctl and pulseaudio –start.
Problem 1:
After being connected, when Ienter the command ‘pacmd list-cards’ I only see one BT card…
Problem 2:
When I use the command mplayer http://stream… the stream starts running but there is no audio coming out of my BT speaker.
Any thoughts?!
Hi Tim,
1- You are connecting only one speaker so it is normal to see one BT card, can you explain more the problem?
2- Here I think you need two things, you need to make Bluetooth output as default sink, and tell mplayer to use PulseAudio.
After connecting, do:
pacmd set-default-sink bluez_sink.xx_xx_xx_xx_xx_xx
(Replace xx with your BT MAC)
And then, do:
mplayer -ao pulse http://stream…
Good luck.
Hi Younnes, thanks for the quick reply.
Everything in the tutorial goes fine until
1. In your tutorial your are saying:
“Command pacmd list-cards
You’ll find two, the built-in one of Raspberry Pi, and the headset one:
bluez_card.xx_xx_xx_xx_xx_xx”
I just get one BT card. This one:
1 sink(s) available.
* index: 0
name:
driver:
flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY FLAT_VOLUME DYNAMIC_LATENCY
state: SUSPENDED
suspend cause: IDLE
priority: 9009
volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
balance 0.00
base volume: 56210 / 86% / -4.00 dB
………
I would think I would see my RP bluetooth card and my speaker… So not sure if it is correct now.
2. After the ‘pacmd set-default-sink’ command I get the message ‘Sink bluez_sink.[MAC] does not exist’
It is weird because my BT device is connected…. Any thoughts?
Hi Tim,
1. I was saying that you will see 2 sound cards, not two BT cards. Here you will see BCM card and your speaker.
When you do the command pacmd set-default-sink bluez_sink… Just press TAB button of your keyboard and the system sill show you the list of sinks to choose one of them.
2- I think your BT speaker is not correctly connected. Can you remove it and start again? (Use bluetoothcl menu to do this)
Hi,
Thanks for this post, it’s very usefull.
However, I have a RPI 2B with a fresh Jessie install but I don’t have any bluez_card.xx_xx_xx_xx_xx_xx when I list cards 🙁
[bluetooth]# info xx:xx:xx:xx:xx:xx
Device xx:xx:xx:xx:xx:xx
Name: UE ROLL 2
Alias: UE ROLL 2
Class: 0x240404
Icon: audio-card
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Vendor specific ([…])
UUID: Serial Port ([…])
UUID: Audio Source ([…])
UUID: Audio Sink ([…])
UUID: A/V Remote Control Target ([…])
UUID: Advanced Audio Distribu.. ([…])
UUID: A/V Remote Control ([…])
UUID: PnP Information ([…])
Modalias: bluetooth:v000ApFFFFdFFFF
pi@raspberrypi:~ $ pacmd list-cards
2 card(s) available.
index: 0
name:
driver:
owner module: 6
properties:
alsa.card = “0”
alsa.card_name = “bcm2835 ALSA”
alsa.long_card_name = “bcm2835 ALSA”
device.bus_path = “/devices/virtual/sound/card0”
sysfs.path = “/devices/virtual/sound/card0”
device.string = “0”
device.description = “bcm2835 ALSA”
module-udev-detect.discovered = “1”
device.icon_name = “audio-card”
profiles:
output:analog-mono: Mono analogique Output (priority 100, available: unknown)
output:analog-stereo: Stéréo analogique Output (priority 6000, available: unknown)
off: Éteint (priority 0, available: unknown)
active profile:
sinks:
alsa_output.0.analog-stereo/#0: bcm2835 ALSA Stéréo analogique
sources:
alsa_output.0.analog-stereo.monitor/#0: Monitor of bcm2835 ALSA Stéréo analogique
ports:
analog-output: Sortie analogique (priority 9900, latency offset 0 usec, available: unknown)
properties:
index: 1
name:
driver:
owner module: 23
properties:
device.description = “UE ROLL 2”
device.string = “xx:xx:xx:xx:xx:xx”
device.api = “bluez”
device.class = “sound”
device.bus = “bluetooth”
device.form_factor = “headset”
bluez.path = “/org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx”
bluez.class = “0x240404”
bluez.alias = “UE ROLL 2”
device.icon_name = “audio-headset-bluetooth”
device.intended_roles = “phone”
profiles:
a2dp_source: High Fidelity Capture (A2DP Source) (priority 10, available: unknown)
a2dp: High Fidelity Playback (A2DP Sink) (priority 10, available: unknown)
off: Éteint (priority 0, available: yes)
active profile:
ports:
headset-output: Headset (priority 0, latency offset 0 usec, available: unknown)
properties:
headset-input: Headset (priority 0, latency offset 0 usec, available: no)
properties:
Any suggestion would be appreciated 🙂
I can see your speaker it is displayed: UE ROLL 2 (the 2nd card).
I found myself the answer.
If you don’t see the bluez_sink card, try this :
pactl set-card-profile 1 a2dp
Yes I think the profile was off. Good 🙂
The 2nd card (bluez_sink card) is only available when my bluetooth speaker is powered on (but to do that I need to push a button on the speaker).
If I don’t push the power on button, I can successfully connect the raspberry to the bluetooth speaker via bluetoothctl, but the bluez_sink card is not displayed via pacmd list-cards command. So, I can’t stream the music.
However, from my Android mobile application, I can connect to the bluetooth speaker (BLE) and remote power it on and yet stream music from the phone.
Any idea how to remote power on a BLE speaker via bluetoothctl or another program/script?
I would automate the connexion and stream music.
Thanks for the help and this usefull post.
Ah OK now I understand, your speaker is in idle mode and via your app you wake it to stream music, unfortunately I don’t think that you can do this by Raspberry Pi, because you need to know the socket sent by the application…
Here is my script for auto connect to my bluetooth speakers. I haven’t optimized the sleep times yet, can probaby be done with grep.
#!/bin/bash
pulseaudio –start
sleep 2
{
sleep 1;
echo “power on”
sleep 1
echo “agent on”
sleep 1
echo “default-agent”
sleep 1;
echo “remove 00:11:67:11:11:B7”
sleep 1
echo “scan on”
sleep 15
echo “scan off”
sleep 1
echo “pair 00:11:67:11:11:B7”
sleep 1
echo “trust 00:11:67:11:11:B7”
sleep 4
echo “connect 00:11:67:11:11:B7”
sleep 5;
echo exit
} | bluetoothctl
sleep 2
pacmd set-default-sink bluez_sink.00_11_67_11_11_B7
If it is working than it is OK even if sleep times are not adjusted. I advise you to add at the end “pacmd set-default-sink” to turn the profile to “off” and then to “a2dp_sink”, to be sure you are in the correct profile.
I’ve been sifting through the comments, and i would like to know has the bluetooth audio input worked yet?
@Youness are you close to completing step 2?
Not yet for me, still don’t know why PulseAudio 6 is not working with HSP. But some comments told it works for them, maybe speaker brand matters.
Youness have you tried using an external Bluetooth dongle?
I was able to get HFP+A2DP to work on a RPI3, but only with external bluetooth, the one build in just did not work for the HFP profile. There was no sound what so ever.
Also do you have any idea on how can we load the module-echo-cancel for HFP?
I’m trying to build a handsfree based on the RPI, I kind-a got it working but I’m facing 2 problems:
1) Echo
2) Stability
For me the easiest way to get it all working was one of the following 2:
a) Use Jessie-Backports (comes with Pulseaudio 7.1 )
b) Use Stretching repo (comes with PulseAudio 10.0)
Again another thing, for some reason Raspberry Pi Zero, same setup as the Pi 2 or Pi 3 but there is no audio when using HFP only some garlicky sound. Tried compiling PulseAudio for the Pi Zero same result, so Pi Zero might not be a working solution.
I did the opposite, I used Raspberry Pi Bluetooth + wired connection instead of WiFi, and I noticed big improvement in terms of connection and audio quality. So my advice is to not use both Raspberry Pi WiFi and Bluetooth.
I keep your other questions in mind if I find the answers later.
First of all, thanks for the tutorial. I was simply trying to get output to a bluetooth speaker. But now I’m having the issue where I can’t switch the sound back to the analog output. Not sure why, I switched the sink back over to the analog, its not muted. Not sure what the issue is. Sorry I’m super new to linux tinkering
pi@rpi-vtrevino:~$ pacmd list-sinks
1 sink(s) available.
* index: 0
name:
driver:
flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY FLAT_VOLUME DYNAMIC_LATENCY
state: SUSPENDED
suspend cause: IDLE
priority: 9009
volume: front-left: 56210 / 86% / -4.00 dB, front-right: 56210 / 86% / -4.00 dB
balance 0.00
base volume: 56210 / 86% / -4.00 dB
volume steps: 65537
muted: no
current latency: 0.00 ms
max request: 0 KiB
max rewind: 0 KiB
monitor source: 0
sample spec: s16le 2ch 48000Hz
channel map: front-left,front-right
Stereo
used by: 0
linked by: 0
configured latency: 0.00 ms; range is 0.50 .. 341.33 ms
card: 0
module: 6
properties:
alsa.resolution_bits = “16”
device.api = “alsa”
device.class = “sound”
alsa.class = “generic”
alsa.subclass = “generic-mix”
alsa.name = “bcm2835 ALSA”
alsa.id = “bcm2835 ALSA”
alsa.subdevice = “0”
alsa.subdevice_name = “subdevice #0”
alsa.device = “0”
alsa.card = “0”
alsa.card_name = “bcm2835 ALSA”
alsa.long_card_name = “bcm2835 ALSA”
device.bus_path = “/devices/virtual/sound/card0”
sysfs.path = “/devices/virtual/sound/card0”
device.string = “hw:0”
device.buffering.buffer_size = “65536”
device.buffering.fragment_size = “65536”
device.access_mode = “mmap+timer”
device.profile.name = “analog-stereo”
device.profile.description = “Analog Stereo”
device.description = “bcm2835 ALSA Analog Stereo”
alsa.mixer_name = “Broadcom Mixer”
module-udev-detect.discovered = “1”
device.icon_name = “audio-card”
ports:
analog-output: Analog Output (priority 9900, latency offset 0 usec, available: unknown)
properties:
active port:
Not sure if anything stands out here. Still messing around with it myself.
Im sure someone has had this issue and wants to be able to switch back and forth.
Ok so I figured out something… Not sure what that is exactly. But it answers some questions and raises new ones. Wasn’t getting any sound from doing ‘mpg123 sound.mp3’ but then I tried omxplayer and the clip played. I see that omxplayer doesn’t use ALSA, so I guess it doesn’t configure the same way.
I changed my raps-config back to auto detect mode and tried to play the mp3 but it was just scratch noises. But then I killed pulse audio and the sound clip played fine.
Things i’ve learned: Life is precious. And I’m still confused
So now I see my blue tooth device when I list-cards
pi@rpi-vtrevino:~$ pacmd list-cards
2 card(s) available.
index: 0
name:
driver:
owner module: 6
properties:
alsa.card = “0”
alsa.card_name = “bcm2835 ALSA”
alsa.long_card_name = “bcm2835 ALSA”
device.bus_path = “/devices/virtual/sound/card0”
sysfs.path = “/devices/virtual/sound/card0”
device.string = “0”
device.description = “bcm2835 ALSA”
module-udev-detect.discovered = “1”
device.icon_name = “audio-card”
profiles:
output:analog-mono: Analog Mono Output (priority 100, available: unknown)
output:analog-stereo: Analog Stereo Output (priority 6000, available: unknown)
off: Off (priority 0, available: unknown)
active profile:
sinks:
alsa_output.0.analog-stereo/#0: bcm2835 ALSA Analog Stereo
sources:
alsa_output.0.analog-stereo.monitor/#0: Monitor of bcm2835 ALSA Analog Stereo
ports:
analog-output: Analog Output (priority 9900, latency offset 0 usec, available: unknown)
properties:
index: 4
name:
driver:
owner module: 27
properties:
device.description = “AMPLIFi 75 9f”
device.string = “00:07:80:0C:D5:9F”
device.api = “bluez”
device.class = “sound”
device.bus = “bluetooth”
device.form_factor = “hifi”
bluez.path = “/org/bluez/hci0/dev_00_07_80_0C_D5_9F”
bluez.class = “0x200428”
bluez.alias = “AMPLIFi_75_9f”
device.icon_name = “audio-card-bluetooth”
profiles:
a2dp: High Fidelity Playback (A2DP Sink) (priority 10, available: unknown)
off: Off (priority 0, available: yes)
active profile:
ports:
hifi-output: HiFi (priority 0, latency offset 0 usec, available: unknown)
properties:
hifi-input: HiFi (priority 0, latency offset 0 usec, available: no)
properties:
but not when I list sinks -__-
Ok so that
pactl set-card-profile 4 a2dp
Worked, sorry for spam. The index on the sound card keeps going up every time I reconnect to the speaker on blue tooth. I didn’t notice, also didn’t have to do that step the first time… Sorry and thanks
Yes the index increments after every reconnection in the same session.
(You can also left-click the sound icon in the taskbar, and select analog output.)
what a huge waste of time for this…..pulse 5 no 6 no wait 7 no lets backport it wtf?
it is had to believe that such a relatively minor feature is not usable, or reliable.
Welcome to open source hell…. we will probably have to wait for the Pi4 or 5.
Just forget the integrated bluetooth for now
I understand your point, unfortunately this is a sad part of open source projects…
Hi, Youness, thank you for this CLEAR tutorial! I got what I need from this post.
The A2DP part works on Raspbian Jessie and bluetooth speaker.
The audio quality is not that satisfied via ALSA, it’s even worse after starting pulseaudio daemon. Next, I will try usb audio device, hope the audio quality could be better for a DIY Music alarm clock.
Also, thank you Uriel Guy, you shell script works too.
Tried this with a JBL Charge 3 and Keaton’s guide. Initially only worked in a2dp mode if I switched the profile. I was getting this:
headset_head_unit: Headset Head Unit (HSP/HFP) (priority 20, available: unknown)
a2dp_sink: High Fidelity Playback (A2DP Sink) (priority 10, available: unknown)
off: Off (priority 0, available: yes)
Neither output or input worked on the headset_head_unit profile.
dmesg | grep -i bluetooth
bluetooth hci0: Direct firmware load for brcm/BCM20702A1-0b05-17cb.hcd failed with error -2
I noticed there was an issue with my hci0, so I started googling for possible issues with HSP with my usb bluetooth dongle (Asus bt400) and found this:
https://workingninja.com/installing-asus-bt400-raspberry-pi-raspbian-wheezy
Updated my firmware by following those steps. Rebooted, reconnected to the speaker. Now I can run:
parecord -v test.wav
paplay -v test.wav
And I can hear my recording through the BT speaker.
Other steps I randomly did, not sure if they had anything to do with it:
sudo apt-get reinstall bluez bluez-firmware
apt-get reinstall pulseaudio-module-bluetooth
(then I reran the pulse audio 6 install AFTER the reinstall of pulse audio 5)
cd pulseaudio-6.0 && sudo make install
Here’s what my pactl list cards looks like now:
Card #2
Name: bluez_card.B8_69_C2_40_83_26
Driver: module-bluez5-device.c
Owner Module: 24
Properties:
device.description = “JBL Charge 3”
device.string = “B8:69:C2:40:83:26”
device.api = “bluez”
device.class = “sound”
device.bus = “bluetooth”
device.form_factor = “speaker”
bluez.path = “/org/bluez/hci0/dev_B8_69_C2_40_83_26”
bluez.class = “0x240414”
bluez.alias = “JBL Charge 3”
device.icon_name = “audio-speakers-bluetooth”
Profiles:
headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: yes)
a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
Active Profile: headset_head_unit
Ports:
speaker-output: Speaker (priority: 0, latency offset: 0 usec)
Part of profile(s): headset_head_unit, a2dp_sink
speaker-input: Bluetooth Input (priority: 0, latency offset: 0 usec)
Part of profile(s): headset_head_unit
Hi,
Thanks for your feedback.
I note that in your pactl list cards now the availability of profiles is “yes”, something I didn’t see before in my setup.
You are confirming us that the problem is coming form Raspberry Pi Bluetooth chipset (and/or its firmware), if so, it means that we have to stop dealing with Pulseaudio because version 6 or later is OK.
Thanks a lot Youness. That saved a lot of time indeed. With the above tutorial I was able to connect to my bluetooth speakers in the very first attempt. What I want is
:1) As soon as I turn my bluetooth speaker ON, it should automatically connect to Pi.
2 ) I want Pi to set its default audio output to bluetooth speaker and not the audio jack.
It would be great if I get solutions for the same.
Hi Sameer,
I can’t test this myself now so I give you the information and let me know if it is enough.
In the file: /etc/pulse/default.pa
Add the line:
load-module module-switch-on-connect
(I assume that PulseAudio is already running)
Hello Youness,
It seems the above thing din’t work. But using the script shared in this thread by Uriel Guy , and running it on boot helped me to get my stuff done. Now taking my project to next level. Once again thanks a lot Youness. Your simplified explanation of complicated stuff is just amazing!
You’re welcome 🙂
please I need your help with something with me like this …
I need to make my Rpi bluetooth as a slave receiving strings from “master” hc-05 module connected with arduino
I would like to help you but I need more description of your project… Put all you know in comment.
I made a robot that’s controlled by a RPI ,,,the robot should recieve a number from 4 places ,,each place of them have a master hc-05 module connected to arduino ,,when the robot is in the range of this bluetooth ,,it starts sending the 7 digit number to the robot .
so my RPI should be a slave that accepts data from the arduino hc-05 module master .
Note that Iam talking about the onboard bluetooth of RPI 3 not a bluetooth dongle .
thanks in advance
Hi mahmoud,
I don’t have this module so I just search in Google for you:
In summary you will need to have a permanent connection between Raspberry Pi and the modules.
Check these posts I think you will find what you need:
https://myraspberryandme.wordpress.com/2013/11/20/bluetooth-serial-communication-with-hc-05/
http://www.uugear.com/portfolio/bluetooth-communication-between-raspberry-pi-and-arduino/
To automatically connect your module each time is ON and in range, you need to “trust” it in Raspberry Pi side.
Hii Youness ,
I lost hope about that to be done ,,
Do you work with uart of raspberry pi ? I want to connect hc-05 with raspberry pi and use it as a slave for a master that connects with every master in it’s range ..
I want just to receive strings from this master using hc-05 ..
I read some problems about having 2 uarts in Rpi big one for the bluetooth onboard ..and the other one for the uart pins in the board .
I have to solve this today because I have a competition in 2 days .
thanks :))
Well, you have to do it the easy way if you want to finish it ASAP 🙂
From what I know you have to make choice. Do you want Bluetooth or UART? Because Bluetooth in Raspberry Pi uses first UART. I don’t recommend you to use the second UART because it is not stable.
not stable ? can you explain what can happen ?
The baud rate may be impacted by CPU clock. Check this post it explains UART issue in Raspberry Pi 3.
https://frillip.com/raspberry-pi-3-uart-baud-rate-workaround/
I read about it but the new updated firmware when using enable_uart=1
it supposed to solve this problem
I can’t help you much than say that UART1 is not the same as UART0, if you want to go faster, use USB dongle for Bluetooth, and use UART0 that is OK.
Hi, its great tutorial you have here.
I have followed the same step 1 for the A2dp connection but I’m encountering some problems:
1. The file that you gave in the description is stoping while playing i.e. the frames are not coming continuously.
2. I am not able to run other files. My pi is giving an error “Cannot run the file”.
Please help out. I need it soon. Any suggestions might help.
–thanks for the help.
Hi,
1. This is a performance problem, I guess you are using both Bluetooth and WiFi? If yes, try to use wired connection that solved the cut problem.
2. I think you are trying to open different file format (mp3, wav,…etc) that is not supported by PulseAudio.
Yes, I was using WiFi with Bluetooth. I’ll try it again without WiFi now.
I also see that many people have pointed out that the connection is lost after 15 to 20 seconds. Is there any method to connect to the headset without getting disconnected for a longer time period. This will really help me a lot. Thanks.
I don’t have this problem in latest versions of Raspbiam and PulseAudio.
Can you try this modification:
sudo nano /etc/pulse/daemon.config
Uncomment (remove the ; in) the line and put negative value (-1):
exit-idle-time = -1
Can you suggest a way to do all this using python code and play audio in the background process?
I’m sorry I don’t have the hardware now. For sure I’ll write a script but it will be later 🙁
Worked like a charm with bluetooth USBdongle, Kingone K5 handsfree speaker and mplayer
Just one issue:
– the pulseaudio daemon keeps diconnecting if not used of about 15 seconds, which gives little time to launch audio
– how to test if also microphone is running?
Hi Lukas,
You can check the microphone with my new tutorial:
http://youness.net/raspberry-pi/bluetooth-headset-raspberry-pi-3-ad2p-hsp
after doing this, my bluetooth is not working. it shows no adapter found. please help me to restore it as before.
What did you do exactly?
I tried both, index and name, it was working, suddenly it stopped working for hsp/hfp profile.
[…] Connect Bluetooth Headset To Raspberry Pi 3 […]
Hi,
Reason why you are not able to use default BT on RPI-3 is because its firmware routes SCO data over PCM/I2s but not UART and I beleive there is no PCM/I2S connection between BT chip and Broadcom AP, resulting in SCO not working.
Using vendor specific commands, SCO routing can be changes to use HCI.
But when i tried this and started sCO, i could see SCO data on HCI interface, but frequent H4 re-assembly errors are seen. This i believe is due to no HW flow control (RTS/CTS) used on BT UART.
Any ideas on how to enable HW flow control enabled on BT UART ? As once this is done, default BT chip can be used for SCO activities also.
I couldn’t have any help on that on Cypress forums (they are supporting Broadcom chips but not when included in products like Raspberry Pi).
Your comment is interesting and I gave this area some time (SCO, H4,…), but I find it a waste of time because no official documentation to figure it out, and no Raspberry Pi internal routing schematics…
Did you check if it is possible to assign mannually Raspberry Pi UART or not?
If you have any progress please let me know it.
I tried configuring RTS and CTS in the dts file, and btuart script even deteced them and started hciattach with 3Mbps and flow control, but behaviour of h4 errors still persists. More details can be found in my query posted in forums, but no responses till now.
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=186689&p=1178458
That is where i got blocked and looked at your forum to get BT working using Dongle and continued till flow issue can be resolved.
Thanks for your work with the bluetooth headset. I wonder if you could adapt this to work as a “wireless” microphone/headset. I have not seen how to receive the microphone button contact into the RPi. My ultimate goal would be to receive and transmit over wifi to another raspberry pi that has a full duplex sound dongle and using a gpio pin driven by the bluetooth microphone button, key a radio transmitter (tx/rx). the sound dongle audio out is for radio transmit, and the dongle audio in is for receive.
Ham Radio Operators would love this.
If you mean streaming audio with Wi-Fi, it is a very different topic and unfortunately I’m not familiar with it 🙁
Thank you very much for your work.But i am getting a error.My bluetooth headset get paired and trused.But after that when i am trying to connect it , after connecting it gives me this error -“Failed to connect: org.bluez.Error.NotAvailable” and get disconnected.Even after starting pulse audio it gives me the same error.Please help me…
Hey,
I was wondering if you know how to make the Pi receive “commands” from the headphone buttons.
For example, make Pi to execute a command or script when the “play/pause” button is clicked, or the next/prev button on the headphone and so on.
Any help is much appreciated as I have no idea where I should go after connecting my bluetooth headphone.
Hi,
I have tried to follow the exact procedure on my RPI3 but I always get only 1 card listed when I execute the command “pacmd list-cards”.
What could be the possible reason for this?
Hi,
Please follow the new tutorial here http://youness.net/raspberry-pi/bluetooth-headset-raspberry-pi-3-ad2p-hsp and let me know if you still have issues.
Please guide me to connect a bluetooth speaker along with built-in microphone to pi zero W. It runs on Raspbian Stretch OS. Speaker works fine but microphone isn’t working. Kindly help.
Cheers,
I didn’t use the Zero, but you can try steps here: http://youness.net/raspberry-pi/how-to-connect-bluetooth-headset-or-speaker-to-raspberry-pi-3
You saved my day. Was looking for this since last few weeks and finally I am able to connect to Raspberry
Note that `libjson0-dev` is deprecated in Raspbian Stretch. `sudo apt-get -y install libjson-c-dev` should install the same dependencies as a work-around.
Thanks for the information.
Can I use a microphone and speaker at the same time. If my Bluetooth speaker have both.
Yes you can, please check my other posts: http://youness.net/raspberry-pi/how-to-connect-bluetooth-headset-or-speaker-to-raspberry-pi-3
I’ve a JBL GO2 speaker with microphone. Speaker is working with poor quality and microphone is not detected. Any help is appreciated for making microphone working in raspberry pi.
Pi Model 4B V1.2 is my model.
Buy a dongle if you want a quick solution.