Interfacing with PCF8574 I2C I/O expander

Hi,

I've been trying to get an NXP PCF8574 I2C 8bit I/O expander working for a few days now. I've successfully used the Wire.h library before (with an I2C EEPROM) but this time I'm getting nothing! Here's a link to the datasheet: http://www.nxp.com/acrobat/datasheets/PCF8574_4.pdf.
I have it hooked up like so:

     _ _
GND--| U |--5V
GND--|   |--SDA (Analog 4) --10kohm---5V
GND--|   |--SCL (Analog 5) --10kohm---5V
   --|   |--
   --|   |--
   --|   |--
   --|   |--
GND--|   |--LED---470ohm---5V
     ---

In other words, the 3 address pins A0, A1, and A2 are grounded, as well as the Vss pin. 5V is connected to the Vdd pin. SDA and SCL are connected to the arduino analog inputs for I2C, with 10k pullup resistors to Vdd. I have an LED connected to 5V with a 470ohm resistor and the cathode connected to P4 (the fifth bit). You have to do it this way because the chip can sink more current than it can source, right?

Here's the simplified version of the code I used to test this:

#include <Wire.h>

#define expander B01000000 //expander address with 3 address pins grounded

void setup() {
  Wire.begin();
}

void loop() {
  expanderWrite(B11111111); //turn all ports high
  delay(1000);
  expanderWrite(B00000000); //turn all ports low
  delay(1000);
}


void expanderWrite(byte _data ) {
  Wire.beginTransmission(expander);
  Wire.send(_data);
  Wire.endTransmission();
}

When I run this, I see a very dim glow from the led but it doesn't blink at all. I also tried writing and reading from the chip to see if it was getting anything from the arduino, using this code:

#include <Wire.h>

#define expander B01000000

void setup() {
  Wire.begin();
  Serial.begin(9600);
}

void loop() {
  Serial.println("Writing B11111111.");
  expanderWrite(B11111111);
  Serial.print("Read: ");
  Serial.println(expanderRead(), BIN);
  delay(1000);
  Serial.println("Writing B00000000.");
  expanderWrite(B00000000);
  Serial.print("Read: ");
  Serial.println(expanderRead(), BIN);
  delay(1000);
}


void expanderWrite(byte _data ) {
  Wire.beginTransmission(expander);
  Wire.send(_data);
  Wire.endTransmission(); 
}

byte expanderRead() {
  byte _data;
  Wire.requestFrom(expander, 1);
  if(Wire.available()) {
    _data = Wire.receive();
  }
  return _data;
}

And it actually reads back what I sent to it... but the LED doesn't blink!

So, in the interest of not pulling out all my hair, I came here to see if someone can give me any ideas or if anyone has gotten this I/O expander working before.

Thank you!!

Hi,
I think you got the address of the device wrong.
The Wire Lib expects a 7-bit address that is the address highlighted on page 9 of the datasheet.
Its the seven bits named slave-address under the curly bracket. The Read/Write bit is not part of the address.
That would make

//define expander B01000000 //one bit to high
#define expander B00100000 //expander address with 3 address pins grounded

the correct address.

Eberhard

You know, that makes a lot of sense. I'll try that.
Thanks!

Yep, that did it!
Weird, though, that the read function was returning the right values.
Anyways, you rock, thank you.

There's a PCF8574A version of the PCF8574 which means you can connect up to 16 (128 bidirectional I/O's) to the single i2c bus.

We designed the dCoreDuino168 with an inline i2c header, so any complimentary circuits we can add to make use of the header, we'll produce PCB's.

Futurlec have this board:-

http://www.futurlec.com/Mini_PCF8574.shtml

Their board shows the address for the A as well, but they forgot to mention it expands connectivity another 8, so it's 8 stated in their documentation for the "PCF8574" plus, another 8 using the "PCF8574A".

We can manufacture the PCB's in numbers and therefore produce a board considerably less expensive than theirs, so I'd like to know how you get on using the IC with Arduino, and what application, and any issues you discover as a result of the work you do with it - providing you don't mind posting updates.

Thanks!