Python Script

NOTE: This page describes an older version of the Raspberry Pi character LCD Python code.

You can find a newer library that works on more platforms like the Raspberry Pi and BeagleBone Black by checking out the new character LCD Python library guide. For new projects it's recommended to use the new library!

The Code

The Python code for Adafruit's Character LCDs on the Pi is available on Github at

There are two files we will be working with:

  1. - contains python class for LCD control
  2. - code for IP address and date/time calls methods from

The first file, is a mashup from two different sources of LCD code. Github user lrvick put together a nice python class. His work is the baseline that is slowly being changed as we are bringing in more elements from the Arduino LiquidCrystal library

The easiest way to get the code onto your Pi is to hook up an Ethernet cable, and clone it directly using 'git', which is installed by default on most distros.  Simply run the following commands from an appropriate location (ex. /home/pi):

apt-get install git
git clone git://
cd Adafruit-Raspberry-Pi-Python-Code
cd Adafruit_CharLCD


 You can test the wiring from the previous step by simply running the Python code, as it has a little code it in that will simply display a test message when wired correctly

You can use nano to edit.

chmod +x
sudo ./

IP Clock Example

This script assumes you'll want to display the Ethernet (eth0) IP address. You may want to replace eth0 with wlan0 or wlan1 (etc) for Wireless IP address!

from Adafruit_CharLCD import Adafruit_CharLCD
from subprocess import *
from time import sleep, strftime
from datetime import datetime

lcd = Adafruit_CharLCD()

cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1"


def run_cmd(cmd):
        p = Popen(cmd, shell=True, stdout=PIPE)
        output = p.communicate()[0]
        return output

while 1:
        ipaddr = run_cmd(cmd)
        lcd.message('%b %d  %H:%M:%S\n'))
        lcd.message('IP %s' % ( ipaddr ) )

Running the Code

Start the IP + Clock example

$ sudo ./ 

What You Should See

This guide was first published on Aug 17, 2012. It was last updated on Aug 17, 2012. This page (Python Script) was last updated on Nov 23, 2015.