Arduino: LCD with I2C Expander PCF8574

If you don't want to use 7 or more pins of your Arduino for a character LCD, an I2C expander is your first choice.

The PCF8574 8-Bit I/O Expander

This IC is probably the most used "I2C LCD adapter". The I2C address are mostly either 0x3F or 0x27 depending on the used chip. When working with I2C always check with an I2C Scanner the wiring and the correct address. After setting the address of your display, the Hello World sketch should work like expected.

The Character Set of the HD44780U A00 ROM

There are several Arduino libraries available for this chip. So why does the world need an additional library? The "Noiasca Liquid Crystal" library does a character mapping from UTF-8 to the existing characters in the Hitachi HD44780U A00 ROM. As example some special characters in the second row of the display:

LCD special characters for Arduino

(Degree, Division, middle Point, n with tilde, Pound, Yen, Tilde, Sqareroot, Proportional to, Infinity, Left Arrow, Right Arrow, Backslash)

You can read more about this character mapping in the Introduction or in the German section of this site. For the beginning you should just know that you don't need to enter the octal ROM addresses of the special characters manually and these print can be done by a simple:

lcd.print("°÷·ñ£¥~√∝∞←→\\");

The Hardware Driver for I2C Expanders

The library offers a basic class for displays connected with an I2C expander. It uses the 4bit mode only.

The necessary #include and the constructor are:

#include <NoiascaLiquidCrystal.h>
#include <NoiascaHW/lcd_PCF8574.h>
LiquidCrystal_PCF8574 lcd(lcdAddr, cols, rows);

Remember to add a Wire.begin() to your setup() like in the examples, as this will not be done in the library. (ok, there is a little hack for some processors in the library, but don't rely on it. Do a Wire.begin in the setup before you call the LCD.begin).

Using LCD with Wire1 or Wire2 (for example on a Teensy)

If you want to use the LCD on another I2C port you can hand over an additional parameter to the constructor:

LiquidCrystal_PCF8574 lcd(Wire1, lcdAddr, cols, rows);

Your own Character Converter

If you need a different converter for the characters you can hand over a callback function as optional last parameter.

Obviously - you also have to implement the callback function to do all the magic.

See the general example how to write your own character converter.

German Umlauts

For my German readers: the default constructor enables the support for the small letters ä ö ü and ß. For the sharp s ß we are using the Greek beta as it is available on the LCD. The large German umlauts Ä Ö Ü will be converted to their counterpart A O U. If you want to try other variants, you can use following constructors:

LiquidCrystal_PCF8574 lcd(lcdAddr, cols, rows);                    // (Ä gets A)
//LiquidCrystal_PCF8574 lcd(lcdAddr, cols, rows, convert_ae);      // Ä become Ae
//LiquidCrystal_PCF8574 lcd(lcdAddr, cols, rows, convert_small);   // Ä become ä
//LiquidCrystal_PCF8574 lcd(lcdAddr, cols, rows, convert_special); // Ä become Ä

Summary

If you need an easy support of the given character set of a HD44870 display, take the "Noiasca Liquid Crystal" library in consideration.

Links

(*) Disclosure: Some of the links above are affiliate links, meaning, at no additional cost to you I will earn a (little) comission if you click through and make a purchase. I only recommend products I own myself and I'm convinced they are useful for other makers.

 

Protokoll

First upload: 2020-09-02 | Version: 2024-03-22