PCF8574 read problem

I used PCF8574 expander in a bunch of projects, but output only. Now I am on some project where I need it as input. There comes the problem

Although I have a button with a pull-down resistor, it always shows LOW. When I don't press the button on the multimeter I can see there is GND on the P6, the pin I tied button. When I press the button, there is a 3,3V (3,3V logic I use here). So, on P6 I have LOW or HIGH. But, on Serial, I always get LOW, no matter what comes to P6.

Here is the sketch.

#include "Arduino.h"
#include "PCF8574.h"
PCF8574 pcf8574(0x38);
void setup(){
	Serial.begin(9600);
	pcf8574.pinMode(P6, INPUT);
}
void loop(){
  Serial.println(pcf8574.digitalRead(P6));
}

What am I missing?

not used the library for expander before so not sure...

why not try doing the i2c commands 'directly'! :wink:

you could try an example code like this one.

hope that helps...

Hi,

Does your code need this in setup?

Serial.print("Init pcf8574...");
	if (pcf8574.begin()){
		Serial.println("OK");
	}else{
		Serial.println("KO");
	}

To initialize the 8574.
I hope this is the library you are using?
Can you post a link to where you got your library please?
Have you looked at the examples?
Tom... :slight_smile:

Which PCF8574 library are you using?

To read it you first must set all the Outputs high (0xFF). The outputs are pseudio I/O where the pull down is an active NFET and the pull is accomplished with a pinch fet. Simply stated it has a pull up resistor and a mosfet output that is only active low. When the pins are read it returns the value on the pins not the output register and there is no input register. Setting the outputs low and placing +5V on them can fry the chip.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.