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!!