RaspberryPi: IP address LCD display

Dan Siwiec
Jun 5 · 4 min read

Do you ever find yourself in a need of connecting a monitor, keyboard, and a mouse to your RaspberryPi, just so that you can get its current IP address and then SSH into it from your computer? If so, this short tutorial might help you remove this choir. We will configure an LCD display to show the current IP address of the RaspberryPi at boot time.

Prerequisites

Here are the components we will use:

  • Raspberry Pi 4 — you can use any earlier version, as well
  • Extension Board — I used a similar to this one
  • LCD1602 with an I2C interface — I used this one
  • Monitor, keyboard and a mouse or an SSH connection into the Pi

No soldering required.

Step 1 — Assembly

Let’s talk about the LCD module. We’re using a 2 by 16 display, which will be just enough to squeeze the IP address. A typical LCD display has a parallel 16 pin interface, which is a bit unwieldy, as it would take up a lot of Raspberry Pi’s GPIO pins and would be a hassle to connect. The I2C interface comes to the rescue. It’s a very simple serial interface requiring only 4 pins (1 data, 1 clock, and 2 power). You can read more about it here. The LCD display we’re using comes with a built-in I2C interface, so it is ready for us to use.

Image for post
Image for post
Back of the LCD panel, with I2C interface extension

The assembly consists of attaching the extension board to the Raspberry Pi, and wiring up 4 connections (listed in Pi to LCD order):

  • 5V -> VCC (power supply for the LCD)
  • GND -> GND (ground)
  • SDA1 -> SDA (I2C data)
  • SCL1 -> SCL (I2C clock)
Image for post
Image for post

Now, attach the board to RaspberryPi’s GPIO port with the extension line (the flat tape) and power up the Pi with a power supply. Next, we will look at the software setup required for this tutorial.

Step 2 — Software

For this part, we will need to either SSH into the RaspberryPi or connect a monitor, keyboard, and mouse. Once we’re in, we will do some preliminary diagnostics.

Let’s run the command below.

If i2cdetect is not installed on your system or you get an access error, it is likely that I2C is not enabled on your RaspberryPi. Follow these instructions to set it up.

i2cdetect returns a list of addresses of devices currently connected to the I2C bus. The output above shows there’s only one, at address 0x27. We will need this address in a bit.

Next, let’s test the command to get the IP address, we will soon use in our Python script.

We need to install the Python LCD module. You can find the documentation for it here. It supports talking to the LCD over GPIO parallel connection, as well as I2C, which we will use in this tutorial.

Let’s now test it out in Python’s REPL:

The above commands should display the text on your LCD. If it does, you’re good to proceed. If there’s nothing on the display, one common issue is the contrast of the display, which can be adjusted with that blue screw on the back, using a Philips screwdriver.

Next, we create a Python script, which we will later reference at system bootup. Let’s put it in /home/pi/lcd_ip.py

This script runs the hostname command we tried out before in a loop and puts displays it on the LCD, in the same way, we did in the interpreter before.

The last piece of the puzzle is creating a Linux service, which starts at system bootup and runs our Python script. Here’s what we’ll need for it:

First, we create a service unit file /etc/systemd/system/lcd.service

This service simply runs the Python script that drives the LCD. We now need to enable the service, which ensures it starts at system boot.

Later on, if you’d like to disable it, you run the inverse:

We now have all the needed pieces — the assembled circuit, the Python script displaying the IP on the LCD, and a Linux systemd service that will run the script at system start. We can now reboot the Pi and observe the result. Enjoy!

Image for post
Image for post

The code for this tutorial is available on GitHub here.

Dan On Coding

All things software

Dan Siwiec

Written by

I'm a software engineer, robotics tinkerer and an Agile practitioner. I currently work at Slalom as a Solution Principal

Dan On Coding

All things software

Dan Siwiec

Written by

I'm a software engineer, robotics tinkerer and an Agile practitioner. I currently work at Slalom as a Solution Principal

Dan On Coding

All things software

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store