Overview – What is it
Using a Raspberry Pi you can create a pretty cool stand alone Pandora Streamer. Its a pretty easy project to put together and will only take an evening. Even though this project is basic from a Electrical Engineering standpoint you will learn the basics of GPIO, Python, BASH and basic Circuts. The best part is you can totally use this project on a daily basis. This version also will allow you to use the device as a Airplay reciever when you are not using Pandora.
I do not just want to show you what i did but show you where i went wrong and how i got the correct answers so you will feel confident trying this stuff yourself. This project cost me about $50 – $75 USD and was a blast.
I originally found this project on Instructables (http://www.instructables.com/id/Pandoras-Box-An-Internet-Radio-player-made-with/?ALLSTEPS). I started with this but re-wrote most of the code. I also changed the circuts to remove components that were unnessicary.
What you will need
- Raspberry Pi (sparkfun, Element14, adafruit)
- Breadboard
- PI Cobbler
- LCD Screen
- Buttons
- Resistors (10k and 1k)
Optional
-
Completed Pandora Pi
-
Moved off the breadboard
-
Button Wiring
-
LCD hookup
- Completed Pandora Pi
- Moved off the breadboard
- Button Wiring
- LCD hookup
Lets get started
Step 1 – Get the Raspberry Pi Prepped
A. Flash the Raspberry Pi’s SD Card with the latest version of Raspbian Weezy. First, download the latest OS. Second, put it on the SD Card.
B. Next, Stop the OS from writing to the UART, which we will need to drive the LCD:
In LXTerminal:
sudo nano /boot/cmdline.txt
And change:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 $
to:
dwc_otg.lpm_enable=0 console=tty1 $
Next:
sudo nano /etc/inittab
And change:
#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
to:
#Spawn a getty on Raspberry Pi serial line
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Reboot the Pi
C. Adding Serial Communication to Python, This lets us talk to the LCD:
In LXTerminal:
sudo apt-get install python-serial
D. Enhancing BASH’s GPIO Capabilities, This lets BASH talk to GPIO. This is because we only launch the Python files if we detect HIGH on GPIO pin 22 or we know buttons are connected:
In LXTerminal:
sudo apt-get install git-core
git clone git://drogon.net/wiringPi
cd wiringPi
git pull origin
./build
Go Wireless (optional)
If you choose to go wireless (much cleaner) plug the WIFI adapter into one of the USB ports. Log into the Pi using a keyboard/mouse and HDMI connection. You want to be using the actual Linux GUI not SSH. On the desktop use the “WiFi Config” tool to set up the connection to your wireless network. I was not successful setting it up on my network using just ssh.
Step 2 – Install Pianobar
Pianobar is a command line interface for Pandora. It is super lightweight and will work well with Python.
A. Download and Install
sudo apt-get install pianobar
Accept all of the prompts to install. Type “Pianobar” at the prompt after installation to see it run. It will ask for your email and password but we will automate that in a minute. After starting it will ask which station to play. Select your favorite. After selecting it you will see a 18 digit code in parenthesis next to the station name, copy this we will need it for the config file. Type “?” after it starts to see a list of commands.
B. Set up a config file for Pianobar
If you have been logged into the Pi as the user “Pi” then Pianobar has installed into “/home/pi/.config/pianobar”. Under the Pianobar folder is a config folder, we will put a config file in there that will allow the app to auto-signin. Download the config file below.
In the User section replace user = [Your Email], password = [Your Password] with your credentials. Also, replace autostart_station = [Favorite Station ID] with the ID of the station you want the device to tune to first. Enter the 18 digit code you copied from the last step.
Step 3 – Set Up FIFO
What i learned: In this section i tried creating the FIFO file as a standard one, not using the mkfifo command. I spent a long time trying to figure out where i went wrong.
FIFO is a file that allows communication between Pianobar and our Python scripts. Basically Pianobar is always looking at this file for changes and will treat the text in the file as user input. The config file we added points Pianobar to the folder for FIFO.
fifo = /home/pi/.config/pianobar/ctl
This folder does not exist yet so create it with:
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
You should be able to fully control Pianobar this way. Once you full understand this concept then the Python scripts will make more sense.
Step 4 – Connect the LCD
What I learned: The original circuit called for a 3.3v voltage regulator connected to the 5v bar. I realized this was not needed since the LCD i used could use direct 3.3v from the Raspberry PI. That circuit got simple at that point with only a 1k resistor between Tx and Rx.
A. Connect Power
Connect the 5V on the LCD to the 3.3V rail (5V label on this exact model of LCD is a misprint, it is actually 3.3V)
Connect GND to the Ground Rail.
B. Connect Tx
Connect Rx from the LCD to Tx on the Pi using a 1K resistor (Brown, Black, Red, Silver/Gold) in between.
Connection Diagram
Edit: In this Diagram GND should be connected to the GND rail not SDA, sorry.
Step 5 – Connect your Buttons
What I learned: The original circuit had the switch wired to where the 1k and 10k resistors meet. I found that this would not always work as desired but the diagram below works well.
You will be using the following 6 GPIO pins (SDA, SLC, 4, 17, 27, 22) for input. You need to build a circuit for each
A. Build the button Circuit
Power > 10k > 1K. The 1K splits to the GPIO pin (its the D1 – LED in the diagram) and the Switch witch goes to ground.
B. Repeat for all buttons.
Repeat for (SDA, SLC, 4, 17, 27, 22)
Step 6 – Add the Scripts to connect everything
A. Download the scripts
cd /home/pi/.config/pianobar
git clone git://github.com/shaungehring/Pandora-Pi.git
cd Pandora-Pi
git pull origin
cd ..
cp -r /home/pi/.config/pianobar/Pandora-Pi/scripts/ .
sudo chmod -R 777 /home/pi/.config/pianobar/Pandora-Pi/scripts/
View the README.md for an explanation of the files.
B. Have the scripts autostart with Pianobar
sudo nano /etc/xdg/lxsession/LXDE/autostart
Now add two lines to the end:
pianobar
bash /home/pi/.config/scripts/PandorasBox.sh
Step 7 – Add Airplay support (optional)
Credit To: http://trouch.com/2012/08/03/airpi-airplay-audio-with-raspberry/
This is cool because the Pi will become another audio Airplay device on your network and will show as available for all your IOS devices.
A. Become ROOT
pi@raspberrypi:~$ sudo su
root@raspberrypi:cd /home/pi
B. Update Aptitude (Apt-Get)
root@raspberrypi:~# aptitude update
root@raspberrypi:~# aptitude upgrade
C. Install Depedencies
root@raspberrypi:~# aptitude install git libao-dev libssl-dev libcrypt-openssl-rsa-perl libio-socket-inet6-perl libwww-perl avahi-utils
D. Download & Compile
root@raspberrypi:~# git clone https://github.com/albertz/shairport.git shairport root@raspberrypi:~# cd shairport
root@raspberrypi:~/shairport# make
Test that it worked by running:
Replace [AirPi] with what you want it to be called.
root@raspberrypi:~/shairport# ./shairport.pl -a [AirPi]
You should see it on your network and be able to play audio over it from a IOS device.
E. Make a Daemon that will Autostart
root@raspberrypi:~/shairport# make install
root@raspberrypi:~/shairport# cp shairport.init.sample /etc/init.d/shairport root@raspberrypi:~/shairport# cd /etc/init.d
root@raspberrypi:/etc/init.d# chmod a+x shairport
root@raspberrypi:/etc/init.d# update-rc.d shairport defaults
Edit the Shairport file with the Name you want it to use.
root@raspberrypi:/etc/init.d# nano shairport
Modify the DAEMON_ARGS line to look like, (change AirPi to what you want to name it):
DAEMON_ARGS=”-w $PIDFILE -a AirPi”
D. Start Service
root@raspberrypi:/etc/init.d# ./shairport start
Step 8 – Make a case!!!
Personally i used a old blank CD spindle case that i had lying around. If you have access to a hackerspace i am working on a acrylic case but the design files are not complete.

















Thanks for posting this really cool project! I read about it on HaD…
you can use some Krylon spray paint and make the “old blank CD spindle case” look more like a “professional” enclosure. Maybe use some caulk or epoxy to “surface” as you see fit. Then tape over buttons and LCD, spray paint as deisred. Just a though. Have a nice day and thanks for the article.
I saw this post on Hackaday, and was glad to see somebody took my project and added some enhancements. Since you removed the 3.3V regulator, I figured I would add an explanation. Yes, the LCD runs off 3.3V, which is supplied directly by the Pi. However, the LCD is capable of drawing more power than the Pi can supply on this port (limited to 50mA). Chances are good that you won’t have an issue, but anyone making this box should be aware that it is possible to overdraw the 3.3v supply.
Also, thanks for giving credit on this page and the github. You definitely did a better job with the code than I did, so I will be taking a closer look at it soon. Good job!
So far, I’ve been using your tutorial here for a more simplified setup, where all that happens is the lcd shows the artist and song when a new song starts in pianobar. The issue I’m having is when I run it as pi, it will run for exactly 5 seconds, and update the lcd, then the music stops, and every second or so plays the last clip of music.
When I run it under sudo, pianobar works fine, but of course doesnt recognize my config file. Is there a way to give it a config file when run under sudo?
Dixon
You could 1) Set everything up as the root user, change all instances of pi to root in that case or 2) “Sudo -u pi pianobar” that should sudo you as the pi user.
Ayy, thanks for the explanation. I am not a EE and many of the concepts are over my head. If my LCD stops working i will know now.
Im having issues at the pianobar point of your install. which base version of raspbian did you start with? any possibility of putting out an image of your sdcard to make replication easier? thanks
-E
forgot to say exact issue, cant get it to play, “cannot start eventcmd (no such file or directory)”
got audio out to work had to run this command
sudo modprobe snd-bcm2835
Shaun – What do you mean by “change all instances of pi to root in that case”? For instance, what would be the file path of the pianobar config file?
Doesn’t seem to make a difference if I do “Sudo -u pi pianobar” still hangs up after 5 seconds of the song.
Nevermind, got it working with root. Weird that its giving me issues under pi…
One question though – Do Shairport and Pianobar work well together? What happens if one is playing a song and the other tries to play one?
How can I control this with my android tablet remotely? Or how can we add this feature?
remove pianobar and use a terminal.desktop this will have a terminal window in the GUI
create terminal.desktop file in ~/.config/autostart
containing
[Desktop Entry]
Encoding=UTF-8
Name=terminal
Name[en]=Terminal Autostart
Type=Application
Comment[en]=starts pianobar in terminal on boot
Terminal=True
StartupNotify=True
Exec=lxterminal –command “pianobar”
I just got all my parts to put this together. It’s going to be my first project like this.
I’m totally new to linux, so,
Eric, I don’t understand your post at all, what are you getting at there?
If you use his configuration you have zero control besides the buttons (which i have yet to get in the mail) running the above will give you a terminal window of pianobar running. so you can see status and control (with a monitor plugged in)
awesome, thanks erc.
I got all the hardware together, which was quite a task, as I’ve never even soldered before. And I got all the circuits working independently, i.e. I tested the LCD with a simple hello world script and it worked, and the buttons operate the pianobar, but I can’t get everything working together.
Having a visible terminal window will probably help me debug.
It’s been such a major pain!! pianobar did not install in the directory it was supposed to, permissions have been causing me major grief, and just when everything was working except the LCD showing the song playing, my Pi stopped booting. something about kernel panic file system not mounting. Guess I gotta start from OS install tomorrow.
If anyone is reading, I don’t suggest this as your first project ever, unless you’ve got about a week of totally uninterrupted free time!
Can anyone help me out please?
I just started from a fresh OS install, and have followed the instructions to a T,
I’m logged in as pi in LXterminal and installed pianobar, but there is no such folder or config file as described in the instructions.
if i type : cd /home/pi/.config/pianobar i get the no such file or directory error.
how do i install to this specific directory, or how do i find where it is installed?
thanks for the help. I’m a total noob.
Jordan,
It sounds like Pianobar didn’t install properly. It should install to “/home/pi/.config/pianobar”. You can try running “locate pianobar” to see where it is installed. What version of Raspbian did you load?
the latest version of raspian weezy.
So i’ve been able to get the screen to work, but not my buttons, tried on 2 different raspberry pi. any help on debugging or a way to test input without the script?
ERC, I got the screen and buttons to work, but I can’t get the whole thing to auto-run. Can you help me out with how to get it to run in a terminal window? I can get everything to work only if I boot into the GUI and then manually start everything.
To test your buttons, do you have a voltmeter?
If not, I ran a LED from my buttons on the breadboard first to make sure the circuit worked. If you need further help, I can send a picture of exactly what my circuit looks like.
Basically, I ran one connection of my button to the ground rail, then I ran the other side of the button connection to a part of the breadboard sharing a connection with the connection to the breakout board. Then I also connected those two with the positive side of the power rail with the two resistors in series.
I hope this helps (sorry if it was too basic and you already knew this)
But I could really use help getting the thing auto-starting and being able to view it in the terminal window.
[...] the basic functions, like changing a station or skipping a track, with arcade-style buttons. Maker Shaun Gehrig tweaked the code to add the ability to turn the device into an Airplay receiver for Apple devices [...]
[...] listening to music I found this project for a headless pandora streamer I found this project Pandora Streamer So far I’ve got it up and running, with exception to the buttons which I still need to [...]
[...] Pandora Streamer [via Hack A Day] [...]
[...] Pandora Streamer [via Hack A Day] [...]
Tony Warren: I’ve written an Android app to control pianobar remotely, see http://www.raspberrypi.org/phpBB3/viewtopic.php?f=81&t=28192 for more details.
[...] Pandora Streamer [via Hack A Day] [...]
[...] showed you how to build a Raspberry Pi Airplay Receiver, now take it up a notch and add a Pandora Jukebox to the mix so you can stream tunes to your speakers when you’re not listening to your own music. [...]
Basic question- Do I need a Pandora One account for this, or does it still work with basic, free Pandora?
[...] showed you how to build a Raspberry Pi Airplay Receiver, now take it up a notch and add a Pandora Jukebox to the mix so you can stream tunes to your speakers when you’re not listening to your own music. [...]
I hope no one else runs into this but just in case …
If you repeatedly get 42 seconds of silence after skipping songs or quitting Pianobar, it is coming from Pandora. You have most likely triggered an response to excessive skipping songs/quitting/etc … you can see why they would want to prevent that but it really threw me since it had been working & was suddenly broken. More info
Complete newbie on EE, Raspberry Pi and everything else involved in this project.
I was able to get to this point:
Change
#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
to:
#Spawn a getty on Raspberry Pi serial line
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
When I reboot the Pi, it doesn’t load up all the way and gets stuck. I am not able to do anything from that point and have cleared and reformatted the SD Card several times already.
Anyone have any idea what is going on? All I am doing is adding the # to disable the serial port, as referenced above, nothing more, nothing less.
Thanks in advance!
[...] showed you how to build a Raspberry Pi Airplay Receiver, now take it up a notch and add a Pandora Jukebox to the mix so you can stream tunes to your speakers when you’re not listening to your own music. [...]
Very cool project. Just a quick heads up: it looks like you’re hosting some payday loans code and it’s possible your CMS has been compromised. It’s at least in the source of this page and your resume page.
What changes would I have to make to this setup if I wanted to use buttons to control music being played via raspbmc?
I am wondering I have everything, but the lcd is there anywhere to buy a cheaper one that could use the same code? I am a very poor college kid….
I love this project, however, you can fairly easily reduce the total cost of the project by using http://dx.com/p/arduino-iic-i2c-twi-spi-serial-lcd-1602-module-blue-green-140080
It simply uses a sda/scl connection as opposed to RX.
I followed this tutorial, and got everything working when I run pianobar and the ButtonWatcher script from two different consoles (one directly on the pi and the other through SSH). However, when I set it to autolaunch with LXDE, pianobar works and the LCD turns on, and the song title gets updated, but none of the buttons are being recognized. I did modify the script to use a I2C LCD and buttons, but they work perfectly when run as mentioned above. At first I thought it might be a permissions issue, but the pi user has i2c permissions, and if it were a permissions problem the lcd wouldn’t update either, since it works over i2c also. Any ideas what could be causing this?
[...] Build a Pandora jukebox [...]
Do I need to use a lm1117T-3.3 voltage regulator for the lcd screen? have you had any problems doing it the way you did by just connecting to the 3.3v power supply from the RPi? just seeing if the diagram you give for connecting the lcd will always work and cause no problems.
getting the tls handshake error. i fixed it once but i forget. help!!! please
Corey,
From my experience, the build of Pianobar available from the repository isn’t working properly. I followed instructions to build pianobar from source, and that fixed the problem.
Reading the circuit description for 5.A, it looks like the diode in the schematic should be connected to the junction between R1 and R2 instead of between R1 and the switch. That way R1 will limit the current drawn from the GPIO pin through LED D1 when the switch is closed.
Hey Guys,
I follow the instructions and everything works fine, pianobar, LCD, etc. But the only thing that doesnt work on mines are the pushbuttons. Im able to turn on the pi with one of the buttons but after that I cannot turn it off. The other buttons doesnt work either, everything is set up as the schematic shown on this tutorial. I need help plz!!!
[...] the second floor. So I knew I wanted to develop a wireless sound system. After being inspired by various projects, I decided to build my own Squeezebox (now discontinued , thus giving birth [...]