80 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 ?

  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 ?

Please comment with your real name using good manners.

Leave a Reply