After much trial and error, I have managed to configure Raspberry Pi to function as a Bluetooth Audio Receiver, also known as A2DP Sink mode.
Much of the articles and configurations on the web are for older version of Debian (<=7.x) which worked correctly with older versions of PulseAudio (<=4.x), Alsa & Bluez (<=4.x).
The following configuration has been tested with latest release of Xbian, which is based on Debian Jessie (8.0) and Raspberry Pi 3, which comes with a built-in bluetooth module. Other compatible bluetooth modules should work as well.
- Start by install / updating all the packages
123sudo apt-get updatesudo apt-get upgradesudo apt-get install pulseaudio-module-bluetooth bluez-tools - Add users to groups. This is very important. If using any other distro, replace ‘xbian’ with your username.
12345sudo gpasswd -a xbian pulsesudo gpasswd -a xbian lpsudo gpasswd -a pulse lpsudo gpasswd -a xbian audiosudo gpasswd -a pulse audio - Set up PulseAudio, Bluetooth Device Class
1234sudo sh -c "echo 'extra-arguments = --exit-idle-time=-1 --log-target=syslog' >> /etc/pulse/client.conf"sudo hciconfig hci0 upsudo hciconfig hci0 class 0x200420sudo rebootThe Bluetooth service/device class 0x200420 mean the device is set up for Car Audio. See this link to explore more Bluetooth Class options.
- To pair with a device, we will need to use the “bluetoothctl” tool.
1sudo bluetoothctl - Set the agent to KeyboardOnly and make it default. This needs to be done once only. Inside bluetoothctl, run the following commands:
12agent KeyboardOnlydefault-agent - Turn on bluetooth on your phone/tablet and make sure it is discoverable. Run the following commands inside bluetoothctl:
1234scan onpair xx:xx:xx:...trust xx:xx:xx:...exitxx:xx:xx:.. is the MAC address of your handset/device. After running ‘scan on’, wait a minute for your device to show up along with it’s MAC address. After running ‘pair xx:xx:xx:..’ check your device and accept the incoming connection. Do the same on terminal by typing yes.
- Now connect to the Raspberry Pi from your handset and it should connect as an audio device. All audio played through the device should now be output using Raspberry Pi’s HDMI or Analog out depending on your Pi’s configuration.
- If the connection fails, try again, sometimes it takes 2 attempts.
That is all for now. Please test the above instructions and post your results in the comments below. Enjoy!