Home CodeMBed MBed and a PCF8574

MBed and a PCF8574

by shedboy71

The PCF8574 is an 8 bits I/O port expander that uses the I2C protocol. Using this IC, you can use only the SDA and SCL pins of your Arduino board to control up to 8 digital I/O ports.

A0,A1,A2 are address pins
P0,P1,P2,P3,P4,P5,P6,P7 are digital I/O ports
SDA,SCL are the I2C pins

pcf8574n_pinout

If we set pins A0 to A2 to GND, our device address in binary will be 0x20, thats exactly what I did in my example. To enable read and write there are different values required you can see these in the image below

pcf8574-address-map

 

Schematic

Note that the PCF8574 is a current sink device so you do not require the current limiting resistors

I have only shown 2 LEDs, also note that I have shown A0, A1 and A2 tied to GND, this is what my test module had selected.

mbed-and-pcf8574_schem

Code

This example flashes LEDs on and off

You will need to add the https://developer.mbed.org/users/simon/code/PCF8574/ library to your compiler, if you have signed up there is an Import to compiler button on the page,

[codesyntax lang=”cpp”]

#include "mbed.h"
#include "PCF8574.h"

PCF8574 io(p28,p27,0x40);

int main() {
 while(1) {
 io.write(0xAA);
 wait(0.5);
 io.write(0x55);
 wait(0.5);
 }
}

[/codesyntax]

 

Link
5PCS PCF8574P DIP-16 Remote 8-bit I/O Expander IC

Share

You may also like