i2c LCD - What am I missing?
Jeff Haas
Posts: 421
in Propeller 1
I've got an LCD display with an i2c backpack. It's the one named "I2C LCD DISPLAY VERSION 3" on this page, although this isn't where I bought it: http://arduino-info.wikispaces.com/LCD-Blue-I2C
There's a pretty long thread here on these displays, I've gone over it in detail and it includes code:
http://forums.parallax.com/discussion/146904/propeller-1-and-i2c-lcd-please-help/p1
I used the i2c scanner in that thread; on the Quickstart it will find the address of the LCD (0x27) if it's connected to 28 and 29 but not other pins, even if using the pull-ups recommended in the thread. And I've got JonnyMac's code as well, both for talking to the display and for running a demo. But when I run it, no letters show on the display - but it looks like it's being talked to, because when you get to the end where the backlight blinks, that works.
There is something different about this i2c display, but I can't figure it out. Any ideas what I should look at?
There's a pretty long thread here on these displays, I've gone over it in detail and it includes code:
http://forums.parallax.com/discussion/146904/propeller-1-and-i2c-lcd-please-help/p1
I used the i2c scanner in that thread; on the Quickstart it will find the address of the LCD (0x27) if it's connected to 28 and 29 but not other pins, even if using the pull-ups recommended in the thread. And I've got JonnyMac's code as well, both for talking to the display and for running a demo. But when I run it, no letters show on the display - but it looks like it's being talked to, because when you get to the end where the backlight blinks, that works.
There is something different about this i2c display, but I can't figure it out. Any ideas what I should look at?
Comments
I have made recent updates to my object for that backpack; I've attached for your convenience.
Thanks to both Peter and JonnyMac.
Notes:
- I connected to VDD and GND, and the SDA and SCL pins on the Quickstart board.
- The Quickstart board will work without the pull-ups but the LCD performs better with 10K pull-ups.
- I updated JonnyMac's jm_twi_lcd_demo to work with the updated pcf8574 object, that file is attached. It's set up for an LCD at the 0x27 address, 16x2.
...because the PCF8574 device type ($20) is fixed -- you can only change the address (%000..%111). The comment you have in the code suggests you can change the device ID.
Just for completion, I've attached an updated version of the demo code with the change.
The constant for the I2C address is limited to three numbers:
LCD_ADDR = %111
However, I just got a new I2C LCD, 20 columns wide by four lines, and it's set to an address which is longer in binary. These are the results from the I2C scanner:
2-line LCD - 4e27
01001110 00100111
New 4-line LCD - 4e3F
01111110 00111111
So the object can't address it correctly. I've gone through all the files in the code but this is over my head.
Jeff
Please provide a link to the problematic display. I have run that code through two different PCF8574 backpacks and both work just fine.
And what I2C scanner are you using? I wrote my own but it only cares about 7-bit devices.
I don't mind fixing broken code, but don't like being blamed for problems I didn't create. This is why I had stopped posting in ObEx and am now beginning to think that posting again is a bad idea.
The chip is an PCF8574AT. After some digging, I found that there are two versions of the chip out in the wild - PCF8574T and the PCF8574AT. The difference is the I2C addresses have a different range, so multiple devices can be on the same buss.
I ordered a device with what I thought was the same backpack, and I thought it would be an easy swap for my other LCD, but the one with the other version of the chip showed up.
Here's a link to the data sheet for both versions of the chip:
http://www.nxp.com/products/interface-and-connectivity/interface-and-system-management/i2c/i2c-general-purpose-i-o/remote-8-bit-i-o-expander-for-icbus-with-interrupt:PCF8574_74A
The first version of the chip has addresses that go from hex 20 - 27; the "A" version has addresses that go from 38 to 3F. See Table 4 and Table 5 of the datasheet.
This backpack actually has spots to change the I2C address via solder bridges. Picture attached.
I'm using Tim Moore's i2cScan object, linked in kuroneko's post in the thread previously discussed:
http://forums.parallax.com/discussion/146904/propeller-1-and-i2c-lcd-please-help/p1
As a test, I temporarily bridged A0 closed and ran the scan, and got the correct addresses (3E).
Sorry to come off as annoying, I just try to cut the problem down to the smallest parts. Please let me know if there is anything more I can help with, including testing code before it is posted.
This is a point of confusion/contention. In my world view, a given I2C device can have up to eight addresses %000-%111; though not all device types support all possible addresses. This means for a 7-bit device code (plus RW bit) the possible range is %0001_000_0 through %1110_111_0. Note that group (upper four bits) %0000 is not valid for a single device, and group %1111 is used for special addressing (e.g., 10-bit).
I've attached my own scanner. I used to output all address while scanning, after seeing the program you referenced I changed it just to the devices actually found on the buss. You may find, as I do, that the formatted output is easier to deal with.
The LCD I2C address needs to be changed like this in the top object, for a backpack using the second version of the chip (with the "A"):
From this format, in the current object, set to (0x27):
LCD_ADDR = %111
To this one, (0x3f)
LCD_ADDR = %0111111
I've also discovered that the USB port on my desktop computer is starting to go wonky, and depending on how the USB plug is put in, doesn't give a good connection, even though the Quickstart gets power. So sometimes the LCD didn't work right even though it powered up, thus leading to a lot of incorrect results.
Your new LCD uses the PCF8574A which has a type code of %0111. The possible addresses for that device are %000..%111. Combining these and shifting left by one for the RW bit you can have
%0111_000_0 to %0111_111_0 as valid base device codes (7-bit buss address) for the PCF8574A.
The address parameter in the LCD driver is the 3-bit portion to select a specific PCF8574A, NOT THE ENTIRE 7-BIT DEVICE CODE.
I added two new methods to my PCF8574 object -- the "a" methods to use that device. Likewise I added an "a" method to the the LCD object. The updated LCD driver works with the normal start method with my LCD, you'll have to try it with yours using the new "a" method.
Since every detail seems to have to be spelled out in the forums, what I'm saying is that for your new display you'll start the LCD driver object like this:
Set LCD_ADDR to the 3-bit address revealed by my scanner -- that's the three bits between the two underscore characters in the output.
Very cool!
I rule!