Software apps and online services
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.
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
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:
Unzip and go to the directory:
tar xvf pulseaudio-6.0.tar.xz
Run bootstrap script:
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
./ bootstrap, now missing parts are enabled.
Then, make and install PulseAudio (this will take some time, grab a coffee).
The last command to avoid errors of shared libs not found.
To turn off built-in Bluetooth controller (BCM43438), blacklist it:
sudo nano /etc/modprobe.d/raspi-blacklist.conf
blacklist btbcm blacklist hci_uart
CTRL+X, then Y, then Enter. 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/
sudo apt-get install zip
Open .inf file of the drivers and look for ASUS
cd BTW220.127.116.1100_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:
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
make command. Now you have the executable hex2hcd:
cp /home/pi/Downloads/BTW18.104.22.16800_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)
Bluetoothctl tool and initiate everything:
Turn on the headset, for mine I press and hold the button till I see a 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
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
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.
This part is ongoing because everyday 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 NOT working 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 using 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 W 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 to use this hardware at the Raspberry Pi Foundation?
- Why is the BCM43438 not mentioned on the Raspberry Pi hardware list (on the website)?
To be continued.