I have three waveshare PCF8574, one works perfectly read and write.
The other two only return 255 for value = PCF_38.read8();
The PCF8574 is connected to UNO I2C with 4K7 resistor on sla and sda line to 3.3v . Found a link that said I should use 3.3 not 5v oops, and have changed the voltage, didn't fix the problem though.
The test program is from the forum // FILE: pcf8574_test.ino // AUTHOR: Rob Tillaart with some Serial.print added.
partial results of test of good device
test 0
value of #38: 0
value of #38: 1
value of #38: 2
value of #38: 3
value of #38: 4
..
value of #38: 254
value of #38: 255
partial results of test of less than good device
test 0
value of #38: 255
value of #38: 255
value of #38: 255
value of #38: 255
value of #38: 255
..
value of #38: 255
value of #38: 255
//
// FILE: pcf8574_test.ino
// AUTHOR: Rob Tillaart
// DATE: 27-08-2013
//
// PUPROSE: demo
//
#include "PCF8574.h"
#include <Wire.h>
// adjust addresses if needed
PCF8574 PCF_38(0x38); // add switches to lines (used as input)
PCF8574 PCF_39(0x39); // add leds to lines (used as output)
void setup()
{
Serial.begin(9600);
delay(20);
Serial.print(" ");
Serial.print(" ");
Serial.print("------------------------------------------------------");
Serial.print("-- setup ---");
Serial.println("\nTEST PCF8574\n");
uint8_t value =0;
Serial.println("test 0 ");
for (int i = 0; i< 256; i++)
{
PCF_39.write8(i);
value = PCF_38.read8();
Serial.print("value of #38:\t");
Serial.println(value);
delay(10);
}
Serial.println("test 1");
PCF_39.write(0, 1);
for (int i = 0; i<7; i++)
{
PCF_39.shiftLeft();
value = PCF_38.read8();
Serial.print("value of #38:\t");
Serial.println(value);
delay(10);
}
Serial.println("test 2");
for (int i = 0; i<7; i++)
{
PCF_39.shiftRight();
value = PCF_38.read8();
Serial.print("value of #38:\t");
Serial.println(value);
delay(10);
}
Serial.println("test 3");
for (int i = 0; i<8; i++)
{
PCF_39.write(i, 1);
value = PCF_38.read8();
Serial.print(i);
Serial.println(",1");
Serial.print("value of #38:\t");
Serial.println(value);
delay(10);
PCF_39.write(i, 0);
value = PCF_38.read8();
Serial.print("value of #38:\t");
Serial.println(value);
delay(10);
}
Serial.print("4");
for (int i = 0; i<8; i++)
{
PCF_39.toggle(i);
Serial.print("toggle i");
Serial.println(i);
value = PCF_38.read8();
Serial.print("value of #38:\t");
Serial.println(value);
delay(10);
PCF_39.toggle(i);
value = PCF_38.read8();
Serial.print("value of #38:\t");
Serial.println(value);
delay(10);
}
Serial.print("-- end of setup ---");
}
void loop()
{
}
//
// END OF FILE
//