Posted in Raspberry PI | 0 comments

Turning an old radio into an AirPlay radio with a Raspberry Pi.

Intro

This past spring I bought an old radio on eBay. None of the electronics worked, but the dial to change the channel tuning still spun. I wanted to setup a system in my home where I could play music remotely from my iPhone to the radio. AirPlay was an obvious choice, since we have many iOS devices. I also wanted to replace the electronics in the radio for better sound.

The Parts

  • An old radio sold for parts. Check antique stores or eBay for your favorite. Make sure it is big enough to hold all the parts you will add on the inside.
  • A Raspberry Pi. I used a model B version 2. You may want to consider the new Raspberry Pi B+.
  • HiFi Berry. This gives better sound out of the older Raspberry Pi. I bought the version that allows me to still use the GPIO pins. They make a new one for the new pi, but I hear the sound quality on the new pi is improved. It might be enough for you without the HiFi Berry.
  • Wifi adapter
  • If you want to use a wired connection, use an ethernet cable. I added a plate mount ethernet port to the back of the radio and connected it with a jumper ethernet cable. Adafruit makes one too.
  • An amplifier. I chose the 2x25W at 6 Ohm TDA7492 Class-D Audio Amplifier Board Only. It’s small and cost effective.
  • Speakers. I first thought I needed 4″ speakers. I tried Dayton Audio RS100-4 4″ Reference Full-Range Driver 4 Ohm speakers, but they sounded too tinny. After I got the old radio apart, I found that I could use a 5″ speaker. I wanted full range. I went to my local electronics store and tried a few out. Jensen JRX252 speakers gave me some good bang for the buck.
  • Binding post. Old AM radios were mono, and thus only used one speaker. I plan to make a stereo version someday by making a separate box for the second speaker. For now, I’ll just put speaker wire access on the back of the radio with the binding post.
  • Banana clips. When I’m ready to make the second speaker box, I’ll use banana clips for the speaker wire.
  • Power supply. I chose the Universal Laptop Power Supply 15-19.5V DC with 5V USB Charging Port. It allowed me to power both the amp and the pi with the same power brick.
  • USB cable to connect the Raspberry Pi to the power brick.
  • C13 power socket. This one isn’t the exact one I purchased, but it looks similar.
  • C14 Power cable
  • Heavy duty power switch for the master power
  • Momentary switch. I bought one from a local electronics store. But this one is similar. It does not need to be fancy. We’ll use this to initiate the shutdown of the pi before pulling the master power.
  • RCA Cable. Choose a stacking RCA cable so that you can easily plug in the aux input. If you’re an audiophile, you may want a better cable.
  • RCA to 1/8″ Stereo adapter. I had an extra sitting around, but this one would work. Use this to plug an aux input in directly and not use the AirPlay.
  • Audio potentiometer. I used a 100K Audio Taper Stereo Potentiometer, although this one linked is too short. Get a long shaft so that you can reach the volume knob on the outside of your radio. Also, get one that has an audio taper instead of a linear taper. That will get it to behave as you expect.
  • Speaker cloth. There are lots of kinds out there. Aesthetically, this one worked well with my old radio.
  • PCB board. I used one from Radioshack, but there are some nice ones from Adafruit.
  • 5mm LEDs. I used a white one and a red one. I put them behind the tuner dial. The white one shows that the pi is turned on. The red one turns on just before the pi shuts down to let you know what’s happening. Both of these are optional.
  • 2x 270 Ohm resistors for the LEDs. At least that was the right brightness control for me behind the tuner dial.
  • Jumper cables to attach to the GPIO pins.
  • Misc. other wire, solder, electrical tape, screws, baltic birch boards, etc. to secure items in the case.

Assembly

See the following two diagrams for how to plug everything together.

circuit

airPi_bb

Software

Most of the work is done with Volumio. Follow their instructions to download the disk image, configure the pi, and get everything running.

When the master power switch is turned on, everything boots up. The white LED turns on. It takes a bit for the pi to run through it’s startup sequence and start running volumio. You’ll hear a startup sound from Volumio when it is ready to connect in AirPlay.

You could just shut down the everything with the master switch. But I wanted to have a button that shuts down the pi first. You’ll need to configure the Raspberry Pi and Volumio to use the GPIO pins.

sudo su
wget http://sourceforge.net/projects/raspberry-gpio-python/files/raspbian-wheezy/python-rpi.gpio_0.5.11-1_armhf.deb
dpkg -i python-rpi.gpio_0.5.11-1_armhf.deb

Use the following code:

#!/usr/bin/env python
# created by chris@drumminhands.com

import os
import glob
import time
from time import sleep
import RPi.GPIO as GPIO
import atexit
import sys

########################
### Variables Config ###
########################
led_pin = 15 # LED 1
button_pin = 22 # pin for button to shutdown the pi
debounce = 0.2

####################
### Other Config ###
####################
GPIO.setmode(GPIO.BOARD)
GPIO.setup(led_pin,GPIO.OUT) # LED 1
GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # falling edge detection on button 2
GPIO.output(led_pin,False);

#################
### Functions ###
#################

def cleanup(): #if anything happens, cleanup the GPIO pins
  print('Ended abruptly')
  GPIO.cleanup()
atexit.register(cleanup)

def shut_it_down(channel):  #shutdown the pi
    print "Shutting down..." 
    GPIO.output(led_pin,True);
    time.sleep(3)
    os.system("sudo halt")

####################
### Main Program ###
####################

# when a falling edge is detected on button_pin and button3_pin, regardless of whatever   
# else is happening in the program, their function will be run   
# GPIO.add_event_detect(button_pin, GPIO.FALLING, callback=shut_it_down, bouncetime=300) 

print "Volumio Button Running..." 
GPIO.output(led_pin,True); #light up the lights to show the app is running
time.sleep(3)
GPIO.output(led_pin,False); #turn off the lights

while True:
	GPIO.wait_for_edge(button_pin, GPIO.FALLING)
	time.sleep(debounce) #debounce
	shut_it_down()

Set this code to automatically run at startup.

That’s It

I learned a lot about hardware, cabling, etc. on this project. It works well. I just wish it booted up faster. Some people may end up just having it turned on all the time.

See more pics on my Flickr page.