[Solved] Reading data from a PCF8574

Hi,

I'm fairly new to Arduino, I did a few basic projects. Now I'm trying to learn more about the PCF8574 I/O bus expander. I was able to connect 8 LED's and make them blink one at the time without to much trouble. But now I'm trying to read a button push and it's giving me a hard time for the past 2 days.

This is the way I've set up my project:

and this is the code I'm using:

#define  DEVICE_ADDRESS  56
 
#include <Wire.h>

byte x=0;
 
void setup()
{
  Wire.begin();                
  Serial.begin(9600);       
}
 
void loop()
{
  
  x = Wire.read();
  Serial.println(x);  

}

If somebody could take a look and tell me what I'm doing wrong, that would be great!

You don't do Wire.read on its own like that. Here, read this:

For one thing, you aren't even using this:

#define  DEVICE_ADDRESS  56

So how is it supposed to know which device?

You can look at your I2C read examples in the arduino IDE.

With this chip when you use it as an input you need to set the pins high with a write. Then the input will connect the pins to ground or not. You then read back the pins to see which have been shorted out.
This is the only chip I know that works like this, it is most unconventional.

I've got a much better understanding about I2C's now and got it working. Thank you both!