I recently bought a Raspberry Pi with the intention of using it as an AirPlay receiver and hooking it up to an old stereo. I bought:
- A Raspberry Pi 2 Model B
- The official case
- The official power adapter
- A SanDisk Ultra 8 GB Class 10 microSD HC card1
- A TP-Link TL-WN725N Wi-Fi adapter2
- A Sabrent AU-MMCW USB sound adapter
This is the process I followed to get a working AirPlay receiver!
First off, assemble your Raspberry Pi (put the case on, plug in the Wi-Fi and sound adapters, and plug in an Ethernet cable). I highly recommend connecting a keyboard (USB) and a monitor (HDMI). This is going to just be a temporary thing until you’ve got everything configured, so you could just unplug your Blu-Ray player and hook it up to your telly (this is basically what I did).
Now you’re going to download Raspbian, which is the official Linux for the Raspberry Pi. I got Raspbian Wheezy from the official downloads page, as opposed to Raspbian Jessie, which is a more recent version. I choose Wheezy because it boots to the command line instead of to GUI, and I thought that for what I was doing, that would be a more sensible choice; I’m sure most of the instructions herein will be the same.
After I downloaded Raspbian Wheezy, I unzipped the resulting file and followed the instructions for creating an SD card using OS X. I used Disk Utility and worked out what the disk number of the SD card was by looking at the entry for ‘Device’ in the table underneath the usage chart, and then I ran the following in Terminal.app, where the n in rdiskn
should be replaced with whatever the disk number you find is:
sudo dd bs=1m if=~/Downloads/2015-05-05-raspbian-wheezy.img of=/dev/rdiskn
This whirred away with no outputs to the Terminal until the process had finished, so don’t be alarmed if nothing appears immediately; just be patient.
I then took the SD card out and put it into the Raspberry Pi. I connected an Ethernet cable to the Pi and to my router, so that it would have an Internet connection. I initially did this with no connected monitor, but I found it too frustrating for words not to be able to see what was happening, so I also plugged in a USB keyboard and a HDMI display. Then, I plugged the power cable in and watched everything boot.3
The username and password for your Raspberry Pi are, by default, pi
and raspberry
. On my first boot, I was logged in without needing these, but it’s worth knowing what they are for now. You ought to see the configuration screen upon your first boot, and so I followed these steps to configure my machine, expanding the filesystem, setting a locale and a timezone, and changing the name of my Raspberry Pi on the network. Then I rebooted, and logged in using the username and password, ending up at the shell.
At this stage, I got bored of being in front of my TV, so I unplugged the USB keyboard and the HDMI display and headed to my iMac, where I brought up my Wi-Fi router’s list of devices on the network. Upon learning the IP address that my Raspberry Pi had on the network, I was able to run
ssh pi@192.168.xxx.xxx
to gain access to my Pi4.
The Ethernet cable was trailing across my living room, so configuring Wi-Fi was the next thing to do. Fortunately, once you have the drivers for your Wi-Fi adapter set up correctly, this is pretty easy5! The Wi-Fi adapter I bought isn’t supported out-of-the-box, but a trip to Stack Exchange revealed that this wasn’t a problem, courtesy of this post by MrEngman on the Raspberry Pi forums. To get the adapter working, simply do
pi@RaspberryPi ~ $ uname -a Linux RaspberryPi 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l GNU/Linux
to find your version number (in this case, it’s 3.18.11-v7+ #781
) and then, on MrEngman’s post, find the .tar.gz
filename which corresponds to that number. Then, I just scrolled to the bottom of his post to find out that I needed to run
wget https://dl.dropboxusercontent.com/u/80256631/8188eu-v7-20150406.tar.gz.tar.gz tar xzf 8188eu-v7-20150406.tar.gz ./install.sh
to get my Wi-Fi adapter working. I rebooted the system before continuing, just to be sure.
sudo reboot
I then turned to the official guide to searching for Wi-Fi networks. I used
sudo iwlist wlan0 scan
to find the list of networks and then added the following lines to /etc/wpa_supplicant/wpa_supplicant.conf
.
network={ ssid="name of my network" psk="password for my network" }
I then rebooted once more, just to make sure, before disconnecting my Ethernet cable.
The next step was to get my USB sound adapter working. I used this guide by Patric Neumann to do this, running the following commands
aplay -l cd /etc/modprobe.d cp alsa-base.conf alsa-base.conf-backup sudo nano alsa-base.conf
before replacing the existing
options snd-usb-audio index=-2
with these two lines:
options snd-usb-audio index=0 options snd_bcm2835 index=1
I then rebooted and tested the output by plugging my EarPods into the sound adapter and then running
speaker-test -t sine
If you don’t hear a tone, it’s not properly configured.
Finally, I installed the tools I needed to get AirPlay running on my Raspberry Pi. I initially used this AirPlay tutorial and this AirPlay tutorial to get it working by installing a GitHub project called Shairport into ~/airplay
, which is currently not under active development. I AirPlayed some audio to the Pi, and it worked fine, which made me very happy! However, when I tested using iTunes to play through the Pi and my iMac simultaneously, the two audio tracks were not in sync. As such, I went looking for ways to make AirPlay synchronise the playback.
I found my salvation in the form of Shairport Sync, which is a fork of Shairport with the added benefit that it is in active development6. Here are the steps I took to install it7 (including a line which checks whether systemd
or System V is the way forward on your machine8), which come from the project’s Readme.
cd ~/airplay ps aux | grep systemd | grep -v grep git clone https://github.com/mikebrady/shairport-sync.git sudo apt-get install autoconf libtool libdaemon-dev libasound2-dev libpopt-dev libconfig-dev autoreconf -i -f sudo apt-get install avahi-daemon libavahi-client-dev libssl-dev ./configure --with-alsa --with-avahi --with-ssl=openssl --with-metadata --with-systemv make sudo make install sudo update-rc.d shairport-sync defaults 90 10
I then configured Shairport Sync so that when I AirPlayed to my Raspberry Pi it would appear with a different name. Since I’m going to hook this up to a Sony Hi-Fi, I ran
sudo nano /etc/shairport-sync.conf
before uncommenting the first line under general
so that it read
general = { name = "Sony Hi-Fi";
before the rest of the settings. Then I rebooted the Pi, and Shairport Sync automatically ran on startup and let me AirPlay my music to it, perfectly synchronised with my other speakers.
Finally, I decided to make a copy of my SD card so that if I messed things up in the future, I can roll back to being satisfied with my progress. To do this, I put the SD card back in my iMac, and then (following the advice of this guide) used Disk Utility to work out what disk number it was (the n in rdiskn
), and then did
sudo dd if=/dev/rdiskn of=~/Desktop/pi.img bs=1m
Mission accomplished!
- I might be going crazy, but a look at the SanDisk website doesn’t seem to show this product as a current part of their line-up, with only a microSD XC card available; hence the link to a shop rather than the official product page. ↩
- I later found out that this adapter doesn’t work without a significant amount of coaxing. Don’t worry, I’ll give the details of how I coaxed it herein! ↩
- Watching all the console outputs whizz past on Linux really does make you feel like you’re in The Matrix. ↩
- A lot of Raspberry Pi guides will tell you that you need to enable SSH yourself, but this appears to be false in newer versions of Raspbian. ↩
- Some guides, such as this one, will tell you to edit
/etc/network/interfaces
to get Wi-Fi up and running, but again, this appears not to be necessary in newer versions of Raspbian. ↩ - Shairport Sync was last updated in October 2015, three months before this was written. ↩
- Note that I did this having already followed the tutorials to install Shairport, so it’s possible that this will not work without having done that. I think it should be fine, but I might be wrong! ↩
- I think Raspbian Wheezy requires the System V method whereas Raspbian Jessie can use the
systemd
method, so this part might be a little different if you went modern and plumped for Jessie. ↩
6 replies on “Making an AirPlay receiver from a Raspberry Pi”
Hi John,
thanks very much for your description, a AirPlay Client based on Raspberry Pi hardware is exactly what I am looking for to implement as a shower-music player.
I tried to follow your turn by turn navigation and got stuck when installing the avahi-daemon. The line
./configure --with-alsa --with-avahi --with-ssl=openssl --with-metadata --with-systemv
doesn’t work, unfortunately. Could I ask you to elaborate on that line, please? That would help me a lot.
Cheers
cmos
Hey cmos, try doing this:
cd ~/airplay/shairport-sync/
./configure --with-alsa --with-avahi --with-ssl=openssl --with-metadata --with-systemv
If that works, let me know so I can update the post. Thank you!
It did not work for me, nor did the fix above.
I had to do it in a slightly different order:
…
sudo apt-get install autoconf libtool libdaemon-dev libasound2-dev libpopt-dev libconfig-dev
sudo apt-get install avahi-daemon libavahi-client-dev libssl-dev
cd ~/airplay/shairport-sync/
autoreconf -i -f
./configure –with-alsa –with-avahi –with-ssl=openssl –with-metadata –with-systemv
make
…
Working somewhat right now. I do not have a USB sound adapter yet, ordered one while installing packages 🙂
Using HDMI right now, sound is choppy, but may be a wi-fi issue i have to work out. I don’t think it’s related to your procedure.
This is with Jessie on a Pi 3.
Thanks for the great tutorial!!
[…] [3] http://www.chickensinenvelopes.net/2016/01/raspberry-pi-airplay-receiver/ […]
[…] Making an AirPlay receiver from a Raspberry Pi – Chickens in Envelopes http://www.chickensinenvelopes.net/2016/01/raspberry-pi-airplay-receiver […]
Thanks for the great guide. One step you might need to add is to symlink the init script into the proper directory for update-rc.d to see it.
cp -l /usr/local/init.d/shairport-sync /etc/init.d/
On my pi device the default prefix was set to /usr/local.