How to setup Bluetooth Streaming for a Raspberry Pi with the 30-pin Dock Adapter from Poolside Factory

 

If Airplay 2 is a viable way for you to stream music from your devices, we recommend you follow the Airplay 2 instructions for more features, like multi-speaker streaming.  If you do need to stream audio via Bluetooth to the Raspberry Pi, then continue below:

 

Hardware needed

- Raspberry Pi to iPod HiFi 30-pin-dock Adapter for Airplay Audio Streaming from Poolside Factory. Comes with standoffs and screws to mount to the Raspberry Pi Zero form factor.

- Raspberry Pi Zero W or Raspberry Pi Zero 2 W, either with connector header soldered on.  The 'W' version is necessary for this application.

- SD Card with capacity of 4GB or higher

 

Instructions

If you already have an SD card with a working Raspberry Pi image that you can log into over WiFi, you can use that one, otherwise you can follow these steps to create a fresh one.

Log in to your Raspberry Pi.

Change the hostname of your Raspberry Pi to what you want the name to be that shows up as the Bluetooth speaker name that you can stream to. For this, use raspi-config as shown in the above mentioned steps

Run these commands to bring your Raspberry Pi image up to date and install all the necessary packages (can take 20ish minutes, make sure the shell has your sudo password before you copy-paste the whole block - for instance by running 'sudo ls' first).  The blocks are grouped so that you can copy paste and run them together per group. This tutorial was created using Raspbian 11 Bullseye. 

sudo apt-get update -y && sudo apt-get -y dist-upgrade && sudo apt-get install -y vim pulseaudio pulseaudio-module-bluetooth bluez-tools

Create a user, for instance called "btuser" for running pulseaudio with the following command:

sudo useradd -m btuser 
sudo passwd btuser

Enter a password of your choice and confirm it. Then we add this new user to the sudoers file and log in to the new user.

sudo sed -i '1s/^/btuser ALL=(ALL) NOPASSWD: ALL\n/' /etc/sudoers.d/010_pi-nopasswd
su btuser

Login with your just created password and then run this large block of commands that configure the Raspberry Pi for Bluetooth streaming:

sudo systemctl start user@1001.service # needed for pulseaudio
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus" # needed for pulseaudio

sudo bash -c 'cat <<EOF > /etc/systemd/system/getty@tty1.service.d/autologin.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin btuser --noclear %I $TERM
EOF'
# NOTE: The empty line is important! The empty line will first clear the ExecStart entry, while the next line will introduce a new exec command.

sudo sed -i --follow-symlinks 's/#DiscoverableTimeout = 0/DiscoverableTimeout = 0/' /etc/bluetooth/main.conf
sudo sed -i --follow-symlinks 's/bluetooth\/bluetoothd/bluetooth\/bluetoothd --noplugin=avrcp/' /etc/systemd/system/bluetooth.target.wants/bluetooth.service

sudo bash -c 'cat <<EOF > /etc/systemd/system/bt-agent.service
[Unit]
Description=Bluetooth Auth Agent
After=bluetooth.service
PartOf=bluetooth.service

[Service]
Type=simple
ExecStart=/usr/bin/bt-agent -c NoInputNoOutput

[Install]
WantedBy=bluetooth.target
EOF'

systemctl --user enable pulseaudio
sudo systemctl enable bt-agent

The following commands configure the Raspberry Pi to output the sound to the 30-pin dock adapter from Poolside Factory (if you have already run these commands as part of another Poolside Factory tutorial, then don't run them again to avoid duplicate configuration entries).

sudo sed -i --follow-symlinks 's/dtparam=audio=on/dtparam=audio=off/' /boot/config.txt
sudo sed -i --follow-symlinks '/dtparam=audio=off/a dtoverlay=hifiberry-dac' /boot/config.txt

Reboot the Raspberry Pi for the configuration to become effective

sudo reboot

Execute this last command

bluetoothctl <<EOF
power on
discoverable on
pairable on
agent on
EOF

Now the Raspberry Pi with the 30-Pin Dock Adapter is ready for pairing your Bluetooth device and play music.  There is no pin needed to pair, and the Raspberry Pi will automatically accept your pairing request.  These settings will remain after power cycles of the Raspberry Pi, so they will not have to be repeated. 

It is possible to have both the code for streaming from a Bluetooth source and and from an Airplay 2 source installed on the same Raspberry Pi installation. When one source is playing, then the other source will be ignored until the first source is stopped, and the second source restarted. Overall, this is a great setup allowing for streaming both Airplay 2 and Bluetooth without having to change out the adapter plugged into a 30-pin dock speaker, such as for instance an Apple iPod HiFi. 

Leave a comment

Please note, comments must be approved before they are published