Issue with PCF8575 Input?

Hello All!

I'm using the example from GitHub - xreef/PCF8575_library: Library to use i2c digital expander with arduino, esp8266 and esp32. Can read write digital value with only 2 wire (perfect for ESP-01)., I've used all of them, but lets say specifically the Key Pressed one.

The issue I'm having is that It takes about 100-120 mA of current to make the 8575 read a HIGH. It'll be pulled low on its own it seems, but to make it read HIGH, i basically have to short it to 5v, since not even a 1kohm resistor to 5v does the job.

I'm using a module from Aliexpress and the chip on it is a NXP PCF8575CTS. Its off a Wemos D1 Mini, with a level shifter to be able to talk to the 8575 at 5v.

I can read inputs (provided its basically shorted to 5v) and can write Outputs to the 8575.
Anyone have any ideas what could be causing this?

You have probably fried the chip, or at least that pin, because you have not understood how this chip works.

To use a pin as an input on the pcf chip, you must write a 1 to it, making it output a (weak) HIGH. A circuit connected to it can then pull it low or not (e.g. a switch/button). When you read the pin back, you can see if it has been pulled LOW or is still HIGH. Pulling the pin LOW takes very little current because it is only a weak HIGH, like using INPUT_PULLUP on an Arduino pin.

If you write a 0 to a pin, it becomes an output and outputs a strong LOW. If you try to force it HIGH by pulling it up to 5V strongly, the current will exceed the absolute maximum stated in the data sheet, and the chip will probably be damaged.

This chip will happily run at 3.3V, so a level shifter is not needed. The chip will only output 3.3V, of course. Do you need it to output 5V for some reason?

Hi,
Can you post a circuit diagram of how you have your project connected please?

A picture of your project would also help.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Could be useful, but PaulRB has accurately pointed out the coding blunder causing this behaviour. :+1:

Hey Paul,

Thank you for the reply!

You have probably fried the chip, or at least that pin, because you have not understood how this chip works.

Thankfully I have a few on hand to continue testing with! Just before typing this and to elimate this doubt, I opened the package for the third one and soldered in the header pins. Same issue persisted.

To use a pin as an input on the pcf chip, you must write a 1 to it, making it output a (weak) HIGH. A circuit connected to it can then pull it low or not (e.g. a switch/button).

I understand, but I didn't see this covered in any of the example sketches? I also tried this, but it didn't yield the expected results. The exact coding is below. I even included a heartbeat to make sure I wasn't missing anything. Even with this new third 8575 and this slightly modified example sketch, a 1kohm resistor tied to 3.3v directly (I literally only have the cables running between the Wemos D1 and the 8575, to eliminate all other possible interference) will not pull up the pin.

(Note, I've soldered the address pads to ground (and can read inputs), so its not the possibility of another address. )

#include "Arduino.h"
#include "PCF8575.h"

// Set i2c address
PCF8575 pcf8575(0x20);
unsigned long timeElapsed;
void setup()
{
	Serial.begin(115200);

	pcf8575.pinMode(P1, INPUT);

	pcf8575.begin();
  Serial.println("Start");
}

void loop()
{
  pcf8575.digitalWrite(P1, HIGH);
	uint8_t val = pcf8575.digitalRead(P1);
	if (val==HIGH) Serial.println("KEY PRESSED");
	delay(100);
 Serial.print(".");
}

This chip will happily run at 3.3V, so a level shifter is not needed. The chip will only output 3.3V, of course. Do you need it to output 5V for some reason?

It works out best for my application, since there's a few other things that need 5v.

One last thing, the datasheet you referenced is a Ti datasheet, this is a NXP chip. Im not sure how much that matters? Honestly, I'm considering that these are just counterfeit chips, writing it off as a hardware failure and sourcing different ones.

Photo attached, but not much to show. I’ve stripped it down to just the wires running between everything

I still believe the issue is the way you are using the chip, not the chip itself. Whatever issue it is you are persisting with, you are probably persistently damaging each chip you use!

if (val==HIGH) Serial.println("KEY PRESSED");

How is this "key" wired?

please explain what those are.

Then post a schematic. Hand drawn is fine as long as it is neat, clear and a proper schematic. And get some breadboards!

you are probably persistently damaging each chip you use!

I can see how thats possible! Unless I'm damaging it when soldering it....somehow? The only thing that touches it are the 3.3v, GND, SLA & SDA and then the 3.3v to the input with a 1kohm resistor. I mean... at this point (and I assume I'm kinda jumping the gun here) the only thing that it could be is faulty hardware? Next step is to open a fourth one and not solder the pins in, to eliminate the possibility of heat damage (which shouldn't be the case to begin with. I'm not being harsh with the soldering iron).

How is this "key" wired?

"Key" is that wording from the example. In reality its a 1kohm resistor wrapped around a cable that I make contact with on the pin. Not pretty, but it works!

And get some breadboards!
.....Yeah. I agree. This ones completely on me. I've really been putting it off but I need to invest in a proper breadboard.

The issue persists with the bare bones wire with the example sketch. The other modules have been eliminated from trouble shooting since the issue persists with them removed.

Ok, so...

You are in fact powering the pcf with 3.3V.

You are wiring the button between 3.3V and the pcf pin with a 1K series resistor, but you cannot detect the button press?

Connect the button between the pcf pin and ground. Forget the resistor, it's not needed. When the button is pressed, the pin will read LOW.

Connect the button between the pcf pin and ground. Forget the resistor, it's not needed. When the button is pressed, the pin will read LOW.

Correct, but it draws 100-120mA when it does, which can't be correct! Nor sustainable since I have a total of 4 buttons I need to measure the input for.

Any other suggestions?

Hi,
Did you try the example code that came with the library?

/*
 KeyPressed on PIN1
 by Mischianti Renzo <http://www.mischianti.org>
 https://www.mischianti.org/2019/01/02/pcf8575-i2c-digital-i-o-expander-fast-easy-usage/
*/

#include "Arduino.h"
#include "PCF8575.h"

// Set i2c address
PCF8575 pcf8575(0x20);
unsigned long timeElapsed;
void setup()
{
	Serial.begin(115200);

	pcf8575.pinMode(P1, INPUT);

	pcf8575.begin();
}

void loop()
{
	uint8_t val = pcf8575.digitalRead(P1);
	if (val==HIGH) Serial.println("KEY PRESSED");
	delay(50);
}

Connect P1 to 3v3 then gnd.
Tom... :grinning: :+1: :coffee: :australia:

Hey Tom!

Thanks for the reply. Yes, I’ve tried that and my problem is the unreasonable amount of current it requires to pull it HIGH, as mentioned above

Correction on mis-type

Hi,
Does the serial monitor indicate the change is state?

Can you please post a picture of the component side of your 8575 module?

Tom... :grinning: :+1: :coffee: :australia:

No, you said you were trying to pull it HIGH:

Pulling it HIGH when it's output is LOW would take a damaging level of current. Pulling it LOW when it's output is HIGH should take a very small current, less than 0.1mA.

you said you were trying to pull it HIGH

Oops, typo! You’re right and I corrected my previous post.

Pulling it HIGH when it's output is LOW would take a damaging level of current.

Agreed! But my issue is that I can’t get it to read a logic level HIGH unless I short it to 3.3v, which takes a unreasonable amount of current. My issue isn’t the output aspect of the chip/module. That works as expected. It’s getting the darn thing to read a logic level high.

Should not be necessary to do anything to make it read HIGH. When the pin is set to be an input, it should read HIGH because of its own internal pull-up resistor, unless something external pulls it low. Perhaps you have a short circuit or button connected wrong or a damaged chip. Without a schematic, we can only guess.

Hi,
Where are you measuring the current?

Can you please post a picture of the component side of your 8575 module?

Tom... :grinning: :+1: :coffee: :australia:

I believe there maybe another problem. That module has an inbuilt 3.3v regulator judging by the picture the OP provided. Something like this: PCF8575 IO Expander Module I2C To 16IO For Arduino | eBay

If the solder jumpers are not set correctly, the 3.3 volts from the Wemos D1 will go through that regulator reducing its effective voltage.
Further, the datasheet specifies external pullup resistors of 100k (to the same potential as the pin 24 of the PCF8575)

Ah yes, I recall that now. :confused:

There is a rather strange reason why they are necessary, but I cannot recall it just at present.