105 Responses

  1. Peter at | | Reply

    Hi,
    I tried your steps on Raspberry Pi Zero and Orange Pi Zero with USB Bluetooth dongle and I have the same problem on both devices:
    [bluetooth]# connect 00:E0:4C:1B:22:F9
    Attempting to connect to 00:E0:4C:1B:22:F9
    Failed to connect: org.bluez.Error.Failed

    grep -i bluetooth /var/log/syslog :
    localhost bluetoothd[436]: Sap driver initialization failed.
    localhost bluetoothd[436]: sap-server: Operation not permitted ( 1)
    localhost NetworkManager[440]: Loaded device plugin: /usr /lib/arm-linux-gnueabihf/NetworkManager/libnm-device-plugin-bluetooth.so
    localhost bluetoothd[436]: Confirm name timed out for hci0
    localhost bluetoothd[436]: a2dp-sink profile connect failed for 00:E0:4C:1B:22:F9: Protocol not available

    Can you please help me ?

    1. Guillaume at | | Reply

      Hello Peter and Younes

      I followed instructions, but I have the same issue with RPI3(Stretch) + Asus BT400 (Like Younes)

      pi@rpi3:~ $ sudo bluetoothctl
      [NEW] Controller 5C:F3:70:87:0A:04 rpi3 [default]
      [NEW] Device 78:44:05:99:8B:18 JBL GO
      [bluetooth]# connect 78:44:05:99:8B:18
      Attempting to connect to 78:44:05:99:8B:18
      Failed to connect: org.bluez.Error.Failed

      Syslog shows “a2dp-sink profile connect failed for 78:44:05:99:8B:18: Protocol not available”
      pi@rpi3:~ $ grep -i bluetooth /var/log/syslog
      Nov 25 15:15:23 rpi3 systemd[1]: Failed to start Configure Bluetooth Modems connected by UART.
      Nov 25 15:15:23 rpi3 systemd[1]: Starting Bluetooth service…
      Nov 25 15:15:23 rpi3 bluetoothd[460]: Bluetooth daemon 5.43
      Nov 25 15:15:23 rpi3 systemd[1]: Started Bluetooth service.
      Nov 25 15:15:23 rpi3 systemd[1]: Reached target Bluetooth.
      Nov 25 15:15:23 rpi3 bluetoothd[460]: Starting SDP server
      Nov 25 15:15:23 rpi3 kernel: [ 9.453486] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
      Nov 25 15:15:23 rpi3 kernel: [ 9.453494] Bluetooth: BNEP filters: protocol multicast
      Nov 25 15:15:23 rpi3 kernel: [ 9.453512] Bluetooth: BNEP socket layer initialized
      Nov 25 15:15:23 rpi3 bluetoothd[460]: Bluetooth management interface 1.14 initialized
      Nov 25 15:15:23 rpi3 bluetoothd[460]: Failed to obtain handles for “Service Changed” characteristic
      Nov 25 15:15:23 rpi3 bluetoothd[460]: Sap driver initialization failed.
      Nov 25 15:15:23 rpi3 bluetoothd[460]: sap-server: Operation not permitted (1)
      Nov 25 15:16:22 rpi3 bluetoothd[460]: a2dp-sink profile connect failed for 78:44:05:99:8B:18: Protocol not available

      I think Bluetooth USB is well installed

      pi@rpi3:~ $ dmesg | grep -i bluetooth
      [ 3.099600] Bluetooth: Core ver 2.22
      [ 3.099692] Bluetooth: HCI device and connection manager initialized
      [ 3.099712] Bluetooth: HCI socket layer initialized
      [ 3.099726] Bluetooth: L2CAP socket layer initialized
      [ 3.099763] Bluetooth: SCO socket layer initialized
      [ 3.148879] Bluetooth: hci0: BCM: chip id 63
      [ 3.164883] Bluetooth: hci0: BCM20702A
      [ 3.165849] Bluetooth: hci0: BCM20702A1 (001.002.014) build 0000
      [ 5.063897] Bluetooth: hci0: BCM20702A1 (001.002.014) build 1347
      [ 5.079898] Bluetooth: hci0: Broadcom Bluetooth Device
      [ 9.453486] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
      [ 9.453494] Bluetooth: BNEP filters: protocol multicast
      [ 9.453512] Bluetooth: BNEP socket layer initialized

      PulseAudio is started
      pi@rpi3:~ $ ps aux | grep pulseaudio
      pi 696 0.0 0.0 4372 532 pts/0 S+ 15:18 0:00 grep –color=auto pulseaudio

      pi@rpi3:~ $ dmesg log | grep -i bluetooth
      [ 3.099600] Bluetooth: Core ver 2.22
      [ 3.099692] Bluetooth: HCI device and connection manager initialized
      [ 3.099712] Bluetooth: HCI socket layer initialized
      [ 3.099726] Bluetooth: L2CAP socket layer initialized
      [ 3.099763] Bluetooth: SCO socket layer initialized
      [ 3.148879] Bluetooth: hci0: BCM: chip id 63
      [ 3.164883] Bluetooth: hci0: BCM20702A
      [ 3.165849] Bluetooth: hci0: BCM20702A1 (001.002.014) build 0000
      [ 5.063897] Bluetooth: hci0: BCM20702A1 (001.002.014) build 1347
      [ 5.079898] Bluetooth: hci0: Broadcom Bluetooth Device
      [ 9.453486] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
      [ 9.453494] Bluetooth: BNEP filters: protocol multicast
      [ 9.453512] Bluetooth: BNEP socket layer initialized

      Do you know how to solve this issue ?

      Regards

      G.

      1. Guillaume at | | Reply

        OK I find the issue. I add the pi user to lp group
        sudo usermod -a -G lp pi

  2. windyfly at | | Reply

    I got error requesting gpg keys. It says the key can’t be retrieved, no valid OpenPGP data found.

    Find the following cmd works.

    sudo apt-key adv –recv-key –keyserver pgpkeys.mit.edu

    You may also want to query over typical port 80

  3. Phil at | | Reply

    Hi, thanks a lot for posting this instruction set. I am going to buy a raspberry pi in the very near future in order to replicate this project. I have been trying to find a dedicated bluetooth Tx/Rx with onboard sound for a while, to no avail. I thought raspberry pi might be a solution; so was very grateful to stumble across your post.

  4. Diego at | | Reply

    Mate you are legend!!! Thank you for sharing you collected knowledge in this post.

  5. b789 at | | Reply

    Hi, thank for this post, it helped a lot in making my headset working as ad2p sink to listen music.
    Still the built in play/pause buttons on the headset aren’t working. I kinda undertand that AVRCP is needed for this to work but i didn’t undertand what exactly it is and if there is any chance of getting it working on the raspberry. Do you have any hint in this regard ?

  6. Alex at | | Reply

    Hello Youness, everything was working fine until the very end: when I attempt to pair the headset, it tells me that: “failed to connect to device – could not connect to PulseAudio. try to connect again.” I tied pulseaudio –start, but the same error comes up. Any thoughts?

    1. Alex at | | Reply

      Further to above, I got further now (had to do a clean install of Raspbian 8), but now when I run:
      pacmd set-default-source bluez_source.xx_xx_xx_xx_xx_xx (I used the actual MAC address)
      I get a response:
      Source bluez_source.xx_xx_xx_xx_xx_xx does not exist
      The sink command (pacmd set-default-sink bluez_sink.xx_xx_xx_xx_xx_xx) worked.

  7. Emil Borconi-Szedressy at | | Reply

    Just to give you a 3rd method as well.

    Add stretch source to the sources and install/update pulseaudio & bluez will work nicely. If you dare you can do a full system upgrade as well but you might end up with some things not working.

    1. khoa at | | Reply

      hi,
      would you mind giving more details ?
      Or tutorial ?

      thank you

  8. Harvey King at | | Reply

    1.  Thank you. your blog is one of most useful instruction on this subject matter.
    2. Want to add something. I am using original Raspberry Pi 1 (instead of Raspberry Pi3). Apparently jessie-backport from debian is not compatible with this hardware, so I had to compile pulseaudio on my own. While I running the bootstrap, I noticed that the configuration script failed to detect bluez and udev.

    Upon further research, I noticed that you need to install additional development packages
    libltdl-dev libsamplerate0-dev libsndfile1-dev libglib2.0-dev libasound2-dev libavahi-client-dev libspeexdsp-dev liborc-0.4-dev libbluetooth-dev intltool libtdb-dev libssl-dev libudev-dev libjson0-dev bluez-firmware libbluetooth-dev libsbc-dev libcap-dev

    Once these packages installed, then, the configure script detect bluez and udev successfully.

    3. Then, I run into problem. Please help.
    Once I compiled and installed it, and when I run anything related to pulseaudio, I got an error.  The error is tricky, that if I simply run pulseaudio as a regular user, it will give me “illegal instruction.” If I try to use superuser to execute pulseaudio, it will simply exit the program without giving out any error message.

    So, I simply typed “gdb pulseaudio”

    and it give me this error Illegal instruction error
    0xb6950e30 in ?? () from /usr/lib/arm-linux-gnueabihf/pulseaudio/libpulsecommon-7.1.so

    this library is part of the pulseaudio library I compiled and installed, so I am a bit confused.

    (yes, I compiled and installed Pulseaudio 7.0… I tried 6.0 and gave me the same error so I thought I might give 7.0 a try since installing via backports method also installs version 7.0)

    and, fyi, using method one to install pulseaudio 7 also give me this error.

    Any idea what went wrong?

    Thanks in advance

  9. Harvey King at | | Reply

    Never mind the 3rd point. It was my mistake by trying the jessie-backports repository and that repository only supports ARMv7 instruction sets while my raspberry pi uses ARMv6 CPU. Since I massively updated my system using jessie backports thus many software are no longer usable. I have to reinstall everything again.

    Thanks.

    Your instruction is clearest so far in terms of explaining why you do things certain way, thus, very helpful. I am still trying to install pulseaudio so I don’t know my next steps are. Conceptually, though, I am a bit confused. It seems that pulseaudio need to connect to the alsa somehow anyway.

    if u have extra time, do consider explain this to rest of us?

    much appreciated.

  10. Irvaan Sid at | | Reply

    Currently,I’m trying to implement HSP and HFP in raspberry pi3 using inbuilt bluetooth controller. I’m using Bluez5.23,Pulseaudio 7 and ofono 1.15 . But failed miserably.. However A2DP is working fine.
    Is it possible to implement HSP and HFP? If so , could you please share the steps and required commands?
    Thanks in advance..

  11. Irvaan Sid at | | Reply

    I used a USB bluetooth dongle also and tried implementing HSP and HFP. Using ofono, I’m able to do dial,answer call etc…. But there is no audio from either pi or phone. Is there any way to resolve this??

  12. HFP on Raspberry Pi at |

    […] on-board Bluetooth chip for this project. Unfortunately, it didn’t work. It seems that the problem is related with the chip. So, we have to use a Bluetooth dongle […]

  13. Said at | | Reply

    Both
    “pacmd set-default-sink bluez_sink.xx_xx_xx_xx_xx_xx”
    “pacmd set-default-source bluez_source.xx_xx_xx_xx_xx_xx”
    does not exist.

    Also when I check:
    “pactl list cards”
    it does “Assertion ‘pthread_mutex_lock(&m->mutex) == 0’ failed at pulsecore/mutex-posix.c:90, function pa_mutex_lock(). Aborting.” at the very end

    1. Frank at | | Reply

      After following these instructions to a tee, I get my bluetooth headset to connect to my USB dongle yet I dont see them in “pactl list cards”.

      Im at a loss as to why this is occuring..

      Thank you

  14. Balurdo at | | Reply

    Hello

    Quick question, at the end of your instructions you mention to record yourself with the microphone. Which microphone do you use? does your headset have a built in microphone or did you use a separate bluetooth microphone to record your voice? I’m trying to connect a headset with built in mic and I can get A2DP working to listen to audio but I cannot get HSP/HFP working for audio or recording. I figured I could try whichever bluetooth headset microphone you are using.

    Thanks

  15. David at | | Reply

    hi, Youness, thank you for providing this article, it’s the most informative tutorial about setting up bluetooth headset on pi3. one thing I really want to know is that, is there any information that raspbian will update its bluetooth firmware to support mic?

  16. Odianosen Ejale at | | Reply

    Hell Youness,

    Thanks for the time taken to do this, and its very much appreciated.

    I have followed your instruction with 3 different Bluetooth adapters, even purchasing the exact ASUS one you used (just be be certain) and I still get the same result; that is AD2P works, but not HSP.

    Is there something I am missing, as my headset profile is not working and I can’t set it as source as expected.

    Kind regards

  17. Odianosen Ejale at | | Reply

    Hello,

    I really appreciate the speedy responses.

    Below is what I get when I run the command specified “pacmd list-cards”

    2 card(s) available.
    index: 0
    name:
    driver:
    owner module: 6
    properties:
    alsa.card = “0”
    alsa.card_name = “bcm2835 ALSA”
    alsa.long_card_name = “bcm2835 ALSA”
    alsa.driver_name = “snd_bcm2835”
    device.bus_path = “platform-soc:audio”
    sysfs.path = “/devices/platform/soc/soc:audio/sound/card0”
    device.string = “0”
    device.description = “bcm2835 ALSA”
    module-udev-detect.discovered = “1”
    device.icon_name = “audio-card”
    profiles:
    output:analog-mono: Analog Mono Output (priority 200, available: unknown)
    output:analog-stereo: Analog Stereo Output (priority 6000, available: unknown)
    off: Off (priority 0, available: unknown)
    active profile:
    sinks:
    alsa_output.platform-soc_audio.analog-stereo/#0: bcm2835 ALSA Analog Stereo
    sources:
    alsa_output.platform-soc_audio.analog-stereo.monitor/#0: Monitor of bcm2835 ALSA Analog Stereo
    ports:
    analog-output: Analog Output (priority 9900, latency offset 0 usec, available: unknown)
    properties:

    index: 1
    name:
    driver:
    owner module: 22
    properties:
    device.description = “iLuv MobiOne”
    device.string = “BC:12:06:00:86:54”
    device.api = “bluez”
    device.class = “sound”
    device.bus = “bluetooth”
    device.form_factor = “headset”
    bluez.path = “/org/bluez/hci0/dev_BC_12_06_00_86_54”
    bluez.class = “0x240404”
    bluez.alias = “iLuv MobiOne”
    device.icon_name = “audio-headset-bluetooth”
    device.intended_roles = “phone”
    profiles:
    a2dp_sink: High Fidelity Playback (A2DP Sink) (priority 10, available: unknown)
    headset_head_unit: Headset Head Unit (HSP/HFP) (priority 20, available: no)
    off: Off (priority 0, available: yes)
    active profile:
    sinks:
    bluez_sink.BC_12_06_00_86_54/#1: iLuv MobiOne
    sources:
    bluez_sink.BC_12_06_00_86_54.monitor/#1: Monitor of iLuv MobiOne
    ports:
    headset-output: Headset (priority 0, latency offset 0 usec, available: unknown)
    properties:

    headset-input: Headset (priority 0, latency offset 0 usec, available: no)
    properties:

    Regards

  18. Odianosen Ejale at | | Reply

    Hello,

    Actually I do have audio and it sounds fine using your test command “paplay -v …..wav”

    I have used ti with my iPhone and it works fine over bluetooth. but mic and speaker.

    Well on you last point, I am also beginning to suspect the speaker but will look into getting another one to test and get back to you.

    Thanks for the help

  19. Yahya at | | Reply

    You are tha man bro !! keep it up

  20. Jsyu at | | Reply

    Hi
    I used my phone(Galaxy) and proceeded in order
    $ pactl list cards
    Profile
    a2dp_source: High Fidelity Capture (A2DP Source) (sinks: 0, sources: 1, priority: 10, available: yes)
    headset_audio_gateway: Headset Audio Gateway (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: no)
    $ pacmd set-card-profile 1 headset_audio_gateway
    Failed to set card profile to ‘headset_audio_gateway’.

    I need your help.
    Thank you.

  21. Pablo at | | Reply

    Hi Youness,

    Thanks for the great post.
    I was able to connect with my “handsfree” bluetooth device as HSP.
    I can play .wav files but when I tried to record my voice using the microphone of this “handsfree” device the file is recorded but no sound.
    I have tested the microphone of this device using my phone, and I am sure the mic is working.
    Any thoughts?

    1. khoa nguyen at | | Reply

      hi pablo,

      Which PulseAudio version you are using ?

      I tried both 2 method but still cannot connect to my bluetooth device.

      1. Pablo at | | Reply

        Hi Khoa, I used the same version Youness mention on the post. Version7.
        I used the method number 1.

  22. Pablo at | | Reply

    This is what I get when I record.

    pi@raspberrypi:~ $ parecord -v voice.wav
    Opening a recording stream with sample specification ‘s16le 2ch 44100Hz’ and channel map ‘front-left,front-right’.
    Connection established.
    Stream successfully created.
    Buffer metrics: maxlength=4194304, fragsize=352800
    Using sample spec ‘s16le 2ch 44100Hz’, channel map ‘front-left,front-right’.
    Connected to device bluez_source.FC_58_FA_1C_89_DC (index: 2, suspended: no).
    ^CGot signal, exiting.cy: 64504 usec.
    pi@raspberrypi:~ $

    And this is what I get when I play:

    pi@raspberrypi:~ $ paplay -v voice.wav
    Opening a playback stream with sample specification ‘s16le 2ch 44100Hz’ and channel map ‘front-left,front-right’.
    Connection established.
    Stream successfully created.
    Buffer metrics: maxlength=4194304, tlength=352800, prebuf=349276, minreq=3528
    Using sample spec ‘s16le 2ch 44100Hz’, channel map ‘front-left,front-right’.
    Connected to device bluez_sink.FC_58_FA_1C_89_DC (index: 1, suspended: no).
    Stream started.
    Playback stream drained.: 31750 usec.
    Draining connection to server.
    pi@raspberrypi:~ $

  23. khoa at | | Reply

    Hi Youness,

    Your tutorial is very great and detailed. Thank you for supporting us.

    I want to use a bluetooth dongle and connect it with a bluetooth headset or audio bluetooth module so that I can call Alexa from far away. I tried with my pi zero W and my raspberry pi 3.

    My usb dongle AP Link 4.0:
    https://www.amazon.ca/Bluetooth-Computer-Earphone-Transmitter-Receiver/dp/B01L34KMYK.

    My audio bluetooth module:
    https://www.eprolabs.com/product/csr8630-bluetooth-4-0-audio-stereo-receive-module/

    My bluetooth headset Bluetooth Sony MDR-XB50BS
    http://www.sony.com.sg/electronics/in-ear-headphones/mdr-xb50bs

    On raspberry pi 3:
    Method 1: Install PulseAudio from Debian Backports
    I did sudo apt-get install libudev-dev libsbc-dev libbluetooth-dev libx11-xcb-dev libasound2-dev libsystemd-dev libsamplerate0-dev
    but after ran ./ bootstrap, the udev, bluez5, ofono, native-headset, alsa, X11, systemd, … still were not enabled.

    Then I follow next steps.
    In bluetoothctl, I got error when I connect my audio bluetooth module:
    [bluetooth]# pair 54:01:01:02:23:32
    Attempting to pair with 54:01:01:02:23:32
    [CHG] Device 54:01:01:02:23:32 Connected: yes
    [CHG] Device 54:01:01:02:23:32 UUIDs:
    0000110b-0000-1000-8000-00805f9b34fb
    0000110c-0000-1000-8000-00805f9b34fb
    0000110e-0000-1000-8000-00805f9b34fb
    [CHG] Device 54:01:01:02:23:32 Paired: yes
    Pairing successful
    [CHG] Device 54:01:01:02:23:32 Connected: no
    [bluetooth]# trust 54:01:01:02:23:32
    [CHG] Device 54:01:01:02:23:32 Trusted: yes
    Changing 54:01:01:02:23:32 trust succeeded
    [bluetooth]# connect 54:01:01:02:23:32
    Attempting to connect to 54:01:01:02:23:32
    Failed to connect: org.bluez.Error.Failed
    [bluetooth]#

    So my problem is udev, bluez5, ofono, native-headset, alsa, X11, systemd, … were not enabled , right ?

    Method 2: Use PulseAudio sources
    I got
    pi@raspberrypi:~ $ dpkg -l pulseaudio pulseaudio-module-bluetooth
    Desired=Unknown/Install/Remove/Purge/Hold
    | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
    |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
    ||/ Name Version Architecture Description
    +++-==============-============-============-=================================
    ii pulseaudio 7.1-2~bpo8+1 armhf PulseAudio sound server
    ii pulseaudio-mod 7.1-2~bpo8+1 armhf Bluetooth module for PulseAudio s

    But can’t connect my module too.
    [bluetooth]# pair 54:01:01:02:23:32
    Attempting to pair with 54:01:01:02:23:32
    Failed to pair: org.bluez.Error.AlreadyExists
    [bluetooth]# trust 54:01:01:02:23:32
    Changing 54:01:01:02:23:32 trust succeeded
    [CHG] Device DA:94:4A:70:84:52 RSSI: -70
    [bluetooth]# connect 54:01:01:02:23:32
    Attempting to connect to 54:01:01:02:23:32
    Failed to connect: org.bluez.Error.Failed

    Both method I’ve already added my pi to pulse group

    Would you mind helping me ?

    1. khoa at | | Reply

      Hi,

      I installed the new raspbian image 5/7/2017 and follow all the step again.
      Now I can connect to my audio bluetooth module but I can’t find HSP or headset_head_unit.

      pi@raspberrypi:~ $ pactl list cards
      Card #0
      Name: alsa_card.platform-soc_audio
      Driver: module-alsa-card.c
      Owner Module: 6
      Properties:
      alsa.card = “0”
      alsa.card_name = “bcm2835 ALSA”
      alsa.long_card_name = “bcm2835 ALSA”
      alsa.driver_name = “snd_bcm2835”
      device.bus_path = “platform-soc:audio”
      sysfs.path = “/devices/platform/soc/soc:audio/sound/card0”
      device.string = “0”
      device.description = “bcm2835 ALSA”
      module-udev-detect.discovered = “1”
      device.icon_name = “audio-card”
      Profiles:
      output:analog-mono: Analog Mono Output (sinks: 1, sources: 0, priority: 200, available: yes)
      output:analog-stereo: Analog Stereo Output (sinks: 1, sources: 0, priority: 6000, available: yes)
      off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
      Active Profile: output:analog-stereo
      Ports:
      analog-output: Analog Output (priority: 9900, latency offset: 0 usec)
      Part of profile(s): output:analog-mono, output:analog-stereo

      Card #1
      Name: bluez_card.54_01_01_02_23_32
      Driver: module-bluez5-device.c
      Owner Module: 22
      Properties:
      device.description = “KRC-86B V4.0”
      device.string = “54:01:01:02:23:32”
      device.api = “bluez”
      device.class = “sound”
      device.bus = “bluetooth”
      device.form_factor = “speaker”
      bluez.path = “/org/bluez/hci0/dev_54_01_01_02_23_32”
      bluez.class = “0x240414”
      bluez.alias = “KRC-86B V4.0”
      device.icon_name = “audio-speakers-bluetooth”
      Profiles:
      a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
      off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
      Active Profile: a2dp_sink
      Ports:
      speaker-output: Speaker (priority: 0, latency offset: 0 usec)
      Part of profile(s): a2dp_sink
      speaker-input: Bluetooth Input (priority: 0, latency offset: 0 usec, not available)

      What should I do ?

      Would you mind helping me ?

      Thanks

      1. Pablo at | | Reply

        Hi Khoa, as you can ser un your profiles list, YouTube Bluetooth device is justo a receiver, si you once Have the a2dp profile available, try to connect your headphone instead.

        1. khoa at | | Reply

          Hi Pablo,

          Thank you for your help

          I tried with my Zenphone 2 , Iphone 5s, Sony M4 Aqua and always get
          headset_audio_gateway: Headset Audio Gateway (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: no)

          When I run bluetooth scan ,I can’t find my bluetooth headset Bluetooth Sony MDR-XB50BS
          http://www.sony.com.sg/electronics/in-ear-headphones/mdr-xb50bs

          Haizz, May be I have to buy a new bluetooth headphone.
          Which one you are using , Pablo ?

  24. Pablo at | | Reply

    May Be your headphones needs to be “visible”, do you have the manual of your headphones?
    I am using a “hands free” speaker, Chinese, no brand.
    Pretty much like this one, but no leds light.

    https://m.aliexpress.com/s/item/32819921968.html?spm=a2g0n.search-cache.0.0.7f25570frLIse4

    1. khoa at | | Reply

      Hi, Pablo.

      The Bluetooth version on my Sony MDR-XB50BS is “4.1”. My usb bluetooth dongle is “4.0”
      I think that is the reason why I can’t find my bluetooth headphone. Their bluetooth version doesn’t match each other.

      I tried with my friend’s bluetooth headphone “Anker SoundBuds Sport Bluetooth Headphone” and the bluetooth version is 4.0.

      It works perfectly.

      I’m really sad because my bluetooth headphone is more expensive but can’t work.

      Anyway, many thanks to Youness for making such a great tutorial.

    2. khoa at | | Reply

      But I still don’t understand.

      My phone’s bluetooth support “4.0, A2DP, EDR” but it can connect to my Sony MDR-XB50BS.
      Is it because of A2DP feature ?

    3. khoa at | | Reply

      are there any usb bluetooth dongle 4.1 ?

  25. khoa at | | Reply

    Hi Youness,

    I can connected with my headphone.
    The problem is I have to press and hold the button on my headphone to change it to mode “BLUETOOTH pairing”.

    But now I have another problems.

    1/ On my Pi zero W: I got error
    pi@raspberrypi:~ $ pulseaudio -D
    Illegal instruction

    I type all commands follow the link you gave: https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/SystemWide/

    sudo addgroup –system pulse
    sudo adduser –system –ingroup pulse –home /var/run/pulse pulse
    sudo addgroup –system pulse-access

    # Some distributions restrict access to the sound devices to a group audio
    sudo adduser pulse audio

    # Add a user to the pulse-access group
    sudo adduser pi pulse-access

    But still not works.

    2/ On my pi 3: I already “runpulseaudio –start” and able to connect with my headphone
    I got this after typed “pactl list cards”
    Card #2
    Name: bluez_card.00_18_09_9F_D8_BC
    Driver: module-bluez5-device.c
    Owner Module: 24
    Properties:
    device.description = “MDR-XB50BS”
    device.string = “00:18:09:9F:D8:BC”
    device.api = “bluez”
    device.class = “sound”
    device.bus = “bluetooth”
    device.form_factor = “headset”
    bluez.path = “/org/bluez/hci0/dev_00_18_09_9F_D8_BC”
    bluez.class = “0x240404”
    bluez.alias = “MDR-XB50BS”
    device.icon_name = “audio-headset-bluetooth”
    device.intended_roles = “phone”
    Profiles:
    headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: yes)
    a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
    off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
    Active Profile: off
    Ports:
    headset-output: Headset (priority: 0, latency offset: 0 usec)
    Part of profile(s): headset_head_unit, a2dp_sink
    headset-input: Headset (priority: 0, latency offset: 0 usec)
    Part of profile(s): headset_head_unit

    pi@raspberrypi:~ $ pacmd set-card-profile 2 headset_head_unit
    Failed to set card profile to ‘headset_head_unit’.

    pi@raspberrypi:~ $ sudo pacmd set-card-profile 2 headset_head_unit
    No PulseAudio daemon running, or not running as session daemon.

    1. khoa at | | Reply

      I used to use pavucontrol to drive the sound but now I got
      pi@raspberrypi:~ $ sudo apt-get install pavucontrol
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      Some packages could not be installed. This may mean that you have
      requested an impossible situation or if you are using the unstable
      distribution that some required packages have not yet been created
      or been moved out of Incoming.
      The following information may help to resolve the situation:

      The following packages have unmet dependencies:
      pavucontrol : Depends: libpulse-mainloop-glib0 (>= 0.99.1) but it is not going to be installed
      E: Unable to correct problems, you have held broken packages.

      How do you drive sound to bluetooth to work with Alexa after installed pulseaudio 7.1-2~bpo8+1 ?

  26. Pier at | | Reply

    Hi, did anything change now that Raspbian stretch is out?

  27. Jon Stralkowski at | | Reply

    Now that blue-alsa is recommended and supported solution on rasbian stretch. Have you tried to get this to work on bluealsa instead of pulseaudio.

  28. […] on-board Bluetooth chip for this project. Unfortunately, it didn’t work. It seems that the problem is related with the chip. So, we have to use a Bluetooth dongle […]

  29. John Smith at | | Reply

    On amazon it says the ASUS USB Bluetooth only works with windows and mac.
    Your SURE it works with Linux?

  30. Pablo at | | Reply

    Hi Youness, I am still having troubles trying to connect my RPi2 with usb dongle to my SONY SRS X11 bluetooth speaker.

    Most of the times I have troubles with bluetoothctl trying to pair and connect to the speaker. But removing the devices from the list and start all the process again sometimes I am able to connect to the speaker again, some other times don’t, so I have to reboot the RPi.

    When I am able to connect to the speaker, using the headset_head_unit profile, and I try to play or record, it seems the pulseaudio get bussy and did not respond and I am not able to change the profile, neither a2dp_sink nor off profile.

    This is what I get when I try to record:

    pi@raspberrypi:~ $ parecord -v voice.wav
    Opening a recording stream with sample specification ‘s16le 2ch 44100Hz’ and channel map ‘front-left,front-right’.
    Connection established.

    When this happend I have to ctrl+c or wait for at least 2 minutes until I get an error message.

    Only once I could record an audio, but then after 3 or 4 tests it stopped working.

    Which is more strange is the bluetoothctl does not respond neither, I can’t even remove the device from the list of devices.
    I am suspecting my dongle is not good enough, my dongle is bluetooth 2.0 and my speaker is 3.0.

    Did you have any clue of what can be happening?

    1. Pablo at | | Reply

      I have bought a new Bluetooth dongle, this new is 4.0 (generic) and it works fine. So the issue was the Bluetooth dongle.

  31. Michael at | | Reply

    I think it is excellent that Youness has put up these instructions and takes the time to work on this. Thank you!

    I followed the instructions and I was able to pair and connect with the device. However I have had only partial success but not complete success. I can send music to my bluetooth device, but the microphone does not work.

    I think that either:

    1) there is some additional step that is sometimes needed to make the instructions work,

    or 2) the instructions work for some Bluetooth adapters but not others,

    or 3) the instructions work for some Bluetooth devices but not others.

    My adapter is the Kinivo BTD-400 (Bluetooth 4.0) device from Amazon.

    My device is the Anker SoundCore Mini with speaker and microphone. Both speaker and microphone work with my desktop computer.

    I began with a copy of 2017-07-05-raspbian-jessie.

    The only variation from the instructions was that I had to use a different driver. When I looked at dmesg output I got
    [ 3.075953] bluetooth hci0: Direct firmware load for brcm/BCM20702A1-0a5c-21e8.hcd failed with error -2
    instead of what is listed in the instructions. So I had to inspect the bcbtums-win7x86-brcm.inf file for the matching driver, which was
    BCM20702A1_001.002.014.0889.0896.hex (slightly different number).

    But following the conversion to .hcd and the rest of the instructions, I restarted and then dmesg said the correct driver was present, so I think that I got those steps OK.

    The problem comes when after following all directions, I still could not use microphone. I tried many things, restarting, re-pairing, etc., but still no go.

    I think this is explained when I do “pactl list cards” and I see:
    headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: no)

    I suspect that unless I can see “available: yes” the microphone will not work.

    The question is, what must I change in order to get “available: yes”?

    Did I make a mistake in following the directions? Is there some software that needs to be updated? Do I need to use the exact adapter from the instructions (ASUS BT-400)? Or do I need a different bluetooth speaker/microphone? These are hard questions, maybe no one can know the answer yet.

    I believe that bluetooth and sound on the raspberry pi is a tricky problem, however, and we will all have to work and share whatever we find out about it. If you have success with the instructions, please post the brand of adapter and device you are using, so perhaps we can see the pattern.

  32. khoa at | | Reply

    Hi Michael,

    I have the same problem.
    And I think it depends on the device.

    my speaker Jabra speal 510 works perfectly, The profine is already headset_head_unit. The device automatically change to headset_head_unit after connected to me Bluetooth dongle.
    http://www.jabra.com/business/speakerphones/jabra-speak-series/jabra-speak-510

    But my bluetooth headset Bluetooth Sony MDR-XB50BS
    http://www.sony.com.sg/electronics/in-ear-headphones/mdr-xb50bs
    the headset_head_unit is not available and I still don’t know how to deal with it.

    Hope someone can find the solution.

  33. xizirumeng at | | Reply

    非常感谢,你的文章成功帮助我解决了问题!thanks!

  34. Michael at | | Reply

    I tried the instructions using raspbian stretch instead. It is now easier to install pulseaudio; simply by doing this:

    sudo apt-get install pulseaudio

    sudo apt-get install pulseaudio-module-bluetooth

    which installs pulseaudio v10. (No longer necessary to use backport or build manually.) Also it is no longer necessary to modify the makefile for hex2hcd.

    Also, I borrowed an older Jawbone Jambox bluetooth speaker/microphone. This now works perfectly with the instructions above (using bluetooth dongle), both speaker and microphone, and reports the available profile with “pactl list cards”:

    headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: yes)

    My Anker SoundCore speaker still does NOT work.

    So I conclude: 1) the instructions work for some audio devices but not others, 2) it is not necessary to use the exact same BT dongle that Youness used, 2) updating to stretch and pulseaudio 10 will not help if your device is not compatible, 3) use “pactl list cards” to see if your device is compatible.

  35. Michael at | | Reply

    One more comment: I had some trouble playing through the speaker when I had the system boot into the GUI. This may be due to having two different interfaces to control the audio source active at the same time. The problem went away when I changed the preferences to boot directly to the command line.

  36. Michael at | | Reply

    I have learned the reason some devices work and some do not. According to this note from August 2016 https://www.mail-archive.com/pulseaudio-discuss@lists.freedesktop.org/msg16445.html

    “When all headsets supported both HSP and HFP, life was good and we
    only needed to implement HSP in the native backend. Unfortunately
    some headsets have started supporting HFP only.”

    This is from a developer on the pulseaudio-discuss list. He was working on a fix, but it is not done yet.

    I can confirm that this is the problem, from my experience.

    The Jawbone Jambox speaker works. It is older. It supports both Headset and Handsfree.

    The SoundCore Mini speaker does not work. It is newer. It supports both Handsfree only.

    (To find out what is supported, use bluetoothctl and the ‘info xx:xx:xx:xx:xx:xx’ command.)

    There is a complicated workaround that is mentioned for this at https://freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Bluetooth/#index5h2 for the pulseaudio 11.0 release. I was not able to have success with this workaround, which uses ofono and phonesim.

Please comment with your real name using good manners.

Leave a Reply