Connect Bluetooth Headset To Raspberry Pi 3 (AD2P only).
If you are here, it means that you are trying to use your headset’s microphone AND speakers with Raspberry Pi 3.
What appeared to be a configuration issue turned to a real headache. After so many weekends spent to find a solution, I ended up with a lot of information and no workaround, a sort of puzzle parts that I’m still collecting over all Google results, I’m not exaggerating if I tell you that I already read every single page that Google can propose for this topic.
I keep my previous post for history (not anymore updated): http://youness.net/raspberry-pi/bluetooth-headset-raspberry-pi
With all that effort, I start to have clear idea of the problem. So here you will save your time and focus on the major root cause.
Long story short: The real problem comes from built-in WiFi-Bluetooth chipset: BCM43438 (and/or its driver/firmware)
How do I know it?
Because I used external Bluetooth transceiver (USB dongle), and now my headset works perfectly (AD2P & HSP)
So, unless I find THE ideal solution, you have no choice but to use Bluetooth USB dongle.
I know that some people may just want to know how to do, and don’t care about details, so I’ll explain first how to make it.
Then I’ll post exhaustive story behind this Bluetooth/Raspberry Pi issue, in order to help others who want to explore more.
HOW TO DO
Step 1: PulseAudio
One problem that is mentioned everywhere is the drop out of Bluetooth support by ALSA. Now only way is PulseAudio.
Minimal versions needed for HSP (A2DP included) are: Bluez 5 / PulseAudio 6
I recommend to start with fresh Raspbian Jessie image:
Update and upgrade it:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get autoremove
Check the version of packages:
dpkg -l bluez
dpkg -l pulseaudio
WARNING: Raspbian repository is still using PulseAudio 5
Purge pre-installed PulseAudio:
sudo apt-get purge pulseaudio
To install manually PulseAudio 6 or upper, there are two methods and both of them are OK.
Method 1: Install PulseAudio from Debian Backports
Edit source list:
sudo nano /etc/apt/sources.list
Add the line:
deb http://ftp.debian.org/debian jessie-backports main
Add PGP keys to your Raspberry Pi:
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 --
Update package list:
sudo apt-get update
Install PulseAudio and its Bluetooth module:
sudo apt-get -t jessie-backports install pulseaudio pulseaudio-module-bluetooth
Check the version (6 or upper is OK):
dpkg -l pulseaudio pulseaudio-module-bluetooth
ii pulseaudio 7.1-2~bpo8+1
ii pulseaudio-module-blue 7.1-2~bpo8+1
You can jump directly to Step 2.
Method 2: Use PulseAudio sources
Download the sources from Freedesktop.org:
Unzip and go to the directory:
tar xvf pulseaudio-6.0.tar.xz
Run bootstrap script:
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 PulseAudio (this will take some time, take a coffee).
sudo make install
The last command to avoid some errors of shared libs not found.
Step 2: Bluetooth Hardware
To turn off built-in Bluetooth controller (BCM43438), blacklist it:
sudo nano /etc/modprobe.d/raspi-blacklist.conf
CTRL+X, then Y, then Enter
Now connect your Bluetooth USB dongle, mine is ASUS BT400.
(At this step, the result may differ, maybe your USB dongle is already supported by Raspbian)
For ASUS BT-400, I have to install manually the firmware.
To know if your hardware is correctly called, check it here:
dmesg | grep -i bluetooth
In my case I see the error:
[ 155.924366] bluetooth hci0: Direct firmware load for brcm/BCM20702A1-0b05-17cb.hcd failed with error -2
Here I need to explain some things. The chipset in USB dongle is from Broadcom (BCM)
Broadcom’s firmwares are proprietary, it means that they are’nt shared as open source, and some times not in Linux repositories.
So to use it, you have to find corresponding .hcd file and store it in /lib/firmware folder.
Easy way is to download ASUS drivers online:
wget http://dlcdnet.asus.com/pub/ASUS/wireless/USB-BT400/UT_USB_BT400_6516000.zip -P /home/pi/Downloads/
sudo apt-get install zip
Open .inf file of the drivers and look for ASUS
Search for the driver supporting your hardware. For ASUS BT400 I find the corresponding file:
Not that it is .hex, so I need to convert it to .hcd, I’ll use hex2hcd tool:
sudo apt-get install git
git clone https://github.com/jessesung/hex2hcd.git
Here I meet error due to Raspberry Pi configuration
gcc -O2 -march=native hex2hcd.c -o hex2hcd
*** Error in `gcc’: double free or corruption (top): 0x015fdc58 ***
<builtin>: recipe for target ‘hex2hcd’ failed
make: *** [hex2hcd] Aborted
so I modify the Makefile:
sudo nano Makefile
Replace the line:
CFLAGS = -O2 -march=native
CFLAGS = -mcpu=cortex-a53 -mfpu=neon-vfpv4
make command, now you have the executable hex2hcd:
cp /home/pi/Downloads/BTW188.8.131.5200_Win7_USB_ASUS/Win32/BCM20702A1_001.002.014.1315.1347.hex /home/pi/Desktop/hex2hcd/
./hex2hcd BCM20702A1_001.002.014.1315.1347.hex BCM20702A1-0b05-17cb.hcd
Pay attention here to the name of .hcd file, it is the same one missing in above error with
dmesg | grep -i bluetooth
Copy it to firmware folder, reboot, and check Bluetooth initiation:
sudo cp BCM20702A1-0b05-17cb.hcd /lib/firmware/brcm/
dmesg | grep -i bluetooth
The firmware should be correctly called now!
Now we will connect the Bluetooth headset (same steps as for A2DP only post)
Start Bluetoothctl tool and initiate everything:
Turn on the headset, for mine I press and hold the button till I see white blinking LED.
Start the scan:
After some seconds, you will see the headset name and MAC address (xx:xx:xx:xx:xx:xx)
Pair, trust and connect it:
Now the headset is correctly connected to the Raspberry Pi.
If not, it should be PulseAudio daemon that it is not already running.
Open new console and start it:
Go back to the other console and connect again the headset:
Now the headset is connected!
Check cards in PulseAudio:
pactl list cards
You can see the Bluetooth card, and the profiles A2DP and HSP available.
For me the default profile was headset_head_unit, if it is not for you, force it:
pacmd set-card-profile 1 headset_head_unit
Tell PulseAudio to use the headset as default “sink” and “source”:
pacmd set-default-sink bluez_sink.xx_xx_xx_xx_xx_xx
pacmd set-default-source bluez_source.xx_xx_xx_xx_xx_xx
Record yourself with the microphone:
parecord -v voice.wav
CTRL+C to end it.
Play it back:
paplay -v voice.wav
Are you listening to your voice?!
Final check that A2DP is also working, activate it:
pacmd set-card-profile 1 a2dp_sink
paplay -v voice.wav
Your voice again, that’s all.
This tutorial will for work for any Bluetooth USB dongle that you can find the ASUS driver sources.
If you have any question or remark, feel free to ask me by comment.
THE STORY WHY RASPBERRY PI BLUETOOTH IS NOT WORKING
This part is ongoing because every day I’m learning new things about Bluetooth profiles, hardware architecture, IP issues, …etc.
The aim here is not to blame the Raspberry Pi, but to understand why it is NOK and how to correct it.
Because at the of the day we want to do it by the board only without external add-ons.
Until this, I recommend to use Bluetooth USB dongles if you want to have HSP profile.
Some quick notes and questions:
- Raspberry Pi uses Broadcom BCM43438 “combo” shipset for Wi-Fi and Bluetooth
- Broadcom firmwares are proprietary, not all the time coming with Linux distributions
- Apparently, BCM43438 firmware is the same as BCM43430 (but how to be sure…)
- People report that the use of Wi-Fi & Bluetooth leads to poor audio quality and slow connection
- Raspberry Pi Zero Wi will have the same problem ( same BCM 43438)
- What is the architecture of Raspberry Pi wireless (I know it is not Open Source…)?
- What are the buses and protocols used (HCI, UART, SCO, SDIO…)?
- Did anyone checked that Bluetooth audio will work before agreeing this hardware at Raspberry Pi Foundation?
- Why the BCM43438 is not mentioned in Raspberry Pi hardware list (in the website)?
To be continued.