Adding a LCD to any project immediately kicks it up a notch. This tutorial explains how to connect a inexpensive HDD44780 compatible LCD to the raspberry pi using 6 GPIOs. While there are other ways to connect using I2C or the UART this is the most direct method that get right down to the bare metal.
- allows for inexpensive LCDs to be used
- does not require any i2c drivers
- won’t steal the only serial port on the Pi.
The example python code sends date, time and the ip address to the display. If you are running a Pi in headless mode being able to determine the IP address at a glance is really handy.
To Follow This Tutorial You Will Need
- Standard LCD 16×2 + extras
- Adafruit Pi Cobbler – follow the tutorial to assemble it
- Half or Full-size breadboard
- Hook-up Wire
- A Raspberry Pi
Wiring the Cobbler to the LCD
Whenever you come across a LCD that looks like it has 16 connectors it is most likely using a HD44780 controller. These devices provide the same pinouts making them relatively easy to work with. The LCD uses a parallel interface meaning that we will need many pins from our raspberry pi to control it. In this tutorial we will use 4 data pins (4-bit mode) and two control pins.The data pins are straight forward. They are sending data to the display (toggled high/low). We will only be using write mode and not reading any data.
The register select pin has two uses. When pulled low it can send commands to the LCD (like position to move to, or clear the screen). This is referred to as writing to the instruction or command register. When toggled the other way (1) the register select pin goes into a data mode and will be used to send data to the screen.
The read/write pin will be pulled low (write only) as we only want to write to the LCD based on this setup.
The enable pin will be toggled to write data to the registers.
- VCC – 5v not 3.3v
- Contrast adjustment (VO) from potentiometer
- Register Select (RS). RS=0: Command, RS=1: Data
- Read/Write (R/W). R/W=0: Write, R/W=1: Read (we won’t use this pin)
- Clock (Enable). Falling edge triggered
- Bit 0 (Not used in 4-bit operation)
- Bit 1 (Not used in 4-bit operation)
- Bit 2 (Not used in 4-bit operation)
- Bit 3 (Not used in 4-bit operation)
- Bit 4
- Bit 5
- Bit 6
- Bit 7
- Backlight LED Anode (+)
- Backlight LED Cathode (-)
Before wiring, check that your LCD has an LED backlight, not an EL backlight. LED backlights use 10-40mA of power, EL backlights use 200+ma! EL backlights are often cheap to get but are not usable, make sure you don’t use one or you will overload the Pi. Some cheap LCDs that have LED backlights do not include a resistor on the LCD module for the backlight, if you’re not sure, connect a 1Kohm resistor between pin 15 and 5V instead of connecting directly. All Adafruit LCDs have LED backlights with built in resistors so you do not need an extra resistor!
First, connect the cobber power pins to the breadboard power rail. +5.0V from the cobbler goes to the red striped rail (red wire) and GND from the cobbler goes to the blue striped rail (black wire)
In order to send data to the LCD we are going to wire it up as follows
- Pin #1 of the LCD goes to ground (black wire)
- Pin #2 of the LCD goes to +5V (red wire)
- Pin #3 (Vo) connects to the middle of the potentiometer (orange wire)
- Pin #4 (RS) connects to the Cobber #25 (yellow wire)
- Pin #5 (RW) goes to ground (black wire)
- Pin #6 (EN) connects to cobber #24 (green wire)
- Skip LCD Pins #7, #8, #9 and #10
- Pin #11 (D4) connects to cobber #23 (blue wire)
- Pin #12 (D5) connects to cobber #17 (violet wire)
- Pin #13 (D6) connects to cobber #21 (gray wire)
- Pin #14 (D7) connects to cobber #22 (white wire)
- Pin #15 (LED +) goes to +5V (red wire)
- Pin #16 (LED -) goes to ground (black wire)
Then connect up the potentiometer, the left pin connects to ground (black wire) and the right pin connects to +5V (red wire)
5v LCD vs 3.3v Pi
The raspberry Pi GPIOs are designed for 3.3v, but our LCD is a 5v device. It’s fine to use a 5v display, but only if we are sending data out of the Pi. We are not going to use the 3.3v power rail on the cobbler and we will tie the RW (read/write) pin of the display to GND as we do not want the display sending sending a 5v signal into the Pi.Don’t cross the streams!
Preparing the LCD
Before you start, make sure you have a strip of 0.1″ male header and a 10K potentiometer. All Adafruit Character LCDs come with these parts so you should be good to go.
Next, wire up the contrast potentiometer as shown above, with the middle pin connecting to LCD pin #3 and the other two pins going to 5V and ground.Twist the potentiometer until you see the first line of the LCD fill with boxes. If you don’t see the boxes, check your wiring!
This guide is based on Debian’s “Wheezy” release for Raspberry Pi. It was made available in Mid July 2012. The following items must be installed in order to utilize the Raspberry Pi’s GPIO pins. If you are running Adafruit’s Occidentalis you can just skip this page.
Add the latest dev packages for Python (2.x)
For more detail: Drive a 16×2 LCD with the Raspberry Pi