PCF8574_library

AUTHOR
Version 0.9.0
Mon Nov 13 2017 

Table of Contents

Table of contents

Thermistor library
MIT license written by Renzo Mischianti 

README
Library to use i2c analog IC with arduino and esp8266. Can read and write digital value with only 2 wire (perfect for ESP-01).
Tutorial:
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder PCF8574. Check that the PCF8574 folder contains PCF8574\\.cpp  and PCF8574.h . Place the DHT library folder your <arduinosketchfolder>/libraries/  folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
 
I try to simplify the use of this IC, with a minimal set of operation.
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);

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

If you want write a digital value you must do: 
PCF8574.digitalWrite(P1, HIGH);
 or: 
PCF8574.digitalWrite(P1, LOW);

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);
 Remember you can't use Serial or Wire on interrupt function.
The better way is to set only a variable to read on loop: 
void keyPressedOnPCF8574(){
    // Interrupt called (No Serial no read no wire in this function, and DEBUG disabled on PCF library)
     keyPressed = true;
}

For the examples I use this wire schema on breadboard:  

Class Index
Class List
Here are the classes, structs, unions and interfaces with brief descriptions:
PCF8574::DigitalInput  	pagenum
PCF8574  	pagenum

File Index
File List
Here is a list of all files with brief descriptions:
PCF8574.cpp  	pagenum
PCF8574.h  	pagenum

Class Documentation
PCF8574::DigitalInput Struct Reference

#include <PCF8574.h>
Public Attributes
uint8_t p0
uint8_t p1
uint8_t p2
uint8_t p3
uint8_t p4
uint8_t p5
uint8_t p6
uint8_t p7

Member Data Documentation
uint8_t PCF8574::DigitalInput::p0
uint8_t PCF8574::DigitalInput::p1
uint8_t PCF8574::DigitalInput::p2
uint8_t PCF8574::DigitalInput::p3
uint8_t PCF8574::DigitalInput::p4
uint8_t PCF8574::DigitalInput::p5
uint8_t PCF8574::DigitalInput::p6
uint8_t PCF8574::DigitalInput::p7

The documentation for this struct was generated from the following file:
PCF8574.h

PCF8574 Class Reference

#include <PCF8574.h>
Classes
struct DigitalInput
Public Member Functions
PCF8574 (uint8_t address)
Constructor. 
PCF8574 (uint8_t address, uint8_t sda, uint8_t scl)
Constructor. 
PCF8574 (uint8_t address, uint8_t interruptPin, void(*interruptFunction)())
Construcor. 
PCF8574 (uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin, void(*interruptFunction)())
Constructor. 
void begin ()
wake up i2c controller 
void pinMode (uint8_t pin, uint8_t mode)
Set if fin is OUTPUT or INPUT. 
void readBuffer (bool force=true)
Read value from i2c and bufferize it. 
uint8_t digitalRead (uint8_t pin)
Read value of specified pin Debounce read more fast than 10millis, non managed for interrupt mode. 
DigitalInput digitalReadAll (void)
Read value of all INPUT pin Debounce read more fast than 10millis, non managed for interrupt mode. 
void digitalWrite (uint8_t pin, uint8_t value)
Write on pin. 
Public Attributes
struct PCF8574::DigitalInput digitalInput
Private Attributes
uint8_t _address
uint8_t _sda = SDA
uint8_t _scl = SCL
bool _usingInterrupt = false
uint8_t _interruptPin = 2
void(* _interruptFunction )()
byte writeMode = B00000000
byte readMode = B00000000
byte byteBuffered = B00000000
unsigned long lastReadMillis = 0
byte writeByteBuffered = B00000000

Constructor & Destructor Documentation
PCF8574::PCF8574 (uint8_t  address)

Constructor. 

Parameters:
address 	i2c address 	
PCF8574::PCF8574 (uint8_t  address, uint8_t  sda, uint8_t  scl)

Constructor. 

Parameters:
address 	i2c address 	
sda 	sda pin 	
scl 	scl pin 	
PCF8574::PCF8574 (uint8_t  address, uint8_t  interruptPin, void(*)()  interruptFunction)

Construcor. 

Parameters:
address 	i2c address 	
interruptPin 	pin to set interrupt 	
interruptFunction 	function to call when interrupt raised 	
PCF8574::PCF8574 (uint8_t  address, uint8_t  sda, uint8_t  scl, uint8_t  interruptPin, void(*)()  interruptFunction)

Constructor. 

Parameters:
address 	i2c address 	
sda 	sda pin 	
scl 	scl pin 	
interruptPin 	pin to set interrupt 	
interruptFunction 	function to call when interrupt raised 	

Member Function Documentation
void PCF8574::begin ()

wake up i2c controller 
uint8_t PCF8574::digitalRead (uint8_t  pin)

Read value of specified pin Debounce read more fast than 10millis, non managed for interrupt mode. 

Parameters:
pin 		
Returns:

PCF8574::DigitalInput PCF8574::digitalReadAll (void )

Read value of all INPUT pin Debounce read more fast than 10millis, non managed for interrupt mode. 

Returns:

void PCF8574::digitalWrite (uint8_t  pin, uint8_t  value)

Write on pin. 

Parameters:
pin 		
value 		
void PCF8574::pinMode (uint8_t  pin, uint8_t  mode)

Set if fin is OUTPUT or INPUT. 

Parameters:
pin 	pin to set 	
mode 	mode, supported only INPUT or OUTPUT (to semplify) 	
void PCF8574::readBuffer (bool  force = true)

Read value from i2c and bufferize it. 

Parameters:
force 		

Member Data Documentation
uint8_t PCF8574::_address[private]
void(* PCF8574::_interruptFunction) ()[inline], [private]
uint8_t PCF8574::_interruptPin = 2[private]
uint8_t PCF8574::_scl = SCL[private]
uint8_t PCF8574::_sda = SDA[private]
bool PCF8574::_usingInterrupt = false[private]
byte PCF8574::byteBuffered = B00000000[private]
struct PCF8574::DigitalInput  PCF8574::digitalInput
unsigned long PCF8574::lastReadMillis = 0[private]
byte PCF8574::readMode = B00000000[private]
byte PCF8574::writeByteBuffered = B00000000[private]
byte PCF8574::writeMode = B00000000[private]

The documentation for this class was generated from the following files:
PCF8574.h
PCF8574.cpp

File Documentation
PCF8574.cpp File Reference
#include "PCF8574.h"
#include "Wire.h"

PCF8574.h File Reference
#include "Wire.h"
#include "WProgram.h"
#include <math.h>
Classes
class PCF8574
struct PCF8574::DigitalInput
Macros
#define DEBUG_PRINTER  Serial
#define DEBUG_PRINT(...)  {}
#define DEBUG_PRINTLN(...)  {}
#define READ_ELAPSED_TIME  10
#define P0  0
#define P1  1
#define P2  2
#define P3  3
#define P4  4
#define P5  5
#define P6  6
#define P7  7

Macro Definition Documentation
#define DEBUG_PRINT(  ...)  {}
#define DEBUG_PRINTER  Serial
#define DEBUG_PRINTLN(  ...)  {}
#define P0  0
#define P1  1
#define P2  2
#define P3  3
#define P4  4
#define P5  5
#define P6  6
#define P7  7
#define READ_ELAPSED_TIME  10

README.md File Reference

Index
INDEX