Connect Bluetooth Headset To Raspberry Pi 3 (A2DP and HSP)

Hardware components:
Pi 3 02
Raspberry Pi 3 Model B
× 1
ASUS USB-BT400
× 1
Phillips SHB5600
× 1
Software apps and online services:
Raspberry Pi Raspbian Jessie

Connect Bluetooth Headset To Raspberry Pi 3 (A2DP and HSP)

STORY

This post was initially published in my blog: http://youness.net/raspberry-pi/bluetooth-headset-raspberry-pi-3-ad2p-hsp

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 into 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 series of puzzle pieces that I’m still collecting over all the 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 kept my previous post for history (no longer updating): http://youness.net/raspberry-pi/bluetooth-headset-raspberry-pi

With all that effort, I start to have a 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 the built-in WiFi-Bluetooth chipset: BCM43438 (and/or its driver/firmware)

How do I know? Because I used an 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 a Bluetooth USB dongle.

I know that some people may just want to know how to do it, and don’t care about details, so I’ll explain first how to make it. Then I’ll post the exhaustive story behind this Bluetooth/Raspberry Pi issue, in order to help others who want to explore more.

HOW

Step 1: PulseAudio

One problem that is mentioned everywhere is the drop out of Bluetooth support by ALSA. Now only way is PulseAudio. Source: https://git.kernel.org/pub/scm/bluetooth/bluez.git/commit/?id=4ff9b99292eca193dc0c149722328cb0b1ab0818

Minimal versions needed for HSP (A2DP included) are: Bluez 5 / PulseAudio 6 Source: https://www.freedesktop.org/wiki/Software/PulseAudio/Notes/6.0/

I recommend starting with a fresh Raspbian Jessie image: https://www.raspberrypi.org/downloads/raspbian/

Update and upgrade it:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get autoremove
sudo reboot

Check the version of packages:

dpkg -l bluez
dpkg -l pulseaudio

Purge pre-installed PulseAudio:

sudo apt-get purge pulseaudio

To install manually PulseAudio 6 or higher, 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 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 higher 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:

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

Run bootstrap script:

./bootstrap.sh

I will sum up here all the errors I encountered (in case people search them by copy/paste):

./bootstrap.sh: line 46: intltoolize: command not found

So install all of the following libraries:

sudo apt-get install intltool libtool libcap-dev libjson0-dev libsndfile1-dev

The script should now end 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, grab a coffee).

sudo make

The last command to avoid 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

Add lines:

blacklist btbcm blacklist hci_uart

CTRL+X, then Y, then Enter. Reboot:

sudo reboot

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 the USB dongle is from Broadcom (BCM). Broadcom’s firmwares are proprietary, which means that they aren’t shared as open source and sometimes are not in Linux repositories. So to use it, you have to find the corresponding .hcd file and store it in /lib/firmware folder.

An 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/

Unzip it:

sudo apt-get install zip

Open .inf file of the drivers and look for ASUS

cd BTW6.5.1.6000_Win7_USB_ASUS/Win32/
cat bcbtums-win7x86-brcm.inf

Search for the driver supporting your hardware. For ASUS BT400, I find the corresponding file: BCM20702A1_001.002.014.1315.1347.hex

Because it is .hex, I need to convert it to .hcd. I’ll use the hex2hcd tool:

cd /home/pi/Desktop

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 By CFLAGS = -mcpu=cortex-a53 -mfpu=neon-vfpv4 

Source: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=139091&p=922980

Redo make command. Now you have the executable hex2hcd:

cp /home/pi/Downloads/BTW6.5.1.6000_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 the .hcd file – it is the same one missing in the above error with:

dmesg | grep -i bluetooth

Copy it to the firmware folder, reboot, and check Bluetooth initiation:

sudo cp BCM20702A1-0b05-17cb.hcd /lib/firmware/brcm/
sudo reboot
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:

Read More: Connect Bluetooth Headset To Raspberry Pi 3 (A2DP and HSP)


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *