Go Down

Topic: [Solved] Reading data from a PCF8574 (Read 550 times) previous topic - next topic

Mubanga

Feb 07, 2013, 08:37 pm Last Edit: Feb 08, 2013, 02:34 pm by Mubanga Reason: 1
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:
Code: [Select]
#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!

Nick Gammon

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

http://www.gammon.com.au/i2c
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

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

Code: [Select]

#define  DEVICE_ADDRESS  56


So how is it supposed to know which device?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Grumpy_Mike

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.

Mubanga

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

Go Up