[go: up one dir, main page]

0% found this document useful (0 votes)
15 views4 pages

PCF8574 I2c Digital IO Expander Fast Easy Usage

The document describes a library for using the PCF8574 I2C digital I/O expander IC. It allows reading and writing digital values with only 2 wires. The library simplifies using the IC with minimal operations like reading/writing single pins or all pins, and setting pin modes. Examples are provided for wiring, usage, and reading/writing values.

Uploaded by

Anatolia Medya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

PCF8574 I2c Digital IO Expander Fast Easy Usage

The document describes a library for using the PCF8574 I2C digital I/O expander IC. It allows reading and writing digital values with only 2 wires. The library simplifies using the IC with minimal operations like reading/writing single pins or all pins, and setting pin modes. Examples are provided for wiring, usage, and reading/writing values.

Uploaded by

Anatolia Medya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

instructables

PCF8574 (i2c Digital I/O Expander) Fast Easy Usage

by xxreef

Library to use i2c analog IC with arduino and esp8266.

Can read and write digital value with only 2 wire (perfect for ESP-01).

I try to simplify the use of this IC, with a minimal set of operation.

PCF8574 (i2c Digital I/O Expander) Fast Easy Usage: Page 1


Step 1: Library

You can find my library here. Place the PCF8574 library folder your /libraries/
folder.
To download.
You may need to create the libraries subfolder if its
Click the DOWNLOADS button in the top right corner, your first library.
rename the uncompressed folder PCF8574.
Restart the IDE.
Check that the PCF8574 folder contains
PCF8574.cpp and PCF8574.h.

Step 2: Usage

Constructor: you must pas the address of i2c (to check the adress use this guide I2cScanner)

PCF8574(uint8_t address);

for esp8266 if you want specify SDA e SCL pin use this:

PCF8574(uint8_t address, uint8_t sda, uint8_t scl);

You must set input/output mode:

pcf8574.pinMode(P0, OUTPUT);
pcf8574.pinMode(P1, INPUT);
pcf8574.pinMode(P2, INPUT);

PCF8574 (i2c Digital I/O Expander) Fast Easy Usage: Page 2


Step 3: Read Value

then IC as you can see in the image have 8 digital input/output:

So to read all analog input in one trasmission you can do (even if I use a 10millis debounce time to prevent too
much read from i2c):

PCF8574::DigitalInput di = PCF8574.digitalReadAll(); Serial.print(di.p0);


Serial.print(" - ");
Serial.print(di.p1);
Serial.print(" - ");
Serial.print(di.p2);
Serial.print(" - ");
Serial.println(di.p3);

if you want read a single input:

int p1Digital = PCF8574.digitalRead(P1); // read P1

Step 4: Write Value

If you want write a digital value you must do:

PCF8574.digitalWrite(P1, HIGH);

or:

PCF8574.digitalWrite(P1, LOW);

PCF8574 (i2c Digital I/O Expander) Fast Easy Usage: Page 3


Step 5: Interrupt Pin

You can also use interrupt pin: You must initialize the pin and the function to call when interrupt raised from
PCF8574.

// Function interrupt
void keyPressedOnPCF8574();

// Set i2c address


PCF8574 pcf8574(0x39, ARDUINO_UNO_INTERRUPT_PIN, keyPressedOnPCF8574);

Step 6: Examples Wiring Diagram

Step 7: Thanks

PCF8574 (i2c Digital I/O Expander) Fast Easy Usage: Page 4

You might also like