I2C LCDs

There are many types of I2C character LCDs on the hobby electronics market. To design my new open source data loggers and Phi-3 Arduino shield, I decided to move away from the bare parallel HD44780 character LCDs and go with character LCDs and I2C backpacks (aka I2C LCDs). I found out a few popular designs and thought that I would summarize them for your convenience.

Most I2C LCDs are based on the following two ICs, all of which are I2C I/O (port) expanders:

  • PCF8574 or PCF8574A
  • MCP23008

Hardware:

Both ICs have 8 I/O pins. MCP23008 is more versatile but that is irrelevant to simple applications in LCDs.

Adafruit designed an I2C LCD backpack and Arduino LCD shields based on MCP23008. There are compatible devices sold on ebay. I can’t tell without seeing the sample code to decide whether an ebay seller is actually selling a compatible product. But if you do want to get one on ebay, make sure you find their library code and confirm that the library contains Adafruit’s names. Libraries you find from ebay sellers are likely out of date though. One good thing is that the compatible ones are very likely using the same pin assignments as Adafruit’s so it’s easy to get it to work once you get the library installed.

FM (Francisco Malpartida) designed an I2C LCD backpack based on PCF8574. There are lots of compatible devices sold on ebay and they don’t have the same pin assignments! This creates issues when you are making purchases thinking that they have certain pin assignments. The pin assignments refer to which PCF8574 pin is connected to which HD44780 display pin. Also the I2C addresses are all different. I don’t mean one might have an address of 0x3F and another might have 0x3E. What I mean is that one might have 0x3F and another one may be 0x20. There is no way to set one display that has address 0x20 to address 0x3F! PCF8574 has address space of 0x20 to 0x27. PCF8574A has address space of 0x38-0x3F. Most common addresses I’ve seen are 0x20, 0x27, and 0x3F, with the latter two sharing pin assignments that are different from the ones with 0x20 address. Most of these displays allow you to cut traces or solder pads to change addresses. Why would you if you don’t have multiple LCDs?

Software:

Adafruit has its own library Adafruit_LiquidCrystal. This library is decent. It can take different pin assignments as parameters. On the other hand, it is a different library than Arduino’s included LiquidCrystal library. So code you wrote for LiquidCrystal library may need some change when you switch to an Adafruit compatible I2C LCD.

FM wrote a library New LiquidCrystal. This library is pretty good. You can use a number of different LCDs including parallel HD44780 LCDs, I2C LCDs using PCF8574, LCDs using shift registers etc. A nice feature is that there is a base class LCD so regardless what actual type of LCD you are using, as long as it’s supported by this library, it works the same way on the software level as another supported LCD.

Since not all PCF8574/74A I2C lcds have the same pin assignment, or even back light polarity, using the correct definition will be crucial. I found the following three definitions. Each seems to work with the particular I2C address, although there is no relation between I2C address and how the pins are assigned (by circuit designer):

The first two work on backpacks that look like this:

Notice that only the address is different. Pin assignments and back light polarity are all the same.

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Blue potentiometer with back light jumper.

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Blue potentiometer with back light jumper.

The last definition works on backpacks that look like this:

Notice that pins are very different and back light polarity is negative.

LiquidCrystal_I2C lcd(0x20, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE); // Tiny mental potentiometer no back light jumper.

Detection:

In case you can’t determine the address or pin out, say none of the above definitions work, but you’re sure the IC is PCF8574/74A, you should first scan the I2C bus for the address, and then use your meter to map out the pin assignments, and then use your definition. The lcd constructor has the following parameters: lcd(add, En, Rw, Rs, d4, d5, d6, d7, Bl, Pol).

Here is the I2C scanner I use by Tod E. Kurt:

https://github.com/todbot/arduino-i2c-scanner/

 

More about different LCD backpacks

Last time I discussed what serial LCD to buy. This time, as a response to some Arduino forum questions regarding I2C LCDs, I’ve written the following short comparison to prove that serial LCDs are better choice than I2C LCDs in most projects.

First, there is no official I2C liquid crystal library. Anything not included in arduino IDE 1.0 is contributed by one person or another and some get active support but the rest don’t so they are dead. Most ebay sellers are just selling I2C LCDs because they think they make money selling but not able to do any support and that’s why I put support at top priority. Just read comments on my blog you will see. Unfortunately mine is not I2C (IE cheapest, for good reasons). Just to clarify, although you can get a lib for an I2C LCD, the library goes with the particular I2C LCD and is not useful if you switch to another I2C LCD. Also arduino still does the heavy lifting to communicate with the LCD so your code will be long with the included lib and arduino spends processing time to do the LCD control. On the other hand, serial LCDs (on TTL serial) require no library so there won’t be a time when you want lib and the lib is not up to date and won’t compile. Also the serial LCD controller does all the heavy lifting for arduino. Your code is small since there’s no lib to include. Those are some of the reasons I make and sell serial LCDs and not I2C IO extender LCDs.

Two different I2C LCDs and why one is so much cheaper than the other/serial LCD:
1) LCD with I2C IO port extender (cheap). The port extender is a buck each. There is no “brain” on this type of I2C LCDs. The extender simply adds more IO ports to arduino. Arduino still does all heavy lifting and is prone to long compiled sketch and broken library problems.
2) LCD with controller that talks I2C with arduino (expensive). The controller is a few bucks and needs support such as crystal caps etc. There is a “brain” on this type of I2L LCDs. The controller does all heavy lifting so arduino has short sketch but there is still potential for broken library problems since most of these come with libraries to tell the controller what to do.

3) Then the serial LCD. It’s around the same price and complexity as 2) in terms of price and sometimes a serial LCD offers I2C connectivity as well. It’s not prone to broken library since everything is sent in serial text streams and arduino also has short sketch. You can also connect this type of LCD directly to a PC with a USB TTL adapter! The input and output are both asynchronous and buffered against overflow on arduino and serial LCD. — I’d go with this one, especially the best ones, designed by Liudr. 😉

Update:

Reply from brunialti at Arduino forum (agreed to be reposted here):

That is a really good introduction on choosing an lcd!
I like your approach, and I saw your serial LCD. There is a lot of “brain” inside. I think that it could be the appropriate choice for many projects and you tempted me to buy it (damn!).
On my side, as I’m going to integrate as many I2c device as possible, I would prefer not to manage two interfaces at the same time. The I2c has a strong point on its bus. You can buy a passive, small and cheap backplane and connect all the i2c devices you like, using 4 mu pins at all!

There is also a drawback in putting too much “brain” into devices: with the “brain” you put also logics, syntax and structure. That make impossible a drop-in substitution of a smart LCD with an other one.
That is similar to the broken library problem: you have to change the app code instead of the library code.

My reply to brunialti:

Very good points! Indeed I worried about that (different serial LCDs speak different commands), so, I have used all ANSI escape codes as much as I can so all functions are ANSI escape code driven or ASCII control code driven. So if you want to clear screen, that is \f (old speak for printer to spit out the entire sheet and ready a new sheet, feed). If you want to change LCD coordinates, you do the ANSI escape sequence “CSI n ; m H”, which is say “\e[2,4H” for 2 row and 4 column with 1-based numbers. I wish every serial LCD speaks ANSI, which is by far the most appropriate standard for a character display, but only few do and mine speaks the most ANSI words. All specific functions such as menus and scrolling texts are also implemented as custom ANSI escape sequence for maximal standardization. I’m pretty sure Sparkfun serial LCD won’t speak ANSI since it has a big brain but little intelligence inside. smiley-wink

http://en.wikipedia.org/wiki/ANSI_escape_code

%d bloggers like this: