PROJECT 2 - Driving a Liquid Crystal Display

Animated image of LCD

This will require: Python, GPIO library, Hitachi HD44780 (or compatible) LCD, Ciseco's Slice of Pi board (optional), patch leads


HD44780 chip on an LCD

You can use the Pi to drive a Liquid Crystal Display (LCD) to display all sorts of information: it could be date, time, system status, disk utilisation, MAC and IP address, etc.

The most common LCD is one based on the Hitachi HD44780 chip. This is an LCD controller and driver LSI device with embedded fonts and the ability to create custom characters. The LCD module and driver chip are supplied assembled and have a 14 or 16 pin connection to a PIC, Pi, PC, etc. This can be in a single row 1x14 or 1x16 edge connector or 2x7 or 2x8 0.1" IDC connector. The complete assemblies are easily obtainable and many manufacturers make their own compatible LCDs so that the devices are entirely interchangeable at the control and functional level though not always with the same physical connection.

The HD44780 is the main driver chip but this is limited to two rows of eight characters each and so for larger LCD modules one or more slave Hitachi HD44100 chips are used. These convert the serial data from the HD44780 into parallel for passing to the display.

Circuit diagram

The circuit I used is the one provided by Matt Hawkins at This uses a 4-bit interface to minimise the number of GPIO outputs required but has to send the high and low bit data in two write operations. I used Ciseco's Slice of Pi board to expose the appropriate pins but you could just use single patch leads and connect directly to the 26-way header. The circuit diagram is shown here but a table of connections is below if you prefer that type of format. The connections in red are for the LCD's backlight, if it has one. The 560R resistor is to protect the backlight in the event there is no built-in over-current protection.

I started off with Matt's program but added a few enhancements so that it calls GPIO.cleanup() at the end to close ports so that you do not see warnings if you run the program subsequently. I also had to add a short delay between telling the device which row I was going to write and actually writing it. Without a delay, the first character was sometimes omitted.

Circuit diagram

A further improvement is to connect a 10K variable potentiometer between the 0V and +5V lines and connect the output to the contrast pin (LCD pin 3). By varying the resistance between 0V and +5V you can find the optimum contrast for your LCD module. The connections in blue show the amendments to the original circuit.

Step 1

Connect up the components as shown in the diagram. The table of connections are shown below.

LCD PinFunctionPi FunctionPi PinSlice of Pi Pin
7Data 0
8Data 1
9Data 2
10Data 3
11Data 4GPIO25P1-22GP6
12Data 5GPIO24P1-18GP5
13Data 6GPIO23P1-16GP4
14Data 7GPIO18P1-12GP1
15+5V via 560RP1-025V0

If your display does not have pins 15 and 16 you can ignore the backlight connections.

Step 2

Download the program to your Pi. The easiest way to do this is to use wget from the Pi command line. This will copy the program to your current directory.


Step 3

Run the program as root. The program just displays some text on the LCD - it doesn't ask for any input and runs for about four seconds because of the delays programmed.

sudo python

If you would like a program that lets you enter the text yourself, try this.


sudo python

LCDs Available

Over the years I have collected a variety of LCDs and it is clear that some are more common than others. Amateur Radio Rallies provide a good source of both second hand and new devices. The more popular types are: