Completed Pandora Pi
Engineering, General, Raspberry Pi

Raspberry Pi: Project 1 – Pandora Streamer

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
  1. Raspberry Pi (sparkfun, Element14, adafruit)
  2. Breadboard
  3. PI Cobbler
  4. LCD Screen
  5. Buttons
  6. Resistors (10k and 1k)

Optional

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.

Pianobar Config File

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.

LCD_Hookup

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.

Standard

76 thoughts on “Raspberry Pi: Project 1 – Pandora Streamer

  1. Andrew says:

    I am having the same problem as others. I am able to get the audio to begin playing automatically but the buttons do not work. I don’t think the script is starting properly. I did not follow this tutorial, instead I followed this one: http://www.instructables.com/id/Pandoras-Box-An-Internet-Radio-player-made-with/step8/Putting-it-Together-with-BASH-and-Python/

    The principle is nearly exactly the same. I had to move whatever commands that were in the autostart file to the ~/.bashrc file for it to start automatically.

  2. Most computers utilized in business, and many employed
    in the home, no more operate in the old self contained fashion.
    The K7 Evaluation System is supplied inside a compact
    housing that could be plugged in towards the USB port of every PC type computer, desktop or laptop.
    The management, as well as processing, of knowledge in organizations is famous
    as it, or IT.

  3. Pingback: Raspberry Pi Pandora Streamer @Raspberry_Pi #piday #raspberrypi « adafruit industries blog

  4. po11ution says:

    I have same issue as user Tom..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!

  5. Pingback: Hostel Management

  6. Hello would you mind stating which blog platform you’re working with?

    I’m looking to start my own blog soon but I’m having a
    tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.

    The reason I ask is because your layout seems different then most blogs and I’m looking for something unique.
    P.S Apologies for being off-topic but I had to ask!

  7. I’ll right away take hold of your rss feed as I can not to find
    your email subscription link or newsletter service. Do you’ve any?
    Kindly permit me recognize so that I may subscribe.
    Thanks.

  8. Its such as you read my mind! You appear to grasp so much approximately this,
    such as you wrote the book in it or something. I think that you can do with some % to force the message home
    a little bit, but instead of that, that is wonderful blog.
    A fantastic read. I will definitely be back.

  9. Hello, i read your blog from time to time and i own a similar one
    and i was just wondering if you get a lot of spam comments?
    If so how do you protect against it, any plugin or anything you can suggest?
    I get so much lately it’s driving me mad so any support is very much appreciated.

  10. Hi, i read your blog from time to time and i own a similar one and i was just curious if you get a lot of
    spam remarks? If so how do you prevent it, any plugin or anything you can advise?
    I get so much lately it’s driving me crazy so any assistance is very much
    appreciated.

  11. Pingback: PCOnline - Din datortidning på webben!

  12. I simply could not depart your web site prior to suggesting that
    I extremely loved the standard info a person supply to your guests?

    Is gonna be back often to check out new posts

  13. Pingback: Arduino Hack Space | 11 Raspberry Pi Projects That You Wouldn’t Want To Miss For The World!

  14. Hello, i examine one’s blog out of time for you to moment and i personal an identical just one also i had been only curious in the event you get yourself a lot of
    junk-mail reviews? If that’s the case just how do one prevent any of it, virtually any plug in or anything you should suggest?
    I really get a lot not too long ago it’s operating me personally mad therefore any help is quite a lot
    enjoyed.

  15. I know this web site presents quality depending articles
    and additional stuff, is there any other website which offers these kinds of information in quality?

  16. Cazare Sibiu Piscina

    You’ve made some good points there. I checked on the net for more information about the issue and found most individuals will go
    along with your views on this site.

  17. I read a lot of interesting content here. Probably you spend a lot of time writing, i
    know how to save you a lot of time, there is
    an online tool that creates readable, google friendly posts in minutes, just type in google – laranitas free content source

  18. A person should consider the following factors including age, health concerns, overeating, alcohol, inactivity, and
    genetics. Bupropion may also cause nervousness, restlessness and
    anxiety, so will the two drugs work together and emphasize these unwanted side effects.

    After test is done and also the needle is taken away,
    the individual may feel some throbbing in the puncture site.
    A v3 diet supplement can belong to two categories, prescribed as well as over
    the counter v3 diet pills. sources

  19. Now you get to grips with the expenses as they are
    even offering free mobile games and we can have unlimited fun. The
    contribution of wonderful graphical effects including sparkling lighting, special items like wrapped and striped candies that clear
    larger chapters of the game and to risk it all depends on the world
    around you. The symbian games developer for mobile csr racing
    hack owners. Angry Birds game online, pay as you will love the Pokemon clone genre.
    More often, it is downloaded.

    My webpage … Csr racing cheats for ipad

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>