
Listen to Spotify Connect, Bluetooth, and AirPlay with a Raspberry Pi Receiver
A great way to use the Raspberry Pi is to use it for an audio receiver. Setup with your Stereo will allow a whole new world of possibilities. Using Spotify Connect (Premium required) you can stream in music all day without needing audio pushed from another device. With Bluetooth connectivity, you can connect your smart devices like Alexa, Google Home, or Mycroft. And with Apple Airplay and UPnP you pretty much have all the bases covered for listening to anything through your stereo.
If your using a Raspberry Pi 3 or older, you will need a Bluetooth dongle. The Raspberry Pi 3 does have integrated Bluetooth, but there is a known issue where WiFi and Bluetooth usage at the same time causes interference. Bluetooth dongles like this are cheap and work well.
This guide will show you how to configure usage with a DAC as the Raspberry Pi doesn’t have the cleanest audio output. This is optional however, you don’t need to configure it if you don’t have one. I am using a Cambridge Audio DacMagic, but there are certainly cheaper alternatives that work great as well.
Lets install Raspian Lite
Lets grab the latest release version of Raspian Lite from here.
https://www.raspberrypi.org/downloads/raspbian/
Once downloaded, write the image to your SD card. If your new to writing images, there is a great cross-platform program called Etcher you can use to write to the SD card. It can be found here.
Once your have written to the SD card, lets insert and start our Raspberry Pi.
Configure Raspian Lite
On first boot, we will need to do some initial configuration on the Raspberry Pi. First we need to log into the system with the following.
User: pi
Pass: raspberry
This will log us in with the default user/pass. Now at the command prompt, enter the following.
sudo raspi-config
Change your default password. (You may want to set your keyboard layout first under localization options)
Configure your network options.
Configure your Localization settings.
Under Interfacing Options, set SSH to be active.
Once complete, select Finish to reboot the system.
Once restarted, lets now login to our Raspberry Pi again using SSH or the console again with
User: pi
Pass: (new password)
Now lets see if there are any updates for Raspian using the following commands.
sudo apt-get update sudo apt-get upgrade -y sudo apt-get dist-upgrade -y sudo reboot
If your using a Bluetooth Dongle
Lets disable the onboard Bluetooth so we don’t run into any conflicts.
sudo nano /boot/config.txt
Now scroll to the bottom of the file, and add the following to the end of the file.
# Disable onboard Bluetooth dtoverlay=pi3-disable-bt
Press Ctrl+x, press y to save the changes, and enter to exit the editor.
Now at the prompt, enter the following command.
sudo systemctl disable hciuart.service
Lets Configure the Raspberry Pi to use our DAC
If your using a USB DAC, we will need to configure the Raspberry Pi to use the USB connection by default when rebooted. To do this, we need to reconfigure the order it uses for audio devices. Lets create a new config file with the following command.
sudo nano /etc/modprobe.d/alsa-base.conf
Now in the new window, lets name and reorder our audio devices. Enter the following in our new file.
# sets the index value of the cards but doesn't reorder. options snd_usb_audio index=0 options snd_bcm2835 index=1 # does the reordering. options snd slots=snd_usb_audio,snd_bcm2835
Press Ctrl+x, press y to save the changes, and enter to exit the editor. Now, on reboot, our Raspberry Pi should default to the usb audio device. Lets give a quick reboot to save our new configuration files.
sudo reboot
Now lets setup our Audio Hub
First, lets name our Raspberry Pi to something meaningful for us to connect to. I am going to use the name Stereo. This will be the name that shows up when you are searching for the Raspberry Pi to connect to.
sudo raspi-config nonint do_hostname stereo sudo hostnamectl set-hostname --pretty "Stereo"
GitHub user nicokaiser has done a great job of creating a great set of scripts that automates much of the setup for us.
sudo apt-get install git -y git clone https://github.com/nicokaiser/rpi-audio-receiver.git cd rpi-audio-receiver
Lets setup the Bluetooth receiver. This will make the raspberry pi discoverable any time there isn’t an active connection and allow A2DP streaming.
sudo ./install-bluetooth.sh
Next lets setup our shairport receiver. This will allow audio input using Apples Airplay protocols.
sudo ./install-shairport.sh
Next lets set up Spotify Connect. This will allow you to use the Raspberry Pi as a Spotify Connect Device.
sudo ./install-spotify.sh
Lastly, lets configure UPnP so that UPnP devices can also use our new audio hub.
sudo ./install-upnp.sh
Some final configuration
Now lets adjust our output volume with the following command.
sudo alsamixer
Turn your default volume level up to anywhere from 85% to 100% and press ESC. Now we need to store this volume level for any time we reboot.
sudo alsactl store
Next, lets start up our Bluetooth. Enter the following commands.
sudo bluetoothctl power on discoverable on exit
Lets give our system one final reboot to make sure everything is live.
sudo reboot
All finished!
After our Raspberry Pi reboots, we should be able to have it stream in Spotify using Spotify Connect, pair it using Bluetooth, or stream directly to it via Apple AirPlay or UPnP! Thanks again to nicokaiser for taking the headache out of configuring everything separately.
If you found this guide helpful please leave me some encouragement below! If your really happy, you can always gift me a coffee, I can never say no to coffee!
I have also by request added a bitcoin donation address. If you want to show your appreciation I would be grateful, but under no means do you need to feel obligated. This is a fun hobby for me. 🙂
BTC: 1GzagpXcAkELhU5emJFMLZpp7J5ayf
And for those that have, thank you for enabling my coffee addiction! You all know who you are!
Great post! And really useful instructions for this handy GIT package. One word of warning, I managed to brick my Pi using rpi-update . This shouldn’t be used as apt-get update and apt-get upgrade should do all the necessary. More on this point here https://learn.pimoroni.com/tutorial/raspberry-pi/keeping-your-raspberry-pi-updated
I am a total noob and spent a few hours scratching my head with this before rebuilding the pi and omitting this step. The rest of it went like clockwork.
Thanks for the feedback Robin! I have ran this command so many times and never had an issue. The reason I did have it added was so that we would have the latest firmware which may include updated blue-tooth, but I shouldn’t assume that since it works for mine that it will work for everyone. I will update the guide and remove that so others wont have the same possible problem you did!
I’ve been researching for weeks, trying to build the best home audio system I can with a raspberry pi. I really like this tutorial, but I think there is one large issue; if someone were to connect with spotify and play a song, then someone connects with bluetooth and plays a song, you have a cluster-F of sounds in your house. I know the simple solution to this is to just not be an idiot and play nice, but I assure anyone who says that does not know my friends. I would love to have the option of both spotify connect, bluetooth, and other options, but I can’t work out how I could justify this without some sort of semaphore system.
Hi Nolan, yes this is true. You can run more than one source at a time if you choose too, even if you don’t want too. I occasionally push music from my iPhone via Airplay, and have my Amazon dot connected via bluetooth at the same time. Doing this I can listen to my playlists, and have it answer questions for me at the same time. Good and bad feature I guess…
Thanks for great post! One thing is that spotifyd used in rpi-audio-receiver has an annoying bug while raspotify (https://github.com/dtcooper/raspotify) does not have this issue.
Thank you Hanjo for letting me know! I have been using this on two RPI’s for a while and have not noticed anything. I will look into this for sure. I will update the guide to reflect!
Wtf is going on with my scroll speed on this page?
Whats happening Will? Seems okay for me, same as the rest…
Hi, Cool project I am trying to make it work using a RP 1.2 B+ with a USB Bluetooth – will it work? Also do I need a USB sound card as well? I get this error message Can’t set Simple Pairing mode on hci0: Input/output error (5)
Any help would be appreciated
Hi Zinfab, you shouldn’t need a USB sound card to make this work, but having one will improve sound quality. At what stage are you getting the error in the process?
sudo ./install-bluetooth.sh
Do you want to install Bluetooth Audio (BlueALSA)? [y/N] y
Reading package lists… Done
Building dependency tree
Reading state information… Done
alsa-base is already the newest version (1.0.27+1).
alsa-utils is already the newest version (1.1.3-1).
python-dbus is already the newest version (1.2.4-1).
python-gobject is already the newest version (3.22.0-2).
sound-theme-freedesktop is already the newest version (0.8-1).
vorbis-tools is already the newest version (1.4.0-10).
bluealsa is already the newest version (0.9).
bluez is already the newest version (5.43-2+rpt2+deb9u2).
The following packages were automatically installed and are no longer required:
coinor-libipopt1v5 libmumps-seq-4.10.0 libraw15
Use ‘sudo apt autoremove’ to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Can’t set Simple Pairing mode on hci0: Input/output error (5)
So on the bluetooth install
Hi ZinFab, sorry for the slow reply! This appears to be an issue with your Bluetooth dongle. Are you using built-in bluetooth, or a USB dongle?
It’s a dongle, but it seems to work – in the apple airplay mode…
Hi Zinfab, I can try a re-installation on mine. I use a dongle as well, can see if I have the same problem…
Would be great, but if it’s too much trouble don’t stress…
Hi Zinfab, I finally got around to doing a reinstall. I used a fresh Raspian Buster lite image, followed the steps and everything worked without error. I am using a bluetooth dongle on RPI3. Tested bluetooth and Spotify connect and both are working as expected. Seems like there may be an issue with your dongle perhaps… Airplay uses the wifi so that’s potentially why airplay is fine.
It’s possible to turn it on/off for BT and Airplay ? I want this for a public speaker and would like to have a button to turn it on/off so users can sync their devices by pressing the button and no one else…help please…maybe with subprocess ?
Also, if multiple devices BT are connected, they can all send audio. How to block this to only one connection?
Hi Paulo, what you could do is set up a PIN for the bluetooth to connect. For airplay, you can also set up a password to allow connections. You can take a look here for config setting for Shairport https://www.mankier.com/7/shairport-sync and try here for a little insight into bluetooth pin settings https://stackoverflow.com/questions/34709583/bluetoothctl-set-passkey
Hope this helps some!
Hey, i have a problem with my bluetooth connection to the Pi. Everytime i try to connect to the pi from my computer. it doesn´t work. On the pi is always a error. The error is: Pairing failed – GDBus.Error:org.bluez.Error.AuthenticationCanceled: Authentication Canceled. Can someone help me? Sadly im new to the Raspberry Pi because i orderd it just for this project to make my own audio receiver and i dont know how to solve this.
Hi Henri, that looks like there is potentially a pin request that needs to be handled and its timing out.You may be able to try something like this from your raspberry pi to trust the computer…
[bluetoothctl]# power on
[bluetoothctl]# agent on
[bluetoothctl]# default-agent
[bluetoothctl]# discoverable on
[bluetoothctl]# scan on
[bluetoothctl]# pair
(Not sure if you need to or are able to reverse the order of these two commands. You might try trusting before pairing and see if that helps…)
[bluetoothctl]# trust
[bluetoothctl]# connect
Hopefully this will help! Let me know how it goes…
Hey, thanks for the fast reponse! I tried trusting my computer before trying to pair it with the pi but it still doesnt work. Everytime my computer says: connection issue and the pi says the error code i posted before.
What version of the Raspberry Pi are you using Henri? Are you using on board bluetooth or a dongle? I tested from my Macbook Air that I am using and mine connected right away. I am on a Raspberry Pi3 using a BT dongle with Raspian Buster Lite as the OS.
I am using the Raspberry Pi Model 3 with a Bluetooth Dongle. The wierd Thing is, That i can connect via Bluetooth my iPhone no Problem But with my Windows 10 Computer it just wouldnt work. Everytime the Same issue. I use 2019-09-26-raspbian-buster
Hey, just wanted to inform you that i solved the problem. The issue was that i had a usb dongle connected to my computer and it was the same that i used with my raspberry pi. Today arrived a new bluetooth dongle from another company and after i plugged it in and rebooted the pi once, it works just fine.
Well that’s unexpected ha! Thanks for the update Henri, I am glad you got it working now!
First of all, thank you for the fast Support and awesome manual to set the pi up. But i have another question if you know. Can i change the Default Audio Level of Spotify Connect? When i connect via Spotify Connect i always have to Change the Audio Level to about the half to make it enjoyable for normal music listening and it would ne nice That it is the normal Audio volume at about 50% (somewhere in the middle of the slider).Thanks!
Hi Henri, there is a config file for spotifyd that you can edit with this command. sudo nano /etc/spotifyd.conf but I don’t believe there is a setting for the volume level implemented by the author. You can see more on configuration settings here. https://github.com/Spotifyd/spotifyd#configuration
Thank you so much for the tutorial. I wanted to add that another way to configure the raspberry to use our DAC is by blacklisting the built-in jack. To do this we need to write the following command:
sudo nano /etc/modprobe.d/blacklist.conf
And then add this line to the new file:
blacklist snd_bcm2835
Perfect, thank you for that Pedro!
Hi,
Thanks for these amazing solutions, after a long time got to read such a nice thread..
Can you suggest a way around just to enable Bluetooth in Volumio. I tried a few things as mentioned, but failed to get the result.
Darryl: This all worked fine for my Pi3B with a HiFiBerry DAC+ card (even switching WiFi on and off during Bluetooth connections by removing the two commented lines in install-bluetooth.sh). Just tried same using a Pi ZeroW and the corresponding smaller DAC+ card. Ran the HiFiBerry .sh selecting DAC+ FIRST, then installed all other components. Bluetooth pairs, but no audio. Airplay does not connect. Did I miss a step?
Okay, problem resolved, I think. I reinstalled per the sequence in your ./install.sh and set the dtoverlay to hifiberry-dac (not -dacplus), and I get bluetooth and airplay!
Hi Bob, sorry for the slow reply! it sounds like you have everything under control! I haven’t tried this one a Zero, but I was certain it would work okay. I am glad you got it up and running! I actually really like this project, I have 2 Rpi3’s running this way, one for my listening room, and another on my home theatre system. Nice to have the options for bluetooth, airplay, and Spotify Connect. Cheers!
Hi, spotify connect works fine. How can i play the music to a Bluetooth speaker through the raspberry pi?
Is there anyway this works with non premium spotify accounts, i ask this because spotify connect became a free feature aswell in 2018.
Awesome! Helped me a lot! But how can I use Google’s methods for casting to this device? And is there a way to ad my device to the google home app?
Greetz, mauro.productions
Any chance of adding a FM stereo broadcast output option?
A simple way is to Bluetooth pair to any of a myriad of Bluetooth to FM Transmitters. One of many is the Doosl 4336709303 about $23 on Amazon. Set for the Frequency you want to broadcast and tune in on radios. I picked this one to point out because it uses a microUSB power source not the 12V port used in cars. This way it can be used in a house without a bulky 12V adapter. If you are in an urban area with lots of stations look carefully at the specs to make sure you have enough choices of FM frequencies. Some have just a few options others give you lots of choice of frequencies. If you can find it see if you can find out the wattage of the FM transmitter. One benefit of this solution is that the FM transmitter can be in a location better for the FM broadcast rather than where your Raspberry Pi lives if necessary. There are also simpler Minijack to FM transmitters you could use through the headphone jack. An interesting thing is that some of these use the short input wire as an antenna so if you plug in a minijack extension you increase your FM range.