E-mail : *

Spotify is such an awesome music service. Raspberry Pi Zero is such an awesome ultra-mini computing device. Obviously, combining the two is something I must do!!! The idea here is to make something that’s stylish, portable, can play Spotify, and hopefully also display visuals such as album art. If you’re interested in following this project, feel free to click on the “Follow” icon just above this paragraph. Click the video below to see an overview, otherwise, scroll down to see how I made this musical masterpiece!

Step 1

The Idea

The Pi Zero W is a phenomenal full linux computer that’s basically the size of a stick of gum. And the “W” version has both bluetooth and wireless built in! That opens it up to so many amazing potential projects. One that I have been really wanting to do is a portable streaming Spotify client that displays album art or other visuals. Does it have to be a Pi Zero? Nope. You can use any other Pi or Pi alternative, but I just love the portable size and power consumption of the Pi Zero. The only issue is that the Pi Zero (at least the current iteration at the time of writing this guide) doesn’t support Audio Out, unless it’s through HDMI, but I’ll touch on that a little later on. There are pre-built audio output “hat’s” available, if you want to go that route. But anyway, here’s the basic goals and obstacles I’ll have to overcome for making this project work:

  • Add audio output to the Raspberry Pi
  • Add an amp/speaker to the Raspberry Pi
  • Find a way to stream Spotify as a “headless” client
  • Display album art on a small LCD screen.

Step 2

Setting Up The Pi Zero

Before we do anything else, the first thing is to get the Pi Zero up and running. This is pretty much the standard setup for any Raspberry Pi that you get. Here’s the basic items a Raspberry Pi requires to setup, if you are unfamiliar with the process:

The first step is to load the Raspbian Operating System onto the SD card. The Raspbian OS can be downloaded from here. It downloads as a zip file that contains the Raspbian image file, and the way to transfer that image file to the SD card on Windows is by using the Win32 Disk Imager. Once you launch Win 32 Disk Imager, you can choose the drive letter for your SD card, choose the Raspbian image, and then click “Write” to write the image to the SD card. Then eject the SD card and put it in the Raspberry Pi, along with the monitor, keyboard/mouse, and power.

After the Pi boots up, you can click on the wireless icon in the upper right and choosing your wireless network. Then by right clicking on that same wireless icon and choosing “Wireless & Wired Network Settings”, you can set a static IP address for your Pi. Lastly, you want to click on the menu icon in the upper left and choose Preferences > Raspberry Pi Configuration. Then click on the “Interfaces” tab and make sure SSH is enabled. After that, everything should be setup on the Pi and we can begin the dirty work.

Step 3

Adding Audio Output

The first biggest hurdle to overcome is the fact that the Pi Zero (at least at the time of this post) doesn’t have audio output. There are a few different ways to get around that.

  1. Split out the audio from the HDMI output
  2. Purchase a Pi Zero “hat” extension
  3. Make a simple circuit to extract audio from the GPIO pins

And guess what…I’m going with option 3, of course. The Adafruit blog has a fantastic guide for how to make your own PWM audio adapter. And it’s actually surprisingly easy…if you’re not afraid of a soldering iron. The basic idea is to force the audio through the GPIO pins of the raspberry pi. In this case, it’s pins 18 and 13 (and ground). You can see a schematic below for what I’m going to try and accomplish.

And here’s the parts it requiers:

  1. 2 x 10 µF capacitors
  2. 2 x 0.33 or 0.01 capacitors
  3. 2 x 270 Ohm resistors
  4. 2 x 150 Ohm resistors
  5. Female 3.5mm audio jack

I was able to arrange the components on a bread board and then hooked up a pair of powered speakers for testing.

So to see if this micro-contraption works, we need to tweak the raspberry pi software a little bit. Since we enabled SSH on the raspberry pi, we can login into it remotely from a different computer. On Linux and Mac, you can open up a terminal and just type “ssh pi@192.168.###.###” (replacing # with the static IP you set) and login with your password. On Windows, you’ll need a third party SSH tool. I’m fond of Putty for Windows. Download and install it, then set up a new SSH connection pointing to your Pi’s static IP. Then just login with your password.

We have to tell the Pi to force audio to the PWM pins (Pins 18 and 13), and there are several different methods of doing this, but one of the simplest ways I found was to add a line to the configtxt file:

  • sudo nano /boot/config.txt
  • #add to bottom of file
  • ctrl X (to exit) Y (to confirm save)
  • sudo reboot

After rebooting, I now need to force the Raspberry Pi’s audio through the PWM channel. So after reconnecting to the Pi through SSH, type “sudo raspi-config” and go to 7. Advanced Options > A4 Audio > 1 Force 3.5mm. Then save and exit. With the powered speakers on and plugged into the breadboard, and the breadboard plugged into the Raspberry Pi, I can test it all out by playing some audio using this command:

  • aplay /usr/share/sounds/alsa/Front_Center.wav

If you can hear audio then everything’s working correctly and we can move everything from the breadboard to a nice, compact circuit board! To make it easy to connect the circuit board to the Pi Zero, I turned the Pi Zero off, disconnected everything, and soldered some header pins to each of the pin ports. Then on the circuit board, I soldered some female header pins so that they could fit together easily. From there I soldered on all my components, fired the Pi back up, and tested it out again to make sure it still worked. Looking good! Now for the Amp!