Finally, enter the following command to make sure audio is routed to the headphone jack rather than the HDMI port (you can skip this step if using a USB audio device):
If that runs as expected, connect headphones or speakers. The initial volume level will be very low. Type right parenthesis several times to increase the volume:
If that all works, press “q” to exit pianobar, then shut down the system in preparation for installing the final hardware:
If you haven’t already assembled the LCD Pi Plate, do that step now. Here’s a tutorial to guide you through the assembly.
Raspberry Pi Model A users: the LCD Pi Plate is normally assembled with a rubber bumper near one corner for stability atop the Raspberry Pi. This bumper rests on the Ethernet jack, which is only present on the Model B board. Model A users will need to find a suitable alternative to the bumper, non-conductive and about 5/8″ tall. A cork or rubber eraser trimmed to size can work, a 5/8″ nylon PC board spacer if you have one, or a 2×2 Lego® brick set on its side.
The Raspberry Pi should be shut down when connecting the LCD and installing in a case. If it’s currently running, issue the shutdown command as shown at the bottom of the previous page.
If using the Pi Box case, follow this tutorial to install the Raspberry Pi inside, leaving the top of the case off.
Align the 26-pin headers on the LCD plate and Raspberry Pi, and install the plate by pressing straight down gently.
Connect power to the Raspberry Pi. The red power light should come on. If not, there might be a soldering mistake on the LCD Pi Plate board.
Allow 30 seconds to a minute for the Raspberry Pi to fully boot and situate itself on the network. At this point, you should be able to log in from a terminal over ssh, e.g.:
ssh pi@192.168.0.6 (or whatever address the system reported during the configuration process)
If you previously installed netatalk (optional), and if you changed the Raspberry Pi’s default hostname, you might be able to use:
ssh pi@pandora.local
If you receive a response that the connection timed out or the hostname cannot be resolved, connect a monitor and keyboard and work through the “Initial System Configuration” steps again; it’s most likely a typo in the wireless setup.
You should be successfully logged into the system at this point.
First, let’s test the LCD and buttons:
cd Python-WiFi-Radio
sudo python Adafruit_CharLCDPlate.py
If using an RGB-backlit LCD, the program should cycle through different backlight colors (with the Blue & White LCD, it will flash on and off a few times). Then it will ask you to try pressing buttons.
Adjust the Contrast dial (using a small screwdriver if necessary) until the text is sharp and legible.
When finished, press Control+C to exit. The LCD is ready!
Next, let’s try our radio software:
sudo python PiPhi.py
This is our own “wrapper” for pianobar, allowing us to use the LCD and buttons to interact with that program. If all goes well, the system should report its network address, fetch a list of stations from the Pandora server and start playing. If not, refer to the Troubleshooting page.
With only a few buttons available, we’ve condensed only the most essential functions to this program. If you need to configure your Pandora account (such as adding new stations to the list), use a web browser to access the Pandora web site.
From left to right, the button functions are:
- Play/Pause (tap once to pause, again to play, or hold for three seconds to exit the program).
- Station select (brings up a menu — can then use the up and down buttons to pick a station — press this button again to activate, or the Play/Pause button to cancel).
- Volume Up/Down (two buttons, one above the other)
- Next Track
Take a moment to experiment with the buttons and familiarize yourself with their use. If everything seems to be working, we’ll do some final configuration to make the system truly standalone. To exit from the PiPhi program, hold down Select (the leftmost button) for 3+ seconds.
Final Configuration and Auto-Start
First, cd to the directory with the PiPhi.py script (you should already be there if you’ve followed the steps till now!) and edit the PiPhi.py script:
nano PiPhi.py
Two lines near the start of the code (around line 26) are of interest:
- RGB_LCD = False # Set to ‘True’ if using color backlit LCD
- HALT_ON_EXIT = False # Set to ‘True’ to shut down system when exiting
If you’ve opted for an RGB-backlit LCD, change the first of these lines to:
Since our goal is a standalone system with no keyboard or monitor, we need some way to issue an orderly shutdown (Linux systems don’t like it when you just pull the plug). To make the 3-second button press shut down the system (rather than just exit to a command line prompt), change the second line to:
Nearly there! Now we just need to set up the system to start our program upon booting.
sudo nano /etc/rc.local
Before the final “exit 0” line, insert these two lines:
- cd /home/pi/Python–WiFi–Radio
- python PiPhi.py &
If you downloaded or otherwise placed the radio software in a different location, the first line should be changed accordingly. “sudo” isn’t necessary here because the rc.local script is already run as root.
Reboot the system to test the startup function:
sudo reboot
After 30 seconds to a minute, you should see the backlight turn on and music will begin. If not, connect to the system using ssh and confirm the configuration steps above.
When I run the PiPhi script or any of the LCD examples, I get an “’lcd’ is not defined” error message.
The PiPhi script must be run as root in order to access the LCD and keypad hardware:
sudo python PiPhi.py
If that doesn’t fix it, check for any solder bridges or cold joints on the LCD plate, and make sure the headers between the plate and Raspberry Pi are aligned.
Or the code may be having difficulty accessing the I2C bus. We can override this manually if the need arises. Edit PiPhi.py, looking for this line:
lcd = Adafruit_CharLCDPlate()
And simply add this parameter:
lcd = Adafruit_CharLCDPlate(busnum=1)
Run the code again and see if that helps.
The Raspberry Pi does not boot when the LCD/Keypad Pi Plate is attached.
Check for any solder bridges or cold joints on the LCD plate, and make sure the headers between the plate and Raspberry Pi are aligned.
A keyboard attached to the Raspberry Pi is not responding.
Some keyboards require more power than the Raspberry Pi USB port can provide. Add a powered USB hub, or try a different keyboard if you have a spare.
The system never connects to the wireless network.
Most likely a typo during the wireless setup procedure. Go through each step on the “Initial System Configuration” page and check spelling carefully, including your wireless network name (SSID) and password.
“Hidden” WiFi networks are particularly fussy, and even with the extra directions provided might not connect. We very strongly recommend using a broadcast network name. If using a hidden network…when creating the file wpa_supplicant.conf, did you remember to change the SSID and password to the values used by your network?
It might also be an incompatible USB wireless adapter. The one in the Adafruit shop is known to work with the Raspberry Pi.
The PiPhi script just hangs at “Receiving station list…”
The pianobar application is most likely failing to connect to the Pandora server…probably due to an incorrect email address and/or password. Check the settings in the configuration file and make sure these match your Pandora credentials, not the account on your Raspberry Pi.
If in doubt, run pianobar directly from the command line first. Once that’s working, then move on to the PiPhi script.
pianobar (or the PiPhi script) is running, but no sound is coming from the headphone jack.
Make sure audio is routed to the headphone jack rather than the HDMI port. From the command line:
sudo amixer cset numid=3 1
When pianobar tries to connect, I get a “TLS handshake error” message.
Enter the following command (as a single line — copy and paste verbatim, if possible):
fingerprint=`openssl s_client -connect tuner.pandora.com:443 < /dev/null 2> /dev/null | openssl x509 -noout -fingerprint | tr -d ‘:’ | cut -d’=’ -f2` && echo tls_fingerprint = $fingerprint >> ~/.config/pianobar/config
Then try pianobar (or PiPhi) again.