PROJECT 2 – Driving a Liquid Crystal Display

Introduction

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.

PROJECT 2 - Driving a Liquid Crystal DisplayThe 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 1×14 or 1×16 edge connector or 2×7 or 2×8 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.

PROJECT 2 - Driving a Liquid Crystal Display SchematicThe circuit I used is the one provided by Matt Hawkins at raspberrypi-spy.co.uk. 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.

 

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 Pin Function Pi Function Pi Pin Slice of Pi Pin
1 GND GND P1-06 GND
2 +5V +5V P1-02 5V0
3 Contrast GND P1-06 GND
4 RS GPIO7 P1-26 SPI_1
5 RW GND P1-06 GND
6 E GPIO8 P1-24 SPI_0
7 Data 0
8 Data 1
9 Data 2
10 Data 3
11 Data 4 GPIO25 P1-22 GP6
12 Data 5 GPIO24 P1-18 GP5
13 Data 6 GPIO23 P1-16 GP4
14 Data 7 GPIO18 P1-12 GP1
15 +5V via 560R P1-02 5V0
16 GND P1-06 GND

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.

wget http://www.noveldevices.co.uk/rpdl/lcd.py

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 lcd.py

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

wget http://www.noveldevices.co.uk/rpdl/writelcd.py

sudo python writelcd.py

 

Source: PROJECT 2 – Driving a Liquid Crystal Display

Scroll to Top
Read previous post:
Raspberry Pi on a Portable B&W CRT

Last week at hacklab.to, my friend Igor brought in a Panasonic TR-1030P. This is a black and white CRT, with...

Close