Raspberry Pi Zero AirPlay Speaker


 

Looking for a new project to build around the Raspberry Pi Zero, I came across the pHAT DAC from Pimoroni. This little add-on board adds audio playback capabilities to the Pi Zero. Because the pHAT uses the GPIO pins, the USB OTG port remains available for a wifi dongle. Perfect for a small wireless speaker project!

Hardware

The project is fairly simple and requires following components:

The Raspberry Pi Zero is obviously the brains of the project and will run the Shairport software to wirelessly stream music to. The pHAT DAC is a neat little add-on board adding audio to the Raspberry Pi. It has a jack output, and the possibility to add RCA connectors to it. The fact that the RCA connectors are not presoldered is a bonus, as it exposes the audio lines and keeps a low profile. A small mono amplifier from Adafruit then takes the audio from the pHAT and amplifies it (what else?), playing audio from the speaker. A wifi dongle connected via the USB OTG port provides wireless network connectivity for streaming.

I decided to make a mono speaker to keep things smaller. Making this project with stereo support would imply having a second speaker and replace the mono amplifier by a stereo one.

Screen Shot 2016-01-20 at 22.36.19IMG_0674

I know this isn’t the nicest way to convert stereo to mono (at all?), but it works. I tried to tackle the problem from a software point of view by downmixing the stereo to mono, but with no success. If I do manage to find a proper solution, ideally in software, I’ll be sure to update this post. If anyone has tips on how to achieve this in a simple way, feel free to leave it in the comments!

Software

On the software side, nothing too difficult either.

I started off from the latest Raspbian Jessie image which can be downloaded from the official Raspberry Pi website.

Using “dd”, I put the downloaded image on a 8Gb microSD card and then used it to boot the Pi Zero from.

Once booted, I set up the wifi in the graphical desktop environment by selecting the correct SSID and entering the wifi password. With the Pi Zero connected to the network, I could update the software.

Then came the time to install the project specific software: support for the pHAT DAC and the AirPlay software.

pHAT DAC

A tutorial on how to install and use the pHAT DAC is available on the Pimoroni website. I did things slightly differently though, as I didn’t disable the default sound driver.

Device-tree overlay is used to describe hardware. As the pHAT DAC uses the same hardware as the HiFi Berry, the same overlay can be used by appending the following lines to the config file:

After rebooting, I listed the audio devices using the “aplay” application, and there it was: card 1 – HiFi Berry.

To make it the default for audio playout, I updated the asound.conf file and replaced every reference to “card 0” by “card 1”.

A final reboot ensured everything was applied.

ShairPort

Shairport is an Airtunes emulator, allowing compatible iOS devices or iTunes to stream audio to the device running it.

A few dependencies need to be met before Shairport can be installed and run.

With the dependencies taken care of, the actual Shairport software can be installed.

At this stage, it’s possible to test if everything was installed properly by manually running the shairport.pl script.

Afetr confirming everything works as expected, the shairport application can be daemonized in order to have it automatically start at boot.

Finally, the shairport file needs to be modified in order to specify the name of the AirPlay device. This could be anything you want. In my case, I picked something generic, such as “AirPi”.

Reboot the Pi. Shairport should be running automatically.

Enclosure

Time to package the working AirPlay speaker into something nice, by making a good looking enclosure for it.

This was actually the hardest part of the project. Mainly because I wanted to make it out of wood and with a slightly tricky shape. It meant doing some maths before cutting pieces at the right length using the miter saw and then ensuring the correct angles were cut as well in order to properly connect the pieces. As I’m not a woodworker, and the tools at my disposal are not the most suited either, the results are not always as accurate as you’d expect. That’s where sanding paper and wood filler come to the rescue …

Screen Shot 2016-01-21 at 20.07.53 Screen Shot 2016-01-21 at 20.05.28

Some accents were given to the build by adding 3D printed parts: the side panels and the speaker grill. One of the side panels was not glued into place and can be removed if needed, in order to access the electronics. I was hesitating to paint the 3D printed parts in a different color for a chrome or brass look, but ended up leaving the pieces as is. It gives the build a little funky side, no ?

IMG_0708

Like the project? What else would you make with a Pi Zero? Let me know in the comments!

 

 

35 thoughts on “Raspberry Pi Zero AirPlay Speaker

    1. I’m not sure, I haven’t tried to AirPlay to multiple speakers at once.

      From a first quick search, it looks like AirPlay from an iOS device (iPhone, iPad, iPod, …) does not work to multiple devices out of the box. A third party app seems to be required, and even then there would be limitations it seems. AirPlay to multiple devices from a PC or MAC via iTunes seems possible though.

      https://discussions.apple.com/thread/5353980?tstart=0

    1. You can control the volume from your smartphone via AirPlay, but if really needed, you could add two buttons connected to free GPIO pins and have them trigger the command for volume up and down.

    1. This one could easily be made portable if powered from a battery. I didn’t know about the USR-S12, something worth looking into 🙂
      If you end up building one, I’d love to see the result!

  1. Raspbian is now using systemd instead of sysV init script.
    Here is a sample systemd configuration:

    # cat /etc/systemd/system/shairport.service
    [Unit]
    Description=shairport – Airtunes emulator
    After=network.target avahi-daemon.service

    [Service]
    EnvironmentFile=-/etc/default/shairport
    ExecStart=/usr/local/bin/shairport.pl $SHAIRPORT_OPTS
    Restart=on-failure

    [Install]
    WantedBy=multi-user.target
    Alias=shairport.service

    # cat /etc/default/shairport
    SHAIRPORT_OPTS=”-a AirPi”

    # systemctl start shairport.service

    1. Hi Ben
      I put in these systemd config files, and I can start and stop shairport and see its status.
      However when I try sudo systemctl enable shairport.service to get the ssytem to start automatically on boot up I get an error:
      Failed to execute operationL invalid argument.

      I’ve triple checked the config files. Any idea how I resolve this?

  2. Frederick,

    Jeetje wat maak jij gave projecten, erg inspirerend!

    I am building a retro-radio and i have the same amp and I succeed in down-mixing the audio to mono with the following settings:

    nano /etc/asound.conf

    pcm.!default makemono

    pcm.makemono {
    type route
    slave.pcm “hw:0”
    ttable {
    0.0 1 # in-channel 0, out-channel 0, 100% volume
    1.0 1 # in-channel 1, out-channel 0, 100% volume
    }
    }

    By the way you should try Archphile.org. Very light program with a webinterface and also the options for Airplay and Upnp. I am using this in all my Radio-projects.

    Succes!

    Harry

    1. Hey Harry, thanks! Het is net de bedoeling om mensen te inspireren om zelf dingen te bouwen en uit te proberen. Ik ben blij dat het lukt 🙂

      I tried something similar for the downmixing but couldn’t quite get it to work. I’ll have a look at your snippet and see how it differs from what I had.

      Thanks for the tip on Archphile, it looks interesting!!

        1. Hi! Great!
          Thanks for the input guys. Haven’t tried this before (modding old speakers), so I have a couple of questions:
          – It seems that both with the Justboom and the Adafruit bonnet I would need some extra power, e.g. an extra power supply, than the power for the RPi0?
          – I am also in doubt that the 3W from the Adafruit bonnet would be enough to get the speaker to play?
          – What about the stereo / mono issue? The speaker includes a bass and a midtone speaker – see an image here: http://www.carlssonplanet.com/en/speakers/produced/sonab-od-11/#
          here are some specs:
          Principle: Omnidirectional, bass reflex type. Diagonally facing speaker-
          elements for frontfacing wall or bookshelf placement or upwardsfacing floor-position
          Impedance: 8 ohms
          Frequency range: 45-18.000 Hz
          Frequency response: 52-15.000 Hz ± 4dB
          Crossover frequency: 1800 Hz
          Mid-bass: 1pc 6.5 inch 8 ohms Peerless SC165.
          Tweeters: 1 pc 5 cm 8 ohms Peerless MT20HFC

          – best
          simto

  3. The photograph differs from your schematic overlay in the sense that there is a grey cable going from “L” output on the Phat DAC to a pin that I am unable to see on the amp breakout. Am I correct to assume it goes to A- on the amp chip? All help appreciated 🙂

    1. The grey wire is the GND connection. On the drawing, I’ve connected it to the GPIO header, rather than the L channel’s GND pin on the picture.

  4. Hi, I was thinking of building a tower speaker and doing this, but using 2 car speakers. Do you think this would work if I changed the amp for a bigger one? Thanks

  5. Hi, could you explain why the 2 x 100 ohm resistors please ? Is it just for the mono conversion ?

    i’m planning to connect my phat dac to a an orange cr6s mini amp, on aux stereo input. I was planning to use the same phat dac output as you …

    Thanks

        1. Like I said, I used the mini amp to connect the phat dac, so I just connected/soldered the phat dac output to the aux in (stereo),

          The thing is … it works … but the sound is quite fuzzy . But when i lower down right audio or left audio the sound is quite good. So when it plays both right and left, the sound is lowered and like coming from a cave …
          Any idea ?

          I also have a lot of noise but i currently use two separate power inputs, I’m planning to get the power from lowering down the 18V from the amp to 5V … maybe it will help for the noise …

          1. Getting a common ground by using the same power supply is worth a try.

            As for the fuzzy audio: what is your audio source on the Pi and which application do you use to play it? Perhaps check the volume settings on the Pi itself as well, make sure it is not at 100%, and try to lower it there and work purely with the amp to increase the volume.

          2. Hi,

            The only thing i still don’t get on the Phat dac is:

            in the case you don’t power the amp with the rpi 0, and you connect the amp with the stereo RCA pinout, how do you get the Ground, is the default GND pin OK ?

            For example, if you want to connect this kind of stuff (L- and R-) :
            https://www.adafruit.com/product/987

            Simpler with the Jack i guess … with should be GND embedded …

            Thanks a lot

          3. According to the description of the Adafruit link: if you don’t have differential outputs, simply tie the R- and L- to ground.

            So yes, the standard GND connection should work for L- and R-. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *