One of the neat things about this board is that it uses only two pins on the R-Pi GPIO header to control: the 16×2 Character LCD; up to 3 backlight pins; and 5 keypad buttons. It uses an MCP23017-E/SPI2C port expander chip to make this happen.

The best part is you don’t really lose those two pins either, since you can still add I2C based sensors, RTCs, etc and have them share the I2C bus.

In this post, we update our original Raspberry Pi Internet Radio project using this cool Pi Plate. Our new radio shares many of the features of the original radio and adds: compact size; a color-changing LCD display; and more buttons for an improved user interface.

The Software

Once again, we’re using the Adafruit Occidentalis Linux distribution for the R-Pi. Three python classes from Adafruit handle all of the heavy-lifting for the LCD display, I2C bus, and MCP23017 port expander. We did have to make a few small changes to the Adafruit python classes to allow us to read all the buttons at once. You’ll find the details below.

Programming this beauty turned out to be a little trickier than the previous radio. The Pi Plate uses a serial interface to the R-Pi that’s quite a bit slower than a directly connected LCD. Polling for button changes in the same loop that handles the LCD made the buttons feel somewhat unresponsive. The solution was to move the LCD display to a separate worker thread and to use a Python queue to pass update messages. You’ll see the details in the source code below.

The Radio Play List

The radio play list / channel line-up is loaded dynamically from a file called radio_playlist.sh. This file is processed twice by the radio.py program. The first time it is executed as a shell script and the second time it is read as a text file to load the channel display names.

Don’t forget to change the Linux file permissions on this file to allow execute access.

The Radio Play List

The radio play list / channel line-up is loaded dynamically from a file called radio_playlist.sh. This file is processed twice by the radio.py program: the first time it is executed as a shell script; and the second time it is read as a text file to load the channel display names.