I2C - Pin wiring

Hello,

This is my 1st post and I'll try my best to describe the problem.

I've been doing this little project with Arduino Uno, DHT22 sensor and 20x4 display.

A Co-worker has given me I2c module that they have made with pcf8574 chip on it (It isn't used with Arduino, but for debugging and wrote the code in C for the display). And after weeks of unsuccessful attempts to make it work...i figured that the pins are wired differently, I've found a thread where someone had a similliar problem. 2x20 (ST7066U) lcd not working - Displays - Arduino Forum

Basically the pin wiring on pcf8574 is different than what it's supposed to be. Can the library be adjusted and defined differently?

I'm aware that the module is so cheap i could just order a new one that works out of the box, but if there's a way around this one i would be glad to try and ''fix it''.

The display is working, and the I2c module works if its used with the code it was written for on a different application.

EDIT: I've managed to do solve the problem. I've found the constructor in the code.

hd44780_I2Cexp lcd(addr, chiptype, rs,[rw],en,d4,d5,d6,d7,bl,blpol);
hd44780_I2Cexp lcd(0x27, I2Cexp_PCF8574, 0,1,2,4,5,6,7,3,HIGH); // with rw support

And managed to edit and change so the pinout is correct. The display is working now.

OK, so it is a trifle unclear what you are describing but apparently you have a "home made" PCF8574 module - certainly not a profitable project in itself as indeed both modules for the common 1602 and 2004 LCD modules and as general-purpose port expanders are cheaper to buy from China than to construct, or at least this was the case until the recent at minimum doubling of prices on eBay.

So what we need to know is if this module actually is specifically crafted to interface with a 2004 display, whether its configuration is copied from one - any one - of the available I2C "backpacks" and whether it implements all the functions of such a "backpack" ?

If it does, then you need to use the IDE Library Manager to install the "HD44780" library after which you will find code in the "examples" section to automatically detect the particular configuration and actually make the display operate correctly. You can then use such code to implement your own project, continuing to use (or not if you choose otherwise) the automatic configuration.

Indeed, it may even work if this module's configuration was not deliberately copied from a particular module to hand.

I can't tell what you started with and what you have done.
And what environment you are trying to get the LCD working in.
I have assumed that you took a backpack that was being used in a non Arduino environment and are now trying to use it with Arduino projects.

It sounds like things weren't working but then you changed something?
The hd44780_I2Cexp i/o class does not use a single pin wiring and can auto detect between several different wirings.
And the constructor that you show is using one of the most common pin wirings.

Can you step back a bit and describe how things were when you started.
Please describe:

  • your build environment
  • how the PCF8574 Px pins wired up to the LCD.
  • what you changed to get something working.

---- bill

Yeah I'm a bit fresh with all of this, so excuse me if my describing wasn't really that helpful.

Well as you assumed. The backpack was ''home made'' and it is being used in other environment with a 20x4 display.

Things weren't working because the pin wiring on the backpack were like this:

LCD pcf8574 output port pin
DB7 P3
DB6 P2
DB5 P1
DB4 P0

EN P4
RW P5
RS P6

So i was struggling to make it work because, i had the schematics but was not aware that the pin wiring with common available backpacks were different.

When i installed HD44780 library, I ran I2CexpDiag, it found the address every time but had LCD busy stuck error. I have checked the soldering on display and the backpack. The display was working separately as was the backpack.

And after searching for an answer and stumbling on a thread with similar results i realized the pin wiring was wrong. Then i tried to figure out, how should i try and fix the situation.

First i tried to make a cable from display to backpack with switched pins...so i had to re-route every connection by itself. It almost worked..I2CexpDiag then passed the LCD busy stuck problem...but had memory error.

I found the constructor in hd44780_I2Cexp and the option to use pre-defined backboard types. So i changed the configuration

From this: hd44780_I2Cexp lcd(0x27, I2Cexp_PCF8574, 0,1,2,4,5,6,7,3,HIGH);

To this: hd44780_I2Cexp lcd(0x27, I2Cexp_PCF8574, 5,6,4,0,1,2,3,7,HIGH);

Not sure what you mean by this:

I found the constructor in hd44780_I2Cexp and the option to use pre-defined backboard types. So i changed the configuration

From this: hd44780_I2Cexp lcd(0x27, I2Cexp_PCF8574, 0,1,2,4,5,6,7,3,HIGH);

To this: hd44780_I2Cexp lcd(0x27, I2Cexp_PCF8574, 5,6,4,0,1,2,3,7,HIGH);

There is no default pin mapping using the constructor you mentioned in the library.
That said, the pin mapping (5,6,4,0,1,2,3,7,HIGH) is not one of the 6 mappings supported by the auto configuration so you will have to do a manual configuration.

BTW,
You can leave off the i2c address or set it to 0 in the constructor to get the library to auto locate the i2c address.

--- bill

Ah yes that is what i meant, i have manually configured it.

Thanks for the guidance Bill