Pcf8574-Gpio-Extender-Lib is for supporing multiple Pcf8574 boards together
in chain with less complexcity of the programming
mex we can connect 8 Pcf8574 together in chain which will give extra 64 pins for operations
this api support a simple interface where we can controll 1-64 pins by its sequence number
respected to their sequence in the chain
pin number will start from 1 to (number of board X 8 pin per board)
NOTE: pcf8574 work on different logic so when pin is low by current then its on and when pin is high then its off
but that is taken care by on off api already
NOTE: Order of Pcf8574 board address wise must be in sequence otherwise it will not work in expected manner
Connect Details
we have connect the sda and scl from arduino to Pcf8574 board
+5v vcc and gnd pin from arduino to Pcf8574 board
then connect the device on pin po to p7 for controlling them
use the vcc of the last board for powering up the device
for different adddress configuation we have to set the jumper of Pcf8574 board like shown in the above image
and we can set 8 boareds with 0x21 to 0x27 addressing with 8pin in each board
#include "Pcf8574.h"
#include "Pcf8574Board.h"
Pcf8574Board pcf8574Board;
#define NO_OF_BOARDS 8
.......
pcf8574Board.initPcf8574Boards(NO_OF_BOARDS);
........
void setup() {
Serial.begin(xxxx); // xxx can be any valid supported number
.........
}
switchOn(pinNo) will take the pin number 1 to ( no of boards X 8 ) in chain sequence
void loop() {
.......
pcf8574Board.switchOn(pinNo); // pinNo is the sequence value of the pin in Pcf8574 chain starting from 0 to (8 x number of board) in chain
..........
}
### use lib method for pin off
* switchOff(pinNo) will take the pin number 1 to ( no of boards X 8 ) in chain sequence
void loop() {
.......
pcf8574Board.switchOff(pinNo); // pinNo is the sequence value of the pin in Pcf8574 chain starting from 0 to (8 x number of board) in chain
.......... }
## Complete Example
Pcf8574Board pcf8574Board; int MAX_PINS = 0;
void setup() { Serial.begin(9600); pcf8574Board.initPcf8574Boards(NO_OF_BOARDS); MAX_PINS = NO_OF_BOARDS * 8; }
void loop() { int pinNo = random(0, MAX_PINS); Serial.print("MAX PIN "); Serial.println(MAX_PINS); Serial.print("PIN NO "); Serial.println(pinNo); delay(1000); pcf8574Board.switchOn(pinNo); pcf8574Board.displayPinState(); delay(1000); pcf8574Board.switchOff(pinNo); pcf8574Board.displayPinState(); delay(1000); }