11-07-2024, 12:04 PM
(11-07-2024, 11:52 AM)admin Wrote: just do as our sample code's I2C bus pin define.
I did set pint to 4/5 and modified your example to get it up and running, maybe someone else will re-use it as original code is not working - at lest for myself)
Code:
#include "Arduino.h"
#include "Adafruit_PCF8574.h"
static const uint8_t P0 = 0;
static const uint8_t P1 = 1;
static const uint8_t P2 = 2;
static const uint8_t P3 = 3;
static const uint8_t P4 = 4;
static const uint8_t P5 = 5;
static const uint8_t P6 = 6;
static const uint8_t P7 = 7;
static const uint8_t PIN_UART_RX = 3;
static const uint8_t PIN_UART_TX = 1;
static const uint8_t PIN_SDA = 4;
static const uint8_t PIN_SCL = 5;
// Set i2c address
Adafruit_PCF8574 pcf8574_1;//(0x24,4,5);
Adafruit_PCF8574 pcf8574_2;//(0x25,4,5);
TwoWire i2c = TwoWire(0);
void setup()
{
Serial.setPins(PIN_UART_RX, PIN_UART_TX);
Serial.begin(9600);
delay(1000);
i2c.begin(PIN_SDA, PIN_SCL);
Serial.print("Init pcf8574_1...");
if (pcf8574_1.begin(0x24, &i2c)){
Serial.println("PCF8574_1_OK\n");
}else{
Serial.println("PCF8574_1_KO");
}
Serial.print("Init pcf8574_2...");
if (pcf8574_2.begin(0x25, &i2c)){
Serial.println("PCF8574_2_OK");
}else{
Serial.println("PCF8574_2_KO");
}
pcf8574_1.pinMode(P0, OUTPUT);
pcf8574_1.pinMode(P1, OUTPUT);
pcf8574_1.pinMode(P2, OUTPUT);
pcf8574_1.pinMode(P3, OUTPUT);
pcf8574_1.pinMode(P4, OUTPUT);
pcf8574_1.pinMode(P5, OUTPUT);
pcf8574_1.pinMode(P6, OUTPUT);
pcf8574_1.pinMode(P7, OUTPUT);
pcf8574_2.pinMode(P0, OUTPUT);
pcf8574_2.pinMode(P1, OUTPUT);
pcf8574_2.pinMode(P2, OUTPUT);
pcf8574_2.pinMode(P3, OUTPUT);
pcf8574_2.pinMode(P4, OUTPUT);
pcf8574_2.pinMode(P5, OUTPUT);
pcf8574_2.pinMode(P6, OUTPUT);
pcf8574_2.pinMode(P7, OUTPUT);
}
void loop()
{
pcf8574_1.digitalWrite(P7, LOW);
delay(1000);
pcf8574_1.digitalWrite(P7, HIGH);
delay(1000);
pcf8574_2.digitalWrite(P7, LOW);
delay(1000);
pcf8574_2.digitalWrite(P7, HIGH);
delay(1000);
}