Thomas Tongue
ABOUT | SITEMAP | CONTACT
"No one means all he says, and yet very few say all they mean, for words are slippery and thought is viscous." - Henry Adams

Introduction

Many of the projects I'm interested in building with a Raspberry Pi are headless applications where VNC or an HDMI display + keyboard are really not ideal. A simple, low-cost LCD display and a few buttons for input would cover alot of use-cases, so when I found the Adafruit RGB LCD Shield, I was excited and ordered one right away. The kit is for an Arduino, but it communicates over I2C and that's supported by the Pi as well, so it shouldn't be an issue.... right? Let's just say, it was an opportunity to learn.

When the kit arrived, I followed the instructions for assembly, and then considered how to modify the wiring scheme from the Arduino to the Pi. That's when I found the catch. The Arduino likes to have a 5V pull up on the I2C lines, and the Pi does not. If you look at the diagram for the LCD shield, and then consult the schematic, you'll find that the 5V pull-ups are provided by R1 & R2 resistors on the board. Leaving them off the board eliminates the pull up, and makes communication with the MCP23017 i2c port expander chip friendly with the Pi.

In the time since I ordered it, Adafruit has produced a Raspberry Pi version of the shield, which looks very similar to the Arduino version, and has a stacking header for plugging directly into the Pi GPIO pins while still making those pins accessible for other plugins (very cool!).

If you have the Arduino version of this shield however, you don't need to order the Pi version separately, you can simply modify your shield to drop the 5V pull up. Below is a picture of my shield with the LCD mounted on a header to make it easy to remove / replace.

LCD Shield
Figure 1: The LCD Character Display Shield connected to the Raspberry Pi vi the Pi cobbler breakout board

Below is the shield with the LCD Char Display removed so the R1 and R2 spots for the missing resistors are clearly visible.

Shield without the display
Figure 2: The shield without the LCD Char Display installed. Note that the original kit from Adafruit does not use a header to connect the display to the shield, I added this to make it easier to remove / change the display at the cost of slightly less mechanical rigidity.

With the kit configured as pictured above, all that is left to do is wire it to the Pi. This is pretty easy, you just make the following connections:

  • 5V0 Pin on Pi to Pin 3 on the shield
  • GND Pin on Pi to Pin 5 on the shield
  • SDA0 Pin on the Pi to Pin 11 on the shield
  • SCL0 Pin on the Pi to Pin 12 on the shield

where the pin numbering convention is left->right: 1->12 when looking at the shield with the lettering upright.

In order to talk to devices over I2C, some additional packages need to be installed, which can be done with:

sudo apt-get install i2c-tools
sudo apt-get install python-smbus

Once the i2c-tools are installed, and the shield is hooked up to the Pi, you can check to see if the device is seen over the I2C bus using:

sudo i2cdetect -y 0

or if you're using the newer Raspberry Pi (Version 2) with 512MB, you can try:

sudo i2cdetect -y 1

which should give a result as shown in Figure 3 below, indicating that the device at address 0x20 (hex) has been detected. If nothing shows up in the listing produced by i2cdetect, re-check the wiring because nothing is going to work until i2cdetect is satisfied.

i2cdetect results
Figure 3: Results from i2cdetect when the hardware is properly built and connected to the Pi.

At this point, in terms of speaking to the MCP23017, Adafruit has produced this excellent introduction that uses their library to talk to the chip over I2C, so read through that material to understand how the low-level stuff is being taken care of. In particular, the background color of the LCD is directly controlled by GPIO6, GPIO7, and GPIO8 on the MCP23017, so no additional libraries are needed to set that aspect of the display.

To actually put characters on the display, Adafruit has provided a library for their Pi Plate product that is fully compatible with this kit. Details of using the library are found in this tutorial for their Pi-specific kit.