For the past few weeks (months?) whenever I was flashing an SD card with Balena Etcher I would see an ad for creating a Spotify Connect server out of a Raspberry Pi. I never really thought about it until I was cleaning the garage (not for fun, I’m moving to Texas) and I wanted to play some music. I have had a standard stereo receiver with some stand up cabinet speakers for a while it just hasn’t gotten much use this year. When I had used it I would just plug my phone into a cable I had directly plugged into the receiver and I would play songs that way. Well now I have an iPhone, no more Androids, and now I don’t have a headphone jack. Great. Fuck the dongles. I now had a need for a Spotify Connect server, which honestly is what I should have done a while back. Balena has their own special way of doing things, which I kinda don’t like so I searched out a different solution.
The software I used is called Raspotify and it is really simple to get up and running. All you need is a (any) Raspberry Pi, the SD card for it, power, and a way to plug it into your stereo. Almost any Pi except a Zero are basically plug-n-play as they have a 3.5mm audio jack. Super simple. After flashing Raspbian Lite to the SD card, boot the Pi and then run one command: curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
That will get you going, after the Pi is finished you should now see a Spotify Connect server named “raspotify” on your Spotify app. You can edit /etc/default/raspotify to change the defaults if you want. Like stream quality and the server name etc. I highly recommend doing this. I noticed the volume was super low by default, well the Pi had its volume set to 40%, dang. Use the command alsamixer that will let you up the volume. I tend not to use things at 100% of the volume available, most times devices start to distort at max levels. I usually stick to 90% for my volume level.
I initially got it setup and running on a Pi 3B+ and it worked just fine, except it didn’t sit well with me using a full blown Pi for such a simple task as streaming music. It just isn’t right. You could use one single Pi as a Spofity connect server as well as host many other things (Pihole etc) but I like to keep things separate. Less chance of failure for me, since I tend to not leave shit alone. Enter the Raspberry Pi Zero W. But the RPi Zero doesn’t have an audio output, ha-hah! There are a few audio DAC hats out there for the Zero that add outputs, but I don’t have one and I didn’t want to buy one or wait for it to get delivered. So we have to make one! It is actually very simple, as long as you have the parts around that is. We are going to create a pair of basic line-out outputs. Good for receivers not so good for things like headphones. Its also just a basic output no extra DAC here. If you find the audio quality isn’t up to snuff (I have not noticed a difference but I have not also tested it thoroughly or compared it to other sources, yet) then a DAC hat is for you.
To create audio outputs for the RPi Zero you need:
- (2) 150ohm resistors
- (2) 270ohm resistors
- (2) 33nf poly capacitors (labelled 333 or a 10nf labelled 103)
- (2) 10uf electrolytic capacitors
- (1) audio connector (either a pair of RCA connectors or a 3.5mm jack)
(There is a wiring diagram at the bottom that will show you the circuit needed for the simple audio outputs, the diagram shows a series of diodes used to stop back voltage but I have not seen this part built anywhere, just referenced)
I took a 5cm x 7cm PCB and soldered up some components and I couldn’t be happier with the outcome. I used the RPi Zero W, a small DC-DC step down module, an LED, and a DC power jack. I also used a female 40pin header so I can remove the Pi whenever I want. All this was soldered to a 5cm by 7cm PCB. I collect a lot of random electronics and junk so all the parts I used I had collected from eBay or scavenged through the years, it helps a lot with projects like these. I opted for RCA jacks instead of a 3.5mm plug. To me it has more of a “Stereo” feel to it that way. The RCAs were salvaged from an old audio board but you can get them off eBay or Mouser etc. I found it easier to double sticky tape the RCA to the PCB then solder the leads down, since the RCA is not designed to just plop in a normal size PCB hole this worked really well. The LED power status is also pretty easy, just an LED with a 330ohm resistor. Connected to a UART pin and wired to ground with a simple code change in config.txt to enable UART you get a power LED! Pretty handy to know if the Pi has booted or is ready for shutdown (shutdown button, which I added to a second unit I ended up making for a friend). You also need to edit config.txt to enable the pins for our audio outputs.sudo nano /boot/config.txt
then at the very bottom we are going to add:
(this line of code tells the Pi to spit out audio on those two GPIO pins, without it we get no sound)
Save and reboot.
After it was all said and soldered there are a couple of things I would do for a Mark II. If I had laid down all the capacitors instead of standing them up I could have made the RPi Zero fit over the components. It would have made the footprint stay to the size of the 5cm by 7cm PCB. As it is now the Pi sticks out over the back of the PCB. But I am still happy with it.
Now I cant have a bare gadget just flopping around, something could make contact with it and I would be sad. So it needs a case. Now most people would probably fire up Fusion 360 but I just can’t bring myself around to sitting down and learning the damn program. So off to TinkerCAD I go! I always import STLs of the pieces I am using, like the PCB, a RPi Zero, the DC plug etc. This helps me a ton when modeling a box for something.
The end result was great, even though I could make improvements this one will work nicely. If I need to make another one I will probably make the changes and redesign a new case for it. But that didn’t happen. After I finished this project I was immediately asked to make two more for friends and family. I ended up making the same design three times. For the shutdown button that was added I just drilled a hole and slapped in a mom-open push button. Heres an example for a safe shutdown for a Pi if you needed it.
Good reference page http://shallowsky.com/blog/hardware/pi-zero-audio.html
Walk-through on installing Raspotify https://pimylifeup.com/raspberry-pi-spotify/
I used this adafruit page as reference and the wiring diagrams https://learn.adafruit.com/adding-basic-audio-ouput-to-raspberry-pi-zero/overview