Plug in this internet radio player and listen to your favorite stations on Pandora Radio. Six pushbuttons control the music, while an LCD gives feedback on the song, artist, and other useful information. All of this is housed in a custom acrylic case with access to the Raspberry Pi's ports.

Special thanks to LVL1 Hackerspace (www.lvl1.org) for use of their laser cutter!

Raspberry Pi is a trademark of the Raspberry Pi Foundation.

Step 1: Parts List

In order to build the system, you will need several things. The main piece is a Raspberry Pi Model B with a 5V, 1A power supply. This Instructable is based on a Revision 2 board, but will work on earlier boards with minimal changes. 

Next, you will need an SD card with a Raspbian Wheezy image. Instructions for this process found at: http://elinux.org/RPi_Easy_SD_Card_Setup

Electrical hardware needed:
1) Solderless breadboard (and wire)
2) Serial LCD module (3.3V module from Sparkfun was used: www.sparkfun.com/products/9067)
3) Ethernet Cable
4) USB Keyboard and mouse (necessary for setup, not the final product)
5) Pushbuttons (6) -  "Normally Open" type with threaded mounts
6) 3.3V Regulator (LM1117T-3.3 from Texas Instruments in the TO-220 package type used here)
7) Resistors: (7) ~10kOhm, (6) 1 kOhm
8) Capacitors: (2) 10 uF tantalum (as recommended by TI for 3.3V regulator
9) Pi T-Cobbler from Adafruit (not necessary, but makes GPIO access much easier)
10) Auxiliary audio cable

Other equipment needed:
1) Soldering Iron and solder (for the T-Cobbler breakout board)
2) 1-Minute Epoxy (for the acrylic case)
3) Acrylic (and a means of cutting it)
4) Nylon Standoffs and Screws
5) Velcro strips (with sticky sides)

The acrylic used in this project was 0.08" thick and can be found at Lowe's in 8"x10" sheets. This was great for cutting with a laser-cutter. Other thicknesses can probably be used - this will be left up to your discretion (and experience).

The standoffs used were a combination of (3/8"  - hex -  1.25" -  4-40 thread) and (3/8" - hex - 0.375" - 4-40 thread) nylon male/female standoffs. 4-40 fillister flat head nylon screws were used with these standoffs.

Although this Instructable includes directions for the custom case, this is probably the trickiest part of the design. Familiarity with a laser-cutter is necessary, since every laser cutter and design software package is different.

Step 2: Setting up the Pi

After getting Raspbian Wheezy up and running on the Pi, the OS will need to be configured. Four changes need to be made.

1) In LXTerminal, run the following:

sudo raspi-config  

The SD partition should be expanded to fit the entire SD card, and the boot_behavior option should be set to boot to the desktop on startup. Also, enabling the SSH server will let us work on the Pi on a separate computer, without a keyboard and mouse plugged into the Pi.

2) Next, follow the instructions here to stop the OS from writing to the UART, which we will use to drive the LCD: 

3) Adding Serial Communication to Python:
The OS comes with Python installed. We need to add the serial module in order to drive our LCD module. Run the following in LXTerminal:

sudo apt-get install python-serial

Documentation for the Pyserial module can be found at: http://pyserial.sourceforge.net/

4) Enhancing BASH's GPIO Capabilities:
Now, in order to access the GPIO pins in a more user-friendly manner, we will install the wiringPi library. Instructions are available here: https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/

However, to simplify these instructions, we only need to run:

sudo apt-get install git-core
git clone git://drogon.net/wiringPi
cd wiringPi
git pull origin

Now simply wait for the build to finish, and the operating system is ready to install Pianobar, an open-source program running Pandora Radio.

Important warning: All of the work in this Instructable assumes you are working as the "pi" user. If not, the file locations used later on will need to be altered. Either work as the "pi" user, or be prepared to alter some scripts later.

Step 3: Installing Pianobar

Pianobar is an open-source, lightweight terminal program which runs Pandora Radio. Although the Pi is limited in resources, a lightweight application like Pianobar is right at home.  Setup is simple - run the following from a terminal:

sudo apt-get install pianobar

After entering "y" to all the prompts, Pianobar should be successfully installed. By entering pianobar in a terminal, the program begins. Log into your  Pandora account, and get a feel for the program. (Hint: typing "?" will give a list of keybindings for controlling Pianobar)

This installation has a directory for configuration files located in /home/pi/.config/pianobar. Our next step is setting up configurations for Pianobar, an example of which is given below. (Note that the login information needs to be replaced with your own Pandora account information).

Copy the following into a new file "config" in the /home/pi/.config/pianobar directory, changing the login information:

# This is an example configuration file for pianobar. You may remove the # from
# lines you need and copy/move this file to ~/.config/pianobar/config
# See manpage for a description of the config keys
# User
user = your@user.name
password = password
# or
#password_command = gpg --decrypt ~/password

# Proxy (for those who are not living in the USA)
#control_proxy =

# Keybindings
act_help = ?
act_songlove = +
act_songban = -
act_stationaddmusic = a
act_stationcreate = c
act_stationdelete = d
act_songexplain = e
act_stationaddbygenre = g
act_songinfo = i
act_addshared = j
act_songmove = m
act_songnext = n
act_songpause = p
act_quit = q
act_stationrename = r
act_stationchange = s
act_songtired = t
act_upcoming = u
act_stationselectquickmix = x
act_voldown = (
act_volup = )

# Misc
#audio_quality = low
autostart_station = 123456
event_command = /home/pi/.config/pianobar/scripts/eventcmd.sh
fifo = /home/pi/.config/pianobar/ctl
#sort = quickmix_10_name_az
#love_icon = [+]
#ban_icon = [-]
#volume = 0

# Format strings
#format_nowplaying_song = %t by %a on %l%r%@%s
#format_nowplaying_station = Station %n
#format_list_song = %i) %a - %t%r

# high-quality audio (192k mp3, for Pandora One subscribers only!)
#audio_quality = high
#rpc_host = internal-tuner.pandora.com
#partner_user = pandora one
#partner_password = TVCKIBGS9AO9TSYLNNFUML0743LH82D
#device = D01
#encrypt_password = 2%3WCL*JU$MP]4
#decrypt_password = U#IO$RZPAB%VX2
tls_fingerprint = B0A1EB460B1B6F33A1B6CB500C6523CB2E6EC946

After setting the configuration file, restart pianobar from a terminal. It now automatically logs us into Pandora, and ask what station to play. After selecting a station, an 18 letter number will appear in parenthesis. By copying this number into the config file under autostart_station, Pianobar will automatically start playing that channel once it is opened.

If you are a Pandora One subscriber, additional settings in this config file will let you access high-quality streaming.

Step 4: Setting up the fifo

The fifo lets a script send commands to Pianobar. This is useful for sending button-based commands from a BASH script. In the last step, we configured Pianobar to look in the /home/pi/.config/pianobar directory for a fifo named “ctl”, which still needs to be created. In LXTerminal, the following command makes a fifo:

mkfifo /home/pi/.config/pianobar/ctl

To test that everything is working correctly, restart Pianobar. In another terminal window, enter:

echo 'n' >> /home/pi/.config/pianobar/ctl 

This should change the song being played by Pianobar. If so, we are now able to control it from another terminal (and by extension, a BASH script). All of the commands from Pianobar can work this way - and some interesting combinations can be made. Try “))))))” to increase the volume a lot at one time, or check out the difference between “s” and “s2”. Experimenting with this now will help our scripts make sense later.

Step 5: Setting up the Hardware

There are four main components that need to be connected: the Raspberry Pi, the T-Cobbler breakout board, the serial LCD module, and the six pushbuttons. The Pi should not be connected to the power supply during these steps in case any wires get crossed.

Although it is not absolutely necessary, the T-cobbler makes working with the Raspberry Pi's GPIO pins much simpler. Some assembly is required for the breakout board (instructions for this are available at: http://www.adafruit.com/blog/2012/11/16/new-product-adafruit-pi-t-cobbler-breakout-kit-for-raspberry-pi/)

It is important to connect the ribbon cable the proper direction. On the Pi, the red line of the ribbon cable should be attached closest to the SD card (away from the yellow composite video connector).

Once the ribbon cable is connected to the Raspberry Pi, the T-Cobbler should be placed on a breadboard as shown in the second image.

Step 6: Connecting the LCD

The LCD module from Sparkfun accepts serial input, making it simple to communicate with on the Raspberry Pi's UART Transmit (TX) pin. 

This circuit uses three pins on the T-Cobbler breakout board - 5V, GND, and TX. For more information about the GPIO pins, refer to: http://elinux.org/RPi_Low-level_peripherals

Be careful about running wires next to the 3.3V regulator - it will be producing a modest amount of heat.

Bonus: Now that the LCD module is connected, some quick Python scripting will let us control it. Try the following Python "Hello World" script:

import sys, serial, time
global serialport
LCD = serial.Serial('/dev/ttyAMA0', 9600)
LCD.write('\xFE\x01')      #CLEARS THE LCD

Step 7: Connecting the Pushbuttons

Each of the six pushbuttons needs a GPIO pin connection. The schematic shows a circuit that needs to be duplicated for each pushbutton. This circuit is useful since when the pushbutton is open, this arrangement does not drain any power. However, a logic "1" will be read on the GPIO pin, which is important to note. Also, the 1kOhm resistor on the GPIO pin is important in case the pin is set to output mode when the button is pressed. This would overdraw current on the pin, possibly burning it out. 

On the Revision 2 Pi, the six pushbuttons will connect to GPIO pins 2 (SDA), 3 (SCL), 4, 17, 27, and 22 (in order of vertical appearance on the Pi T-Cobbler). These pins are different for the Revision 1 boards; the pin changes can be found at the low-level peripherals link from the previous step.

EDIT: Since pins 2 and 3 on the Revision 2 board have pull-up resistors on them, the circuit I have shown is unnecessary (and may not function properly). You can simply connect the pushbutton between the GPIO pin and GND. 

The box has six buttons. In the picture, they they are attached from left to right in the pin order given above. The functions are:
1) Change Song
2) Change Station
3) Volume Down
4) Volume Up
5) Pause/Play
6) Menu/Shut Down

Button six has a dual function. If pressed momentarily, it brings up a Menu. If held for more than two seconds, it shuts down the Operating System. Once the Menu is open, new button functions are available. They are:
1) Like the current song
2) Dislike the current song (also skips to the next song)
3) Display the Pi's IP
4) Nothing (yet...)
5) Nothing (yet...)
6) Exit the Menu

Displaying the IP was added to make SSH access easier.

Step 8: Putting it Together with BASH and Python

Now that the hardware is connected, some custom scripts will give us control over Pianobar, the LCD, and the buttons. Programmers will probably cringe, but for simplicity's sake I gave each of these files full permissions for each user (in the terminal, enter "chmod 777 x.xx" where x.xx is the filename). This lets a BASH program execute a Python script, for example.


The first step to creating these scripts is to edit the autostart file in the LXDE directory. Edit this file with:

sudo nano /etc/xdg/lxsession/LXDE/autostart

Now add two lines to the end:

bash /home/pi/.config/pianobar/scripts/PandorasBox.sh

Save and exit, and your OS is configured to start pianobar at startup. It will also begin continuously polling for pushbuttons. 

The scripts used to control the LCD and buttons are hosted in a Github repository. They can be retrieved through the following:

cd /home/pi/.config/pianobar
git clone git://github.com/AyMac/Pandoras-Box.git
cd Pandoras-Box
git pull origin
cd ..
cp -r /home/pi/.config/pianobar/Pandoras-Box/scripts/ .

Now that the scripts have been retrieved, only one step remains to create a working system. 

Final Step: Since one of the options is to randomly select a new station, the main script needs to know how many stations are on a user's Pandora account. (To figure this out, start Pianobar and press "s". This will list all the available stations). Now open the file /home/pi/.config/pianobar/scripts/ButtonPiper.sh and change the "n=" value to the number found above.

Your system should be complete! Please comment on this Instructable with any issues you have, and I will try to address them. The next step talks about making a case, but the system should be fully functional before this step.

Step 9: Custom Box Design

A nice custom box is a great way to finish any project! Unfortunately, fabricating custom boxes is no cake walk. Plans for the box are attached, however should only be used as a general basis for your work. Verify the measurements (and puzzled edges) before starting the laser.

Note: The images attached are not to scale. They give dimensions for a box made from 0.25" acrylic. After a trip to Lowe's, I decided to use 0.08" acrylic instead, so the dimensions were adjusted accordingly when sent to the laser-cutter. Unfortunately, these plans are lost in the ether. You will have to use your judgement with the box design. Access to a drill (or drill press) and a tap set help tremendously. I do not recommend you attempt to cut the smaller holes (3/32") with the laser-cutter - they should be drilled instead.

In the six images provided, seven box pieces are given. One piece is for a horizontal divider inside the box, which is used to stack the Raspberry Pi above the breadboard. Once all seven pieces were cut, the holes should be drilled to the appropriate pilot size and then tapped as noted on the diagrams. Note that the LCD's holes are missing from the face plate, and will need to be added.

Before assembling the sides and bottom, connect the pushbuttons and LCD to the front plate. After this, the four sides and bottom can be assembled using 1-Minute epoxy. I did not use epoxy on the top piece, since I like being able to open the box (hinges or clear tape are both would be a nice choice to connect the top).

Once the sides are assembled, the breadboard should be attached to the bottom using velcro. 1.25" standoffs should be added, then the center piece screwed into these. After connecting the ribbon cable, the Pi should be mounted to the smaller 0.325" standoffs and screwed in place. Secure the top, and the system is complete! Photos of the final product are given in the last step.

Step 10: Final Product

Finished, assembled product for reference. I hope you enjoyed!
<p>This doesn't seem to have been updated in a long time... As it will hopefully help anyone else attempting this build, here is a link to the Adafruit Tutorial for their Raspberry Pi Pandora Radio build. The old Pianobar install instructions here, and elsewhere, don't work! Follow the Adafruit Tutorial's section on installing Pianobar and you'll be all set! Here is the link: https://learn.adafruit.com/pi-wifi-radio/raspberry-pi-setup-1-of-3</p>
<p>Thanks for the updated link - I have not touched this instructable in nearly 2 years, so it's bound to be pretty outdated. Unfortunately I have not spent much time with the RPI lately.</p><p>I've stickied your comment for visibility. Hope the project went well for you!</p>
<p>Thanks! It did go very well. I made a PCB version of your breadboard setup and had all the parts on order but they took so long to get here that I went with the Adafruit kit as a part of my project.(Hint: It's not JUST a radio.) I'll still have to make another using your setup since I basically have all the wiring done... My project will be up on Instructables in a week or two. It's a bit of a different approach but I think you'll enjoy it! I've linked back here in it and gave you a bunch of credit for the inspiration!</p>
Can someone explain to me the point of using 5v and a regulator to get to 3.3v when there is a 3.3v supply from the pi. I am fairly new to this stuff and am just trying to learn. Thanks.
That's a really good question. The answer has to do with the current limit on the Raspberry Pi's 3.3V line. According to the link below, the 3.3V line can output up to 50 milliamps current. Meanwhile, the 3.3V LCD module I used can draw up to 60 mA.<br> <br> While LCD may never draw that full 60 mA, it has the potential to cause issues. Since the 5V supply can supply over 300 mA (when using a 1A power supply), I chose to add the 3.3V regulator. &nbsp;<br> <br> RPi electrical specs:&nbsp;<a href="http://elinux.org/RPi_Low-level_peripherals" rel="nofollow">http://elinux.org/RPi_Low-level_peripherals</a><br>
Could i get an estimate of the cost? i really would like to do this project, and i am a beginner..
This depends on what equipment you already have. For example, I already had soldering equipment, drill and tap set, standoffs, SD card, and resistors. I'll give some prices for the bigger items: <br> <br>Raspberry Pi: $35 + shipping <br>Power Supply: $8 + shipping <br>T-Cobbler: $8 + shipping <br>Serial LCD Monitor: $25 + shipping <br>Buttons: $7 <br>Acrylic Sheets: $8 <br>Epoxy: $5 <br>Capacitors: $2 <br>Velcro: $5 <br> <br>The small things tended to add up quickly - like the bits I had to get from Radioshack and Lowes (buttons, capacitors, velcro, etc). I probably could have gotten some things much cheaper online, but I didn't have the patience to wait for the velcro to ship. All the parts were around $110 with shipping - but since I plan on reusing most of the stuff for future projects, the cost felt reasonable. <br> <br>Hope that helps.
thats very helpful thanks <br>
Note: On the box plans, the center piece has an issue with the spacing of the raspberry pi's holes. If you are making the same box, double check the holes (I don't have the original files to correct the images...)
<p>Thanks for the tutorial - this is absolutely amazing. I just had to use the following command for the fifo to work:</p><p>cd</p><p>exec 3&lt;&gt; ./config/pianobar/ctl</p><p>otherwise my terminal was hanging after the echo command</p>
<p>This is very close to what I have been looking to build however I want to integrate it into say a 2.1 amplified speaker system. My biggest curiosity is if it is possible to set it up to be able to stream say SiriusXM from my account via the web?</p>
<p>Its striking</p>
<p>I would buy this if for sale...</p>
So, I didn't get the controller but, how do I do the rxd? I have the power and ground but, not that. What pin is it on the lcd?
<p>Very nice and interesting work</p>
<p>Would anybody be interested in my version? I made it using Python only (no Bash) it works using only 3 buttons and 2 LEDs and a motion sensor (no screen). Total cost is around $45 US including the Raspberry, a pack of LEDs, a pack of resistors, female to female jumper wires and an empty Tea Box. </p>
<p>Hey Jay - I'd be really interested to see your software! Do you have it on a repo?</p>
<p>If anyone is interested I did a PCB layout for the buttons and attachment to the LCD screen. A lot more work than using a breadboard but it saves space and doesn't tie up your breadboard in the process. Send me a message if you want the file! </p><p>R1-R7 are 10K</p><p>R8-R13 are 1K</p><p>I'm going to try etching it with the toner transfer method. We'll see if it takes...</p>
<p>This looks really cool, but I don't have access to a place to get the housing. Could it be, say, 3D printed? Then a company like Shapeways (or a friend with a 3D printer) could make the model. What would be involved in making that into a model?</p>

About This Instructable




More by Ayy:Pandora's Box - An Internet Radio player made with a Raspberry Pi! 
Add instructable to: