User Tools

Site Tools


i2c_lcd_display

I2C LCD Display



LCDs are a great way to display simple information (like an IP address) without going to the expense of a full LCD panel, or connecting a monitor. For my previous LCD I used a 2 line LCD in 4 bit mode, this is a very simple implementation, but it uses lots of GPIO pins.

Another way to connect an LCD is to use the I2C interface. This only requires a total of 4 wires, two for the data, 2 for power. You can buy LCDs with built in I2C adaptors, I got mine from eBay, I can't really link it because the links to eBay items seem to die fairly quicly.

If you do a search for something like this:

  Yellow Green Serial IIC/I2C/TWI 2004 20X4 Character LCD Module For Arduino


Then you should find what you are looking for.

Here is the description for what I purchased (obviously you can ignore the Arduino references)

Yellow Green Serial IIC/I2C/TWI 2004 20×4 Character LCD Module For Arduino

  Dedicated IIC control for Arduino, it only takes two IO
  
  Adjustable contrast, the backlight control to provide library
  
  High quality LCD screen, Yellow Green, clear display
  
  IIC bus control, it only takes two IO ports
  
  Backlight control, you can control via a jumper, you can also program control
  
  Adjustable display contrast
  
  5V power supply, the device address 0x27
  
  Compatible to Arduino


There are many of these available on eBay in 2016, and they average around £3.50-£4.00

Here is one connected to a Pi Zero (1.3)



The most tricky part of getting any LCD to run is finding a driver/library for it. I have followed a tutorial from a chap called TheRaspberryPiGuy who you can look up on YouTube.

This guide assumes that you have installed Raspbian (or equivalent) and updated everything with the following commands:

  sudo apt-get update
  sudo apt-get upgrade


On the LCD the four connections will be labelled something like:

  LCD          R-Pi
  
  GND (Ov)     Pin 6
  VCC (5v)     Pin 2
  SDA          Pin 3 (GPIO2)
  SCL          Pin 5 (GPIO3)


You need to ensure that the I2C pins are active:

  sudo raspi-config
  Advanced Options
  I2C
  
  Where you see the message -  Would you like the ARM I2C interface to be enabled?
  
  Select Yes, then exit this menu system
  
  Reboot for the changes to take effect


Once the OS is installed and the LCD is connected, the libraries can be installed:
Ensure you are in your home folder (probably /home/pi)

From the command line:

  git clone https://github.com/the-raspberry-pi-guy/lcd
  
  cd lcd
  
  sudo sh install.sh (RPi will auto reboot)


Once the Pi has rebooted:

  Navigate to your home folder (probably /home/pi)
  cd lcd
  edit lcddriver.py to ensure the ADDRESS = 0x27 is the correct address (some are 0x20)


I found this guide by doing this YouTube search:

  
  Raspberry Pi - Mini LCD Display Tutorial by TheRaspberryPiGuy


To start the demo LCD code:

  sudo python lcd_lcd.py


You should now have some text on the LCD

i2c_lcd_display.txt · Last modified: 2023/03/09 22:35 by 127.0.0.1