Pages: [1]   Go Down
Author Topic: [Solved] Reading data from a PCF8574  (Read 456 times)
0 Members and 1 Guest are viewing this topic.
Gouda, The Netherlands
Offline Offline
Newbie
*
Karma: 1
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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!
« Last Edit: February 08, 2013, 08:34:17 am by Mubanga » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://www.gammon.com.au/i2c
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#define  DEVICE_ADDRESS  56

So how is it supposed to know which device?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 604
Posts: 33432
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Gouda, The Netherlands
Offline Offline
Newbie
*
Karma: 1
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: