PCF8574

From Pinguino
Jump to: navigation, search


The PCF8574 is an 8-bit input/output (I/O) expander for the two-line bidirectional bus (I2C) designed for 2.5V to 6V VCC operation. The device provides general-purpose remote I/O expansion for most microcontroller families by way of the I2C interface [serial clock (SCL), serial data (SDA)].

Example

Example for functions: I2C.master I2C.start I2C.send I2C.stop

u8 i2cAddr = 0b0100111;    // PCF8574's I2C address

void setup()
{
    pinMode(12, OUTPUT);
    I2C.master(I2C_100KHZ);             // or I2C.master(100);
}

void loop()
{
    I2C.start();                                // All I2C commands must begin with a Start condition

    I2C.send((i2cAddr << 1) & 0xFE);            // write operation (bit 0 set to 0)
    
    digitalWrite(USERLED, LOW);
    I2C.send(0b00000000);                       // set all bits of PCF8574 register to 0
    delay(500);                                 // wait for 500 ms
    
    digitalWrite(USERLED, HIGH);
    I2C.send(0b00000001);                       // set bit 0 of PCF8574 register to 1
    delay(500);                                 // wait for 500 ms

    I2C.stop();                                 // Terminate the write sequence
}