I2C LCD Backpacks for 1602 Screens Buttons

I2C LCD Backpacks for 1602 Screens Buttons

Introduction: Raspberry Pi: Using 1$ I2C LCD Backpacks for 1602 Screens Buttons!

Hello! I’m Arsenijs, I like building stuff with Raspberry Pi’s and lately I’ve been working with character displays, as well as their I2C backpacks, so I’ve collected some hacks I can show you. Today, I’ll tell you how to save a lot of pins on Raspberry Pi if you’re using those popular HD44780 based character displays, like the one on the second picture.

For this, I’m using a 1$ a piece I2C LCD backpack which are available in large quantities on eBay (those which I have on the header image) and are typically used with 5V Arduinos. This backpack is typically run from 5 volts due to the fact that it supplies its VCC to the HD44780 display, and these LCDs most often are 5V only and we all remember Raspberry Pi doesn’t like 5V on its GPIOs! However, with a single cut trace and a pin added to a header you can modify it so that the backpack itself works with 3.3V (perfect for Pi) and supplies the 5V necessary for the screen to work.

Moreover, I’ll also tell you how to hack this backpack so that it can interface with up to 8 buttons using I2C! Not only that, but I’ll show you how use interrupt capability of PCF8574 to avoid unnecessary loading of I2C bus and therefore reduce CPU load by monitoring just a single GPIO pin instead of asking about the buttons’ state again and again.

I’ll also provide you with Python code for both button reading and output to screen. It’s easy to read and modify to suit your needs =)

In the end, you can add a screen and buttons (or multiples of them both!) to your project using just 2 I2C pins (can be shared among multiple devices) and an optional 1 GPIO pin. Moreover, if you analyze my code and the IC datasheet, you can even use those boards to increase your GPIO count on the Pi. Those backpacks are using PCF8547 ICs, and these ICs have a lot more features than just driving an LCD. If that’s what you’re interested to hear about, continue reading and you’ll get a glimpse of a recent big project of mine that’s sure to catch your attention ; )

Some links:

A very detailed writeup on HD44780 displays, their different variations, controllers and backpacks

Step 1: Connecting Your Backpack to the LCD

This is a closeup the backpack’s board. It’s designed to be pin to pin compatible to those displays. Those backpacks are typically supplied with male pins.

Anyway, keep in mind that the backpack’s pin 1 (the rightmost pin of the header) goes to the pin 1 of the LCD (leftmost when looking at the display from the “display things” side and rightmost when looking at the display from the PCB side). If you connect them in some another way, it most likely will not break anything,
I2C LCD Backpacks for 1602 Screens Buttons
just that the display obviously won’t work in that arrangement.

All is well, but you cannot just connect this backpack out of the box to your Raspberry Pi and expect it to work. The possible outcomes of this are:

It won’t workIt will fry your Raspberry PiThe display won’t show anything

Step 2: Explaining and Fixing the Incompatibility

What’s the real problem with those backpacks and Raspberry Pi? Well, as I said, the LCDs need 5V power, especially for the contrast. This backpack is mainly used for 5V Arduino+LCD setups, so it uses 5V for the onboard IC and its I2C pullups, too. Thus, the I2C lines have 5V on them, which isn’t suitable for connection to your Pi. Pi has pullups, too, so a viable alternative would be removing the backpack’s onboard pullups except that it then stops working reliably. Why? Minimum voltage the backpacks accepts as high logic level is 0.7VCC = 5V07 in this case = 3.5V, which is less than 3.3 of Raspberry Pi’s and the situation is what programmers call “undefined behaviour” it might work or it might not. In my case, it didn’t work. The solution? The backpack’s controller IC is perfectly OK with 3.3V as VCC, just that the displays are not. Thus, we need to isolate display’s VCC line, feed the controller with 3.3V and have a separate 5V line for the display, and that’s a very simple hardware mod.

Look at the first picture with the board I’m using it’s a single cut trace. Once you’ve cut that trace, check that pin 2 of the header (LCD’s VCC) is not connected to anything on the board, including VCC on 4 pin header. Use your multimeter’s continuity checking tool for that. If it’s not OK, or your expander looks similar but is totally different, leave me a pic of both sides of your expander in the comments, I’ll show you which traces to cut and where to connect 5V =) Once it’s clear 5V is not connected to anything, you can solder a short piece of wire to the pin 2 solder a single 2.54 pin at the end of that wire and hotglue it in place so that it’s more of a 5 pin header than a 4 pin header.

That’s it! Now connect the backpack to your Raspberry Pi:

LCD 5V VCC (pin we added) 5V GND GND VCC 3.3V SDA SDA SCL SCLNow, let’s check the connection and get the software!Step 3: Software for the LCD
I2C LCD Backpacks for 1602 Screens Buttons