In previous posts I’ve covered using 16×2 and 20×4 LCD screens with the Raspberry Pi using Python. These are relatively easy to use but require a number of connections to be made to the Pi’s GPIO header. This setup can be simplified with the use of an I2C enabled LCD screen.

These can either be purchased as a complete unit or you can attach an I2C backpack to a standard screen.
Here is an I2C backpack :
I2C LCD Backpack
and here is a backpack soldered to the back of a standard 16×2 LCD screen :I2C LCD Backpack
This is a great way to add an I2C enabled LCD screen to your Pi with only four wires!

Step 1 – Connect Screen to the Pi

i2c Level ShifterThe I2c module can be powered with either 5V or 3.3V but the screen works best if it provided with 5V. However the Pi’s GPIO pins aren’t 5V tolerant so the I2C signals need to be level shifted. To do this I used an I2C level shifter.
This requires a high level voltage (5V) and a low level voltage (3.3V) which the device uses as a reference. The HV pins can be connected to the screen and two of the LV pins to the Pi’s I2C interface.
Level Shifter Pi I2C Backpack
LV 3.3V (pin 1)
LV1 SDA (pin 3)
LV2 SCL (pin 5)
GND GND (pin 6) GND
HV 5V (pin 2) VCC
HV1
SDA
HV2
SCL
While experimenting I found that it worked fine without the level shifting but I couldn’t be certain this wasn’t going to damage the Pi at some point. So it’s probably best to play it safe!

Step 2 – Download the Example Script

The example script will allow you to send text to the screen via I2C. It is very similar to my scripts for the normal 16×2 screen. To download the script directly to your Pi you can use :
wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/lcd_i2c.py

Step 3 – Enable the I2C Interface

In order to use I2C devices you must enable the interface on your Raspberry Pi. This can be done by following my “Enabling The I2C Interface On The Raspberry Pi” tutorial. By default the I2C backpack will show up on address 0x27.

Step 4 – Run Script

Running the script can be done using :
sudo python lcd_i2c.py
Hopefully you will see something like this :
I2C 16x2 LCD Screen

Troubleshooting

If you are having problems then :
  • Double check your wiring
  • Start from a fresh Raspbian image
  • Make sure you set up I2C as mentioned in “Enabling The I2C Interface On The Raspberry Pi” tutorial
  • Check the screen is detected when you follow the “Testing hardware” section in the above tutorial
  • Ensure SDA and SCL are correctly wired to Pins 3 and 5 on the Pi via the level shifter
  • Adjust the contrast ratio using the trimmer on the i2c backpack