Raspberry Pi 3 and bluetooth speaker setup [command line]

Streaming sound from a Raspberry Pi 3 to a bluetooth speaker was not as easy as it should. Internet is overloaded with outdated information about this issue. So I compiled a small tutorial for the latest Raspbian (at the date of writing). My setup is composed with the following elements:

Trying to connect the device to the Raspberry Pi with the following code will raise an error:   Failed to connect: org.bluez.Error.Failed

It is not obvious, but what is missing to the connecting device is the answer from the host saying that it can stream sound. In order to send the correct answer to the device, pulseaudio should be started first and should correctly load the bluetooth module.

First, ensure that all requirements are installed:

Then start pulseaudio an check that the module is indeed loaded:

At this point, if you try to connect your device, this should work. Most of the devices produce a sound when the connection succeed. Within bluetoothctl , it is not required to redo the pairing procedure, but before continuing you may need to ensure that the bluetooth controller is on with [bluetooth]# power on .

Load a MP3 on your Raspberry Pi and play it using mpg123 your.mp3 .

If you restart your Raspberry Pi now, your device will fail to connect again.
pulseaudio is not really ment to start system-wide at boot, but in the case of embedded device it makes sense.

You could use /etc/rc.local  but it’s a bit punk, so instead let’s create a systemd service.
Add the following content to this file /lib/systemd/system/pulseaudio.service :

And start the service by hand using systemctl start pulseaudio . When running systemctl status pulseaudio , you may find a warning about starting pulseaudio system-wide, but don’t worry, with this setup it makes sense.
Add pulseaudio to the list of services to start at boot:  systemctl enable pulseaudio.service

Don’t forget to add both root and pi users to the group pulse-access in /etc/groups :

Note that the group ID 115 may be different on your system.

Reboot your Raspberry Pi and you are good to go, if the speaker in ON, it should be automatically connected to your system.

3 thoughts on “Raspberry Pi 3 and bluetooth speaker setup [command line]”

  1. Hi,

    Thanks for the post which really interest me.
    I have been trying to achieve your solution but cannot make it work.
    Actually no sound is being played when I launched the mpg123 with a mp3 file after following all the first steps:
    – I do have a pulseaudio service active and running
    – I do have done all the bluetooth settings
    I have succeeded the following steps :
    – Launch a pulseaudio deamon which successfully connect to bluetooth speaker (I can hear the pairing sound) thanks to the “pulseaudio -D” command
    – Launch a test mp3 file to confirm that sound can be stream in this configuration.
    Nevertheless, when i do launch the pulseaudio service :
    – I cannot hear the pairing sound
    – As a direct consequence I cannot hear any sound when playing mp3.

    Do you have any clues where it could come from ?
    Thanks a lot,


    1. * Update :
      It comes from the config of pulseaudio in system mode.
      The config is at /etc/pulse/system.pa and some changes need to be made to :
      – Connect to bluetooth
      – Switch to new discovered sink available

      After that it’s working pretty well.

Comments are closed.