This commit is contained in:
Renzo Mischianti 2020-11-23 22:40:07 +01:00
commit 3f1a547c20

View File

@ -9,13 +9,13 @@
align="right"></a>
</div>
### Additional information and document update here on my site: [pcf8574 Article](https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/).
### Additional information and documentation on my site: [pcf8574 Article](https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/).
### If you need more pins [here](https://www.mischianti.org/2019/07/22/pcf8575-i2c-16-bit-digital-i-o-expander/) you can find pcf8575 16bit version of the IC.
### If you need more pins [here](https://www.mischianti.org/2019/07/22/pcf8575-i2c-16-bit-digital-i-o-expander/) you can find the pcf8575 16bit version of the IC.
### Version 2.2
Library to use i2c analog IC with arduino and esp8266. Can read and write digital value with only 2 wire (perfect for ESP-01).
Library to use I2C analog IC with arduino and esp8266. Can read and write digital value with only 2 wires (perfect for ESP-01).
Tutorial:
@ -25,17 +25,17 @@ To download. click the DOWNLOADS button in the top right corner, rename the unco
23/11/2020: v2.2.2 Add multiple implementation for encoder management (you can enable by uncomment relative define)
# Reef complete PCF8574 PCF8574AP digital input and output expander with i2c bus.
I try to simplify the use of this IC, with a minimal set of operation.
I try to simplify the use of this IC, with a minimal set of operations.
PCF8574P address map 0x20-0x27
PCF8574AP address map 0x38-0x3f
Constructor:
you must pas the address of i2c (to check the adress use this guide [I2cScanner](https://playground.arduino.cc/Main/I2cScanner))
**Constructor:**
Pass the address of I2C (to check the address use this guide [I2cScanner](https://playground.arduino.cc/Main/I2cScanner))
```cpp
PCF8574(uint8_t address);
```
for esp8266 if you want specify SDA e SCL pin use this:
For ESP8266 if you want to specify SDA and SCL pins use this:
```cpp
PCF8574(uint8_t address, uint8_t sda, uint8_t scl);
@ -47,11 +47,11 @@ You must set input/output mode:
pcf8574.pinMode(P2, INPUT);
```
then IC as you can see in the image have 8 digital input/output:
then IC as you can see in the image has 8 digital input/output ports:
![PCF8574 schema](https://github.com/xreef/PCF8574_library/blob/master/resources/PCF8574-pins.gif)
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):
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):
```cpp
PCF8574::DigitalInput di = PCF8574.digitalReadAll();
Serial.print(di.p0);
@ -63,13 +63,13 @@ So to read all analog input in one trasmission you can do (even if I use a 10mi
Serial.println(di.p3);
```
To follow a request (you can see It on [issue #5](https://github.com/xreef/PCF8574_library/issues/5)) I create a define variable to work with low memori device, if you decomment this line on .h file of the library:
To follow a request (you can see It on [issue #5](https://github.com/xreef/PCF8574_library/issues/5)) I create a define variable to work with low memory devices, if you uncomment this line in the .h file of the library:
```cpp
// #define PCF8574_LOW_MEMORY
```
Enable low memory props and gain about 7byte of memory, and you must use the method to read all like so:
Enable low memory props and gain about 7 bytes of memory, and you must use the method to read all like so:
```cpp
byte di = pcf8574.digitalReadAll();
@ -77,7 +77,7 @@ Enable low memory props and gain about 7byte of memory, and you must use the met
Serial.println(di, BIN);
```
where di is a byte like 1110001, so you must do a bitwise operation to get the data, operation that I already do in the "normal" mode, here an example:
where `di` is a byte like 1110001, so you must do a bitwise operation to get the data, operation that I already do in the "normal" mode. For example:
```cpp
p0 = ((di & bit(0))>0)?HIGH:LOW;
@ -91,13 +91,13 @@ where di is a byte like 1110001, so you must do a bitwise operation to get the d
```
if you want read a single input:
if you want to read a single input:
```cpp
int p1Digital = PCF8574.digitalRead(P1); // read P1
```
If you want write a digital value you must do:
If you want to write a digital value:
```cpp
PCF8574.digitalWrite(P1, HIGH);
```
@ -106,7 +106,7 @@ or:
PCF8574.digitalWrite(P1, LOW);
```
You can also use interrupt pin:
You can also use an interrupt pin:
You must initialize the pin and the function to call when interrupt raised from PCF8574
```cpp
// Function interrupt
@ -115,9 +115,9 @@ void keyPressedOnPCF8574();
// Set i2c address
PCF8574 pcf8574(0x39, ARDUINO_UNO_INTERRUPT_PIN, keyPressedOnPCF8574);
```
Remember you can't use Serial or Wire on interrupt function.
Remember you can't use Serial or Wire on an interrupt function.
The better way is to set only a variable to read on loop:
It's better to only set a variable to read on loop:
```cpp
void keyPressedOnPCF8574(){
// Interrupt called (No Serial no read no wire in this function, and DEBUG disabled on PCF library)