I recently bought one of these
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
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 http://sourceforge.net/p/lcdproc/discussion/312/thread/d9daf8e0/) 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 -d:pserver:firstname.lastname@example.org:/cvsroot/lcdproc checkout -P lcdproc
Now we need to configure the build.
pi@raspberrypi ~ $ cd lcdproc pi@raspberrypi ~ $ sh ./autogen.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:
[server] DriverPath=/usr/local/lib/lcdproc/ Driver=hd44780 Bind=127.0.0.1 Port=13666 User=nobody WaitTime=5 [hd44780] ConnectionType=piplate Device=/dev/i2c-1 Port=0x20 Size=16x2
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 ## [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 ! DriverPath=/usr/lib/lcdproc/ # Tells the server to load the given drivers. Multiple lines can be given. Driver=hd44780 # Tells the driver to bind to the given interface Bind=127.0.0.1 # Listen on this specified port; defaults to 13666. Port=13666 # Sets the reporting level; defaults to 2 (warnings and errors only). #ReportLevel=3 # Should we report to syslog instead of stderr ? [default: no; legal: yes, no] #ReportToSyslog=yes # User to run as. LCDd will drop its root privileges, if any, # and run as this user instead. User=nobody # The server will stay in the foreground if set to true. #Foreground=no # 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. WaitTime=5 # 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] #AutoRotate=no # 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] #ServerScreen=no # 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] #Backlight=open # 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] #Heartbeat=open # set title scrolling speed [default: 10; legal: 0-10] #TitleSpeed=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: ToggleRotateKey=Enter PrevScreenKey=Left NextScreenKey=Right #ScrollUpKey=Up #ScrollDownKey=Down ## The menu section. The menu is an internal LCDproc client. ## [menu] # 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: MenuKey=Escape EnterKey=Enter UpKey=Up DownKey=Down LeftKey=Left RightKey=Right ## Hitachi HD44780 driver ## [hd44780] ConnectionType=piplate Port=0x20 # Device of the i2c interface [default: /dev/lcd] # Raspberry Pi version 1 require i2c-0; version 2 requires i2c-1 Device=/dev/i2c-0 # Bitrate of the serial port (0 for interface default) Speed=0 # If you have a keypad connected. # You can configure the keypad layout further on in this file. Keypad=yes # Set the initial contrast (bwctusb and lcd2usb) [default: 500; legal: 0 - 1000] Contrast=0 # If you have a switchable backlight. Backlight=yes # If you have the additional output port ("bargraph") and you want to # be able to control it with the lcdproc OUTPUT command OutputPort=no # Specifies the size of the LCD. # In case of multiple combined displays, this should be the total size. Size=16x2 # Character map to to map ISO-8859-1 to the LCD's character set CharMap=hd44780_default # 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. DelayBus=false # 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 KeyDirect_1=Enter KeyDirect_2=Up KeyDirect_3=Down KeyDirect_4=Left KeyDirect_5=Right # EOF