Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Setting up a Bluetooth Speaker from the command line on a raspberry Pi Zero W

The setup of a bluetooth speaker on a Pi Zero W is pretty touchy.

Please get in touch via Twitter @actuino or if you've got comments or improvements to this quick draft.

First checks

  • Use a solid power source
  • check the speaker works on another hardware (android phone f.i.)
  • make sure you've updated your Raspbian, install and run rpi-update just in case.

In case of compatibility doubt

  • Use a raspbian Pixel, run sudo apt-get update then sudo apt-get dist-upgrade and reboot.
  • use the graphical widget to pair and connect your speaker. You may have to try twice or more.

What to install?

pi-bluetooth and bluez are already installed on recent Raspbian.


sudo apt-get install pulseaudio pulseaudio-module-bluetooth

(without this module, you get messages like "bluetoothd[5556]: a2dp-sink profile connect failed for 00:1D:43:6D:03:26: Protocol not available")

Extra steps

Add your pi user to the bluetooth group

sudo usermod -G bluetooth -a pi

sudo reboot

Start a pulseaudio server

pulseaudio --start

If it complains about not being able to spawn a local server, run

pax11publish -r; /usr/bin/pulseaudio --start

Pair and connect

run bluetoothctl

use "help" if you want more details about the available commands. The first time, you'll have to run the following:

  • power on
  • agent on
  • scan on
  • wait for the device to be discovered, note it's address (you can then use tab for auto-completion)
  • pair <dev>
  • trust <dev>
  • connect <dev> wait for the confirmation, then
  • quit

test : aplay something.wav

edit /etc/pulse/ , add

# automatically switch to newly-connected devices
load-module module-switch-on-connect

edit /etc/bluetooth/main.conf, at the end of the file, add AutoEnable in the existing Policy section :


After a reboot

You may need to:

  • pulseaudio --start

(This last step was not useful for me):

  • bluetoothctl -a then wait and quit when (auto) connected

Still have to sort out

  • Sometimes, the BT speaker disconnects itself, but it's still viewed as "connected" from the Pi. From this point, nothing will fix it exept a Pi reboot.
Copy link

TimoBoiii commented Apr 15, 2021

The whole setting up was without a problem except the aplay something.wav it says command not found i tried even typing Play something.wav but it did the same thing. So now i have the whole thing set up but have no clue how to actually play music on it. I would appreciate if anyone could help me with this issue. Im kinda new to raspberry pi linux and all and i don't know what to do. If somebody explained to me i would really appreciate it Thanks.

Copy link

striderssoftware commented Jun 13, 2021

To send USB Mic Input to the bluetooth device:
aplay < arecord --device hw:1,0 -c1 -d 0 -r 48100 -f S16_LE -V mono

Copy link

striderssoftware commented Jun 13, 2021

Sorry my mistake, here is the command to send USB MIC input to the connected bluetooth device:
arecord --device hw:1,0 -c1 -d 0 -r 48100 -f S16_LE -V mono | aplay

Copy link

sirhopcount commented Jun 25, 2021

By default the audio played over my HDMI, I "fixed" this by disabling it in /boot/config.txt

# Enable audio (loads snd_bcm2835)

If anybody knows a better way of doing this please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment