Adafruit I2C RGB 16×2 LCD+Keypad & Raspberry PI

I recently bought one of these

Adafruit RGB Negative 16×2 LCD+Keypad Kit for Raspberry Pi from an Adafruit reseller in the UK (via eBay), for two reasons. 1 to use in my OBDII project, and 2 to learn how they did it (serial to parallel and some 4 bit mangle).

You see the device uses an MCP23017 16bit I2C port extender, and most 16×2 LCD displays require a 4-bit bus (4 data lines) , and an RS, RW and E lines, so i was interested to see how Adafruit were implementing the lcd display protocol over the i2c bus….

It arrives as a kit of parts with very little to put together, a few minutes soldering is all that is needed. I only wish i had bought a header with longer pins, like this one

Stacking header for raspberry pi

To allow me to tap off the I2c bus for other things i’m working on (RTC, Temp sensor and non volatile ram).

So, the thing with the adafruit shield is, that like everything else for the raspberry pi, it comes with a set of python scripts.

I have nothing against python, i’m sure its a great language, but i want to crack on with what *I’m* doing, i don’t want to start learning python just for this project. So far i’ve written everything in C or Perl. So the examples from Adafruit were no good for me.

I then started thinking about LCDproc, which i have used in the past with a headless Debian box, and a 4×20 LCD display via the parallel port.

LCDproc is great, it runs as a daemon, and you just need to write a client to push data to it. Due to its age, it already has a lot of drivers for different display, including one for an HD44780 LCD display via I2c, so i was hopeful that it wouldn’t be too much work to add the Adafruit display into the mix.

But guess what, i needn’t have worried, because someone else (Jonathan Brogdon or perhaps Thomas Preston had beat me too it, and his patch had already been merged into the head of the LCDproc source code.

So, here is a recipe for getting LCDproc running on a raspberry pi, with the Adafruit RGB 16×2 LCD display with keypad.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install i2c-tools

Now we need to enable i2c

pi@raspberrypi ~ $ sudo sh -c "echo 'i2c-dev' >> /etc/modules"
pi@raspberrypi ~ $ sudo sh -c "echo 'i2c-bcm2708' >> /etc/modules"
pi@raspberrypi ~ $ sudo reboot

Once pi reboots, see if you can detect the lcd display.

pi@raspberrypi ~ $ i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

The display should be detected at address 0x20

Now, we need to install the tool chain.

pi@raspberrypi ~ $ sudo apt-get install cvs autoconf automake

Now get the current version of lcdproc from source control (because apt-get doesn’t have a version that includes support for the Adafruit LCD yet).

pi@raspberrypi ~ $ cvs -z3 checkout -P lcdproc

Now we need to configure the build.

pi@raspberrypi ~ $ cd lcdproc
pi@raspberrypi ~ $ sh ./
pi@raspberrypi ~ $ ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-drivers=hd44780

Then run make to build the binaries

pi@raspberrypi ~ $ make

lets check we built the piplate connection type into the hd44780 driver, edit the local LCDd.conf file and set connectiontype to piplate and driver to hd44780.

pi@raspberrypi ~ $ sudo server/LCDd -c ./LCDd.conf -f

A curses LCD emulation window should show, just hit Ctrl+c to terminate LCDd.

Now install the newly built version.

pi@raspberrypi ~ $ sudo make install

Then edit the /etc/LCDd.conf file to look like this:



Ok, lets test by running the lcdproc client to send some data to our newly created LCDproc server.

pi@raspberrypi ~ $ sudo lcdproc

To add the buttons to LCDproc, we need to add further configuration – here is my complete lcdd.conf file:

# LCDd.conf -- configuration file for the LCDproc server daemon LCDd
# Modified to support a hd44780 connected to a Raspberry Pi using i2c
# This file contains the configuration for the LCDd server.

## Server section with all kinds of settings for the LCDd server ##

# Where can we find the driver modules ?
# IMPORTANT: Make sure to change this setting to reflect your
#            specific setup! Otherwise LCDd won't be able to find
#            the driver modules and will thus not be able to
#            function properly.
# NOTE: Always place a slash as last character !

# Tells the server to load the given drivers. Multiple lines can be given.

# Tells the driver to bind to the given interface

# Listen on this specified port; defaults to 13666.

# Sets the reporting level; defaults to 2 (warnings and errors only).

# Should we report to syslog instead of stderr ? [default: no; legal: yes, no]

# User to run as.  LCDd will drop its root privileges, if any,
# and run as this user instead.

# The server will stay in the foreground if set to true.

# Hello message: each entry represents a display line; default: builtin
#Hello="  Welcome to"
#Hello="   LCDproc!"

# GoodBye message: each entry represents a display line; default: builtin
#GoodBye="Thanks for using"
#GoodBye="   LCDproc!"

# Sets the default time in seconds to displays a screen.

# If set to no, LCDd will start with screen rotation disabled. This has the
# same effect as if the ToggleRotateKey had been pressed. Rotation will start
# if the ToggleRotateKey is pressed. Note that this setting does not turn off
# priority sorting of screens. [default: on; legal: on, off]

# If yes, the the serverscreen will be rotated as a usual info screen. If no,
# it will be a background screen, only visible when no other screens are
# active. The special value 'blank' is similar to no, but only a blank screen
# is displayed. [default: on; legal: on, off, blank]

# Set master backlight setting. If set to 'open' a client may control the
# backlight for its own screens (only). [default: open; legal: off, open, on]

# Set master heartbeat setting. If set to 'open' a client may control the
# heartbeat for its own screens (only). [default: open; legal: off, open, on]

# set title scrolling speed [default: 10; legal: 0-10]

# The "...Key=" lines define what the server does with keypresses that
# don't go to any client. The ToggleRotateKey stops rotation of screens, while
# the PrevScreenKey and NextScreenKey go back / forward one screen (even if
# rotation is disabled.
# Assign the key string returned by the driver to the ...Key setting. These
# are the defaults:

## The menu section. The menu is an internal LCDproc client. ##
# You can configure what keys the menu should use. Note that the MenuKey
# will be reserved exclusively, the others work in shared mode.

# Up to six keys are supported. The MenuKey (to enter and exit the menu), the
# EnterKey (to select values) and at least one movement keys are required.
# These are the default key assignments:

## Hitachi HD44780 driver ##


# Device of the i2c interface [default: /dev/lcd]
# Raspberry Pi version 1 require i2c-0; version 2 requires i2c-1 

# Bitrate of the serial port (0 for interface default)

# If you have a keypad connected.
# You can configure the keypad layout further on in this file.

# Set the initial contrast (bwctusb and lcd2usb) [default: 500; legal: 0 - 1000]

# If you have a switchable backlight.

# If you have the additional output port ("bargraph") and you want to
# be able to control it with the lcdproc OUTPUT command

# Specifies the size of the LCD.
# In case of multiple combined displays, this should be the total size.

# Character map to to map ISO-8859-1 to the LCD's character set

# You can reduce the inserted delays by setting this to false.
# On fast PCs it is possible your LCD does not respond correctly.
# Default: true.

# If you have a keypad you can assign keystrings to the keys.
# See documentation for used terms and how to wire it.
# For example to give directly connected key 4 the string "Enter", use:
#   KeyDirect_4=Enter
# For matrix keys use the X and Y coordinates of the key:
#   KeyMatrix_1_3=Enter



3 thoughts on “Adafruit I2C RGB 16×2 LCD+Keypad & Raspberry PI

  1. Hello and thanks for this useful post 🙂
    I’have cloned (on a breadboard for now) this Adafruit LCD+Keypad Kit, with a 20×4 LCD (not RGB) and the buttons. Pythons examples in Adafruit’s site works fine, so the “clone” works.
    I have installed and configured LCDproc, thanks to your post, and works like a charm..
    But how we can use button with LCDproc? In the HD44780 drivers section I don’t see KEYPAD options, and if I copy from another dirver section don’t works…

    any suggestion?
    Thanks in advance for your anwser

  2. Great stuff! I’ve used this for reference and got my pi radio with display working ^^

    Have you figured out if it’s possible to manage the backlight colors with LCDproc?
    And if so, how?

Please Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.