Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PCF8574 IO Expansion i2c relay board -DO8 arduino demo code
#1
Code:
#include "Arduino.h"
#include "PCF8574.h"

// Set i2c address
PCF8574 pcf8574(0x27,4,5);  //4 is SDA  5 is SCL  need replace by your board's pin define
/*
A0  A1  A2
0    0    0    =0x20
0    0    1    =0x21
0    1    0    =0x22
0    1    1    =0x23
1    0    0    =0x24
1    0    1    =0x25
1    1    0    =0x26
1    1    1    =0x27
*/
void setup()
{
    Serial.begin(115200);
//    delay(1000);
    // Set pinMode to OUTPUT
    pcf8574.pinMode(P0, OUTPUT);
  pcf8574.pinMode(P1, OUTPUT);
  pcf8574.pinMode(P2, OUTPUT);
  pcf8574.pinMode(P3, OUTPUT);
  pcf8574.pinMode(P4, OUTPUT);
  pcf8574.pinMode(P5, OUTPUT);
  pcf8574.pinMode(P6, OUTPUT);
  pcf8574.pinMode(P7, OUTPUT);
//    pcf8574.pinMode(P1, INPUT);
    Serial.print("Init pcf8574...");
    if (pcf8574.begin()){
        Serial.println("OK");
    }else{
        Serial.println("KO");
    }
}
void loop()
{
    pcf8574.digitalWrite(P0, HIGH);
  delay(300);
  pcf8574.digitalWrite(P0, LOW);
  delay(300);
}
arduino code download

.zip   DO8.zip (Size: 485 bytes / Downloads: 156)
PCF8574 arduino library ZIP file download:

.zip   PCF8574_library.zip (Size: 23.8 MB / Downloads: 158)
Reply
#2
I try this, but doens work, my arduino didnt recognize de product, dont find the i2c address in any position.. I try using a i2c scanner but doesnt connect.
Reply
#3
make sure your arduino device have set correct i2c bus pins, check with SDA and SCL pin define.
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)