text: Introduction: Pandora's Box - an Internet Radio Player Made With a Raspberry Pi!
  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 () 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..
  Step 2: Setting Up the Pi://drogon.net.
  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
  #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 = [32m%t[0m by [34m%a[0m on %l[31m%r[0m%@%s
  #format_nowplaying_station = Station [35m%n[0m
  #format_list_song = %i) %a - %t%r
  #
  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..
  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:
  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.open()
  LCD.write('\xFE\x01') #CLEARS THE LCD
  LCD.write('\xFE\x80') #SETS THE CURSOR ON THE FIRST LINE, FIRST CHARACTER
  LCD.write("HELLO")
  LCD.write('\xFE\xC0') #SETS THE CURSOR ON THE SECOND LINE, FIRST CHARACTER
  LCD.write("WORLD")
  LCD.close()
  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.
  AUTOSTART FILE:
  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:
  pianobar
  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.
  PYTHON AND BASH SCRIPTS:
  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!
  First Prize in the
  A/V Contest
  Finalist in the
  Instructables Design Competition
  2 People Made This Project!
  Recommendations
  162 Comments
  5 years ago on Introduction
  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:
  Reply 3 years ago
  I'd like to attempt this. The adafruit instructions depend on an adafruit LCD display. I've happen to have the parts on hand for this set of instructions, but before getting too deep, do you remember what steps were out of date?
  Reply 5 years ago on Introduction
  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.
  I've stickied your comment for visibility. Hope the project went well for you!
  Reply 5 years ago on Introduction
  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!
  8 years ago on Introduction
  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.
  Reply 6 years ago on Introduction
  Why
  Reply 8 years ago on Introduction
  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.
  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.
  RPi electrical specs:
  8 years ago on Introduction
  Could i get an estimate of the cost? i really would like to do this project, and i am a beginner..
  Reply 8 years ago on Introduction
  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:.
  Reply 8 years ago on Introduction
  Thanks!
  Reply 8 years ago on Introduction
  thats very helpful thanks
  8 years ago on Introduction
  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...)
  3 years ago
  Hi! I've been trying to work on a system very similar to this one, and I've used this Instructable as a reference. Problem is, I can't get my Pi to open pianobar on boot. I've tried a ton of different methods (this one included) it seems that I can make it perform other operations on boot, it just won't start pianobar. Any suggestions? Thanks!
  4 years ago
  Hi, can you advise how long or short the delay can be (through using the pause button) ?
  4 years ago
  good
  4 years ago
  Thanks for the tutorial - this is absolutely amazing. I just had to use the following command for the fifo to work:
  cd
  exec 3<> ./config/pianobar/ctl
  otherwise my terminal was hanging after the echo command
  4 years ago
  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?
  5 years ago
  NICE
  5 years ago
  Its striking
  5 years ago
  I would buy this if for sale...