Last week I finished making my second Raspberry Pi powered internet radio.

Raspberry Pi Radio

Here’s a list of the hardware I used.

  • Raspberry Pi Zero
  • Pimoroni Speaker pHat amp
  • Protozero prototyping board
  • Adafruit 7 segment display backpack
  • 4 ohm 3 watt speaker, two buttons and a potentiometer from my box of bits and pieces
  • USB wifi adapter (if only there was a Pi Zero with wireless built in…)
  • Muji photo frame

The radio is a development of one I made a year ago, which borrowed heavily from the many internet radios Giles Booth has made.

I prototyped the hardware by stringing everything together with croc-clips and a breadboard. I removed the small speaker from the Speaker pHat and soldered some solid core wires onto the pads to hook-up the bigger speaker.

Raspberry Pi Radio

The code is based on Giles’, but I’ve modified it to use GPIO Zero and have added a second button which shuts the Pi down. The program runs as a subprocess, which is Adafruit’s code to display a clock on the 7 seg.


import time
import os
import subprocess
import sys
from gpiozero import Button
from subprocess import check_call

pid = subprocess.Popen([sys.executable, ""])

def shutdown():
   check_call(['sudo', 'poweroff'])

shutdown_btn = Button(17, hold_time=3)
shutdown_btn.when_held = shutdown

# pause()

button = Button(23)

# set station to 5 live
station = 5

os.system("mpc play " + str(station))

while True:
  station += 1
  # Assumes there are 7 stations
  if station > 7:
     station = 1
  os.system("mpc play "  + str(station))
  # pause to debounce - is quite long as found the buttons quite bouncy

You can also find the code on GitHub.

Once I was happy it all worked as expected I drew a template of the Muji photo frame on graph paper to get the layout of the components right and mark up where I would need to drill holes. The small holes weren’t any trouble, and were easily made in the two layers of the frame with my Dremel set to low speed. The larger holes were more of a problem and I destroyed one frame before discovering that masonry drill bits seemed to work better than any other I had. As bits of Perspex splintered around me I was glad to be wearing safety glasses! The back sheet needed a window cutting out of it for the 7 segment display to poke through. Again my Dremel was the best tool I had for this, and I managed to get a reasonably tidy hole cut.

I spray painted the back of the top sheet of acrylic white and mounted everything on it before doing the soldering. Finally I hot glued the 7 segment display into place.

This is the triple-deck arrangement of boards with the Speaker-pHat at the bottom, Protozero in the middle and Raspberry Pi Zero on top.

Speaker-pHat, Protozero and Raspberry Pi Zero triple stack

There are more photos here.

I’ve a few ideas for future modifications:

  • Work out how to get the VU meter on the front of the Speaker pHat pumping
  • Or use the LEDs to indicate which station I’m listening to
  • Make it tweet whenever I change stations (can I code it to only tweet after a station has been streaming for ten seconds so it doesn’t go crazy when I change from 5 live to Radio 2?)