Bluetooth Audio Receiver / A2DP Sink with Raspberry Pi

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.

  1. Start by install / updating all the packages
  2. Add users to groups. This is very important. If using any other distro, replace ‘xbian’ with your username.
  3. Set up PulseAudio, Bluetooth Device Class

    The Bluetooth service/device class 0x200420 mean the device is set up for Car Audio. See this link to explore more Bluetooth Class options.

  4. To pair with a device, we will need to use the “bluetoothctl” tool.
  5. Set the agent to KeyboardOnly and make it default. This needs to be done once only. Inside bluetoothctl, run the following commands:
  6. Turn on bluetooth on your phone/tablet and make sure it is discoverable. Run the following commands inside bluetoothctl:

    xx: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.

  7. 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.
  8. 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!

26 thoughts on “Bluetooth Audio Receiver / A2DP Sink with Raspberry Pi”

  1. Hello,

    Thanks for this how-to but I have a problem with the class. It is not
    0x200420 but 0x000000 :/
    I’m using the onboard bluetooth device on a PI3

    pi@LHC_V5:~$ sudo bluetoothctl
    [NEW] Controller B8:27:EB:7A:13:0C LHC_V5 [default]
    [bluetooth]# show
    Controller B8:27:EB:7A:13:0C
    Name: LHC_V5
    Alias: LHC_V5
    Class: 0x000000
    Powered: yes
    Discoverable: no
    Pairable: yes

    Thanks

    1. Hi Sylvain,

      1. You can set the class to 0x200420 again with:
      > sudo hciconfig hci0 class 0x200420
      2. Verify that it is set correctly with bluetoothctl
      3. Remove the Raspberry Pi from your handset and pair again.

      The pairing should work immediately without any actions from Raspberry Pi as the device is already trusted.

  2. Thanks for answer, in fact maybe I’m making a mistake, I’d like to use my PI 3 as audio receiver. I’ve got a DAC Hifiberry Amp+ on it and I’d like to pair my android phone for playing music with Spotify

    Sylvain

  3. Hi,
    I managed to set it up, thanks, but the class changed when I reboot the PI :
    hciconfig -a :
    Class: 0x000420
    Service Classes: Unspecified
    Device Class: Audio/Video, Car Audio

    🙁

    1. I am not facing the same issue, I wonder why? :/
      Perhaps you can try to run the “hciconfig hci0 class 0x200420” using a startup script?

    2. I had same issue on Arch Linux, so I installed pulseaudio-bluetooth, reboot, and now appears as 0x0c0420. This is working good.

  4. Thanks for writing up such concise instructions on how to connect and operate the Pi as a Bluetooth sink. Unfortunately, there seems to be an issue with the instructions now (hardware revision? later release of Raspbian?).
    When following your instructions I run into a couple problems during the pairing process. First, I get a pop up saying “Device has requested a pairing. Do you accept the request?”. If I click “OK” I get the error message “Connection failed – GDBus.Error:org.bluez.Error.Failed: No such file or directory. Try to connect manually.”
    If I then try to connect through bluetoothctrl I get the following:
    “Attempting to connect to XX:XX:XX:XX…
    “Failed to connect: org.bluez.Error.Failed”
    These look to be similar to the issues the other user is having. Any thoughts?
    Running Raspbian Jessie May 2016 Version, release 2016-05-27, kernel 4.4 on R PI 3 B ver 1.2

    1. Update:
      I tried following the instructions with a Xbian image and appear to have had more success. Problem being now that there just isn’t any audio.

  5. Very good instructions, however I haven’t been able to get audio to play from my iPhone on the RPi. I was able to pair with my phone and connect to the RPi, but audio still comes out of the phone. I am using Raspian 8 and bluez 5.23 on a Raspberry Pi 3. I am able to pair and connect with the phone, and I have verified that audio is working on the RPi by playing a test mp3 file using the play command from the sox package.

    $ sudo hciconfig -a
    hci0: Type: BR/EDR Bus: UART
    BD Address: B8:27:EB:BC:64:3C ACL MTU: 1021:8 SCO MTU: 64:1
    UP RUNNING PSCAN ISCAN
    RX bytes:14338 acl:291 sco:0 events:342 errors:0
    TX bytes:12808 acl:276 sco:0 commands:125 errors:0
    Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
    Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
    Link policy: RSWITCH SNIFF
    Link mode: SLAVE ACCEPT
    Name: ‘raspberrypi’
    Class: 0x200420
    Service Classes: Audio
    Device Class: Audio/Video, Car Audio
    HCI Version: 4.1 (0x7) Revision: 0xb6
    LMP Version: 4.1 (0x7) Subversion: 0x2209
    Manufacturer: Broadcom Corporation (15)

    $ sudo bluetoothctl
    [bluetooth]# show
    Controller B8:27:EB:BC:64:3C
    Name: raspberrypi
    Alias: raspberrypi
    Class: 0x200420
    Powered: yes
    Discoverable: yes
    Pairable: yes
    UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
    Modalias: usb:v1D6Bp0246d0517
    Discovering: no
    [bluetooth]# devices
    Device D8:BB:2C:E5:8E:29 Rimadyl
    [bluetooth]# info D8:BB:2C:E5:8E:29
    Device D8:BB:2C:E5:8E:29
    Name: Rimadyl
    Alias: Rimadyl
    Class: 0x7a020c
    Icon: phone
    Paired: yes
    Trusted: yes
    Blocked: no
    Connected: yes
    LegacyPairing: no
    UUID: Vendor specific (00000000-deca-fade-deca-deafdecacafe)
    UUID: Service Discovery Serve.. (00001000-0000-1000-8000-00805f9b34fb)
    UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
    UUID: NAP (00001116-0000-1000-8000-00805f9b34fb)
    UUID: Handsfree Audio Gateway (0000111f-0000-1000-8000-00805f9b34fb)
    UUID: Phonebook Access Server (0000112f-0000-1000-8000-00805f9b34fb)
    UUID: Message Access Server (00001132-0000-1000-8000-00805f9b34fb)
    UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
    Modalias: bluetooth:v004Cp6E00d0930

  6. Never mind. I figured it out. pulseaudio wasn’t starting due to a problem with the script start-pulseaudio-x11. I haven’t figured out how to fix that problem yet, but if I start pulseaudio manually I am able to connect and play music from my phone.

    Thanks for this great how-to!

      1. Ok i figured out how to start it manually. The only problem is that as soon as I execute the command, my machine becomes completely unresponsive.

        pi@raspberrypi:~ $ pulseaudio –start
        |<–blinking

        and stays like that forever. Help?

  7. Thank you for this tutorial! It is a very useful feature to have and there are no recent tutorials.

    I’ve followed the instructions, but my phone does not connect to the raspberry pi. The raspberry pi shows up under the bluetooth devices after being paired, however a connection is not made when clicking in.

    PS, my phone is android, and the gear icon next to the raspberry pi device gives no options other than to ‘forget’ the device.

    Please help

  8. Thanks, this worked well. One thing to note is that you have to disable wifi for the Pi3 to stream music without any stuttering.

    sudo ifconfig wlan0 down

    You can also set it up to auto-connect to your bluetooth device by adding a line to /etc/rc.local.

    echo “connect [MAC address of device] /nquit” | bluethoothctl

  9. I have the my iphone and the pi paired and it says they are connected but the audio wont come through the pi’s audio jack. I’m using the 0x200420 class. If anyone can point me in the right direction that’d be great

    1. It a problem with your internal wifi. If you are using internal BT and wifi, the sound starts stuttering. Disable wifi – problem will be fixed

  10. Hey thanks for the posts! It’s nice to see many people working together with the pi.

    Like you said many write ups are outdated. We currently have a project that does essentially what you have done but uses an installation script to do everything for those who are afraid of the cli.

    The project sets the pi up as an audio receiver and includes auto pairing when a device tries to connect, Streams music via a2dp, device controlled volume, AirPlay functionality for audio, and aux line input. It also sets up the necessary sounds cards. The project currently has 2 versions, one for use when no wireless network is available and another that piggy backs off an existing wireless network.

    You can find them here:
    https://github.com/BaReinhard/Raspberry-Pi-Audio-Receiver-Install-Car-Install

    The install is the best part and super simple.

  11. Hi and thanks for the instructions.
    I just wanted to ask if there is a way to autoconnect new phones without commands on the pi.

    1. There is, I suggest looking into my project here:

      https://github.com/BaReinhard/Raspberry-Pi-Audio-Receiver-Install-Car-Install

      Specifically look at the bluetooth or bt_pa files they should outline it if you have a decent grasp on pulse audio and bluetooth. If not, I would suggest using my project on a fresh Raspbian Jessie Image. If you don’t want all that is included change the runall.sh and remove the lines that install the functions that you don’t want.

Leave a Reply

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