Initial commit

This commit is contained in:
2026-03-31 13:17:21 +02:00
commit 7eeecff042
6821 changed files with 3514215 additions and 0 deletions

View File

@@ -0,0 +1 @@
resources export-ignore

View File

@@ -0,0 +1 @@
{"type": "library", "name": "PCF8575 library", "version": "1.1.0", "spec": {"owner": "xreef", "id": 11372, "name": "PCF8575 library", "requirements": null, "uri": null}}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PCF8575_library</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Renzo Mischianti
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,24 @@
The MIT License (MIT)
Copyright (c) 2017 Renzo Mischianti www.mischianti.org All right reserved.
You may copy, alter and reuse this code in any way you like, but please leave
reference to www.mischianti.org in your comments if you redistribute this code.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,486 @@
/*
* PCF8575 GPIO Port Expand
* https://www.mischianti.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Renzo Mischianti www.mischianti.org All right reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "PCF8575.h"
#include "Wire.h"
/**
* Constructor
* @param address: i2c address
*/
PCF8575::PCF8575(uint8_t address){
_wire = &Wire;
_address = address;
};
/**
* Construcor
* @param address: i2c address
* @param interruptPin: pin to set interrupt
* @param interruptFunction: function to call when interrupt raised
*/
PCF8575::PCF8575(uint8_t address, uint8_t interruptPin, void (*interruptFunction)() ){
_wire = &Wire;
_address = address;
_interruptPin = interruptPin;
_interruptFunction = interruptFunction;
_usingInterrupt = true;
};
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(TEENSYDUINO)
/**
* Constructor
* @param address: i2c address
* @param sda: sda pin
* @param scl: scl pin
*/
PCF8575::PCF8575(uint8_t address, int sda, int scl){
_wire = &Wire;
_address = address;
_sda = sda;
_scl = scl;
};
/**
* Constructor
* @param address: i2c address
* @param sda: sda pin
* @param scl: scl pin
* @param interruptPin: pin to set interrupt
* @param interruptFunction: function to call when interrupt raised
*/
PCF8575::PCF8575(uint8_t address, int sda, int scl, uint8_t interruptPin, void (*interruptFunction)() ){
_wire = &Wire;
_address = address;
_sda = sda;
_scl = scl;
_interruptPin = interruptPin;
_interruptFunction = interruptFunction;
_usingInterrupt = true;
};
#endif
#if defined(ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32)
/**
* Constructor
* @param address: i2c address
*/
PCF8575::PCF8575(TwoWire *pWire, uint8_t address){
_wire = pWire;
_address = address;
};
/**
* Construcor
* @param address: i2c address
* @param interruptPin: pin to set interrupt
* @param interruptFunction: function to call when interrupt raised
*/
PCF8575::PCF8575(TwoWire *pWire, uint8_t address, uint8_t interruptPin, void (*interruptFunction)() ){
_wire = pWire;
_address = address;
_interruptPin = interruptPin;
_interruptFunction = interruptFunction;
_usingInterrupt = true;
};
#endif
#if defined(ESP32)
/**
* Constructor
* @param address: i2c address
* @param sda: sda pin
* @param scl: scl pin
*/
PCF8575::PCF8575(TwoWire *pWire, uint8_t address, int sda, int scl){
_wire = pWire;
_address = address;
_sda = sda;
_scl = scl;
};
/**
* Constructor
* @param address: i2c address
* @param sda: sda pin
* @param scl: scl pin
* @param interruptPin: pin to set interrupt
* @param interruptFunction: function to call when interrupt raised
*/
PCF8575::PCF8575(TwoWire *pWire, uint8_t address, int sda, int scl, uint8_t interruptPin, void (*interruptFunction)() ){
_wire = pWire;
_address = address;
_sda = sda;
_scl = scl;
_interruptPin = interruptPin;
_interruptFunction = interruptFunction;
_usingInterrupt = true;
};
#endif
/**
* wake up i2c controller
*/
void PCF8575::begin(){
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(TEENSYDUINO)
DEBUG_PRINT(F("begin(sda, scl) -> "));DEBUG_PRINT(_sda);DEBUG_PRINT(F(" "));DEBUG_PRINTLN(_scl);
// _wire->begin(_sda, _scl);
#ifdef ARDUINO_ARCH_STM32
_wire->begin((uint32_t)_sda, (uint32_t)_scl);
#elif defined(ARDUINO_ARCH_RP2040)
_wire->setSCL(_scl);
_wire->setSDA(_sda);
_wire->begin();
#else
_wire->begin((int)_sda, (int)_scl);
#endif
#else
// Default pin for AVR some problem on software emulation
// #define SCL_PIN _scl
// #define SDA_PIN _sda
_wire->begin();
#endif
// Serial.println( writeMode, BIN);
// Serial.println( readMode, BIN);
// Check if there are pins to set low
if (writeMode>0 || readMode>0){
DEBUG_PRINTLN("Set write mode");
_wire->beginTransmission(_address);
DEBUG_PRINT(" ");
DEBUG_PRINT("usedPin pin ");
uint16_t usedPin = writeMode | readMode;
DEBUG_PRINTLN( ~usedPin, BIN);
// Serial.println( ~usedPin, BIN);
_wire->write((uint8_t) ~usedPin);
_wire->write((uint8_t) (~(usedPin >> 8)));
DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");
_wire->endTransmission();
}
// If using interrupt set interrupt value to pin
if (_usingInterrupt){
DEBUG_PRINTLN("Using interrupt pin (not all pin is interrupted)");
::pinMode(_interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(_interruptPin), (*_interruptFunction), FALLING );
}
// inizialize last read
lastReadMillis = millis();
}
/**
* Set if fin is OUTPUT or INPUT
* @param pin: pin to set
* @param mode: mode, supported only INPUT or OUTPUT (to semplify)
*/
void PCF8575::pinMode(uint8_t pin, uint8_t mode){
DEBUG_PRINT("Set pin ");
DEBUG_PRINT(pin);
DEBUG_PRINT(" as ");
DEBUG_PRINTLN(mode);
if (mode == OUTPUT){
writeMode = writeMode | bit(pin);
readMode = readMode & ~bit(pin);
// DEBUG_PRINT("writeMode: ");
// DEBUG_PRINT(writeMode, BIN);
// DEBUG_PRINT("readMode: ");
// DEBUG_PRINTLN(readMode, BIN);
}else if (mode == INPUT){
writeMode = writeMode & ~bit(pin);
readMode = readMode | bit(pin);
// DEBUG_PRINT("writeMode: ");
// DEBUG_PRINT(writeMode, BIN);
// DEBUG_PRINT("readMode: ");
// DEBUG_PRINTLN(readMode, BIN);
}
else{
DEBUG_PRINTLN("Mode non supported by PCF8575")
}
DEBUG_PRINT("Write mode: ");
DEBUG_PRINTLN(writeMode, BIN);
};
/**
* Read value from i2c and bufferize it
* @param force
*/
void PCF8575::readBuffer(bool force){
if (millis() > PCF8575::lastReadMillis+READ_ELAPSED_TIME || _usingInterrupt || force){
_wire->requestFrom(_address,(uint8_t)2);// Begin transmission to PCF8575 with the buttons
lastReadMillis = millis();
if(_wire->available()) // If uint16_ts are available to be recieved
{
uint16_t iInput = _wire->read();// Read a uint16_t
iInput |= _wire->read() << 8;// Read a uint16_t
if ((iInput & readMode)>0){
byteBuffered = byteBuffered | (uint16_t)iInput;
}
}
}
}
#ifndef PCF8575_LOW_MEMORY
/**
* Read value of all INPUT pin
* Debounce read more fast than 10millis, non managed for interrupt mode
* @return
*/
PCF8575::DigitalInput PCF8575::digitalReadAll(void){
DEBUG_PRINTLN("Read from buffer");
_wire->requestFrom(_address,(uint8_t)2);// Begin transmission to PCF8575 with the buttons
lastReadMillis = millis();
if(_wire->available()) // If uint16_ts are available to be recieved
{
DEBUG_PRINTLN("Data ready");
uint16_t iInput = _wire->read();// Read a uint16_t
iInput |= _wire->read() << 8;// Read a uint16_t
if ((iInput & readMode)>0){
DEBUG_PRINT("Input ");
DEBUG_PRINTLN((uint16_t)iInput, BIN);
byteBuffered = byteBuffered | (uint16_t)iInput;
DEBUG_PRINT("byteBuffered ");
DEBUG_PRINTLN(byteBuffered, BIN);
}
}
DEBUG_PRINT("Buffer value ");
DEBUG_PRINTLN(byteBuffered, BIN);
#ifdef NOT_SEQUENTIAL_PINOUT
if ((bit(0) & readMode)>0) digitalInput.p00 = ((byteBuffered & bit(0))>0)?HIGH:LOW;
if ((bit(1) & readMode)>0) digitalInput.p01 = ((byteBuffered & bit(1))>0)?HIGH:LOW;
if ((bit(2) & readMode)>0) digitalInput.p02 = ((byteBuffered & bit(2))>0)?HIGH:LOW;
if ((bit(3) & readMode)>0) digitalInput.p03 = ((byteBuffered & bit(3))>0)?HIGH:LOW;
if ((bit(4) & readMode)>0) digitalInput.p04 = ((byteBuffered & bit(4))>0)?HIGH:LOW;
if ((bit(5) & readMode)>0) digitalInput.p05 = ((byteBuffered & bit(5))>0)?HIGH:LOW;
if ((bit(6) & readMode)>0) digitalInput.p06 = ((byteBuffered & bit(6))>0)?HIGH:LOW;
if ((bit(7) & readMode)>0) digitalInput.p07 = ((byteBuffered & bit(7))>0)?HIGH:LOW;
if ((bit(8) & readMode)>0) digitalInput.p10 = ((byteBuffered & bit(8))>0)?HIGH:LOW;
if ((bit(9) & readMode)>0) digitalInput.p11 = ((byteBuffered & bit(9))>0)?HIGH:LOW;
if ((bit(10) & readMode)>0) digitalInput.p12 = ((byteBuffered & bit(10))>0)?HIGH:LOW;
if ((bit(11) & readMode)>0) digitalInput.p13 = ((byteBuffered & bit(11))>0)?HIGH:LOW;
if ((bit(12) & readMode)>0) digitalInput.p14 = ((byteBuffered & bit(12))>0)?HIGH:LOW;
if ((bit(13) & readMode)>0) digitalInput.p15 = ((byteBuffered & bit(13))>0)?HIGH:LOW;
if ((bit(14) & readMode)>0) digitalInput.p16 = ((byteBuffered & bit(14))>0)?HIGH:LOW;
if ((bit(15) & readMode)>0) digitalInput.p17 = ((byteBuffered & bit(15))>0)?HIGH:LOW;
#else
if ((bit(0) & readMode)>0) digitalInput.p0 = ((byteBuffered & bit(0))>0)?HIGH:LOW;
if ((bit(1) & readMode)>0) digitalInput.p1 = ((byteBuffered & bit(1))>0)?HIGH:LOW;
if ((bit(2) & readMode)>0) digitalInput.p2 = ((byteBuffered & bit(2))>0)?HIGH:LOW;
if ((bit(3) & readMode)>0) digitalInput.p3 = ((byteBuffered & bit(3))>0)?HIGH:LOW;
if ((bit(4) & readMode)>0) digitalInput.p4 = ((byteBuffered & bit(4))>0)?HIGH:LOW;
if ((bit(5) & readMode)>0) digitalInput.p5 = ((byteBuffered & bit(5))>0)?HIGH:LOW;
if ((bit(6) & readMode)>0) digitalInput.p6 = ((byteBuffered & bit(6))>0)?HIGH:LOW;
if ((bit(7) & readMode)>0) digitalInput.p7 = ((byteBuffered & bit(7))>0)?HIGH:LOW;
if ((bit(8) & readMode)>0) digitalInput.p8 = ((byteBuffered & bit(8))>0)?HIGH:LOW;
if ((bit(9) & readMode)>0) digitalInput.p9 = ((byteBuffered & bit(9))>0)?HIGH:LOW;
if ((bit(10) & readMode)>0) digitalInput.p10 = ((byteBuffered & bit(10))>0)?HIGH:LOW;
if ((bit(11) & readMode)>0) digitalInput.p11 = ((byteBuffered & bit(11))>0)?HIGH:LOW;
if ((bit(12) & readMode)>0) digitalInput.p12 = ((byteBuffered & bit(12))>0)?HIGH:LOW;
if ((bit(13) & readMode)>0) digitalInput.p13 = ((byteBuffered & bit(13))>0)?HIGH:LOW;
if ((bit(14) & readMode)>0) digitalInput.p14 = ((byteBuffered & bit(14))>0)?HIGH:LOW;
if ((bit(15) & readMode)>0) digitalInput.p15 = ((byteBuffered & bit(15))>0)?HIGH:LOW;
#endif
if ((readMode & byteBuffered)>0){
byteBuffered = ~readMode & byteBuffered;
DEBUG_PRINT("Buffer hight value readed set readed ");
DEBUG_PRINTLN(byteBuffered, BIN);
}
DEBUG_PRINT("Return value ");
return digitalInput;
};
#else
/**
* Read value of all INPUT pin in byte format for low memory usage
* Debounce read more fast than 10millis, non managed for interrupt mode
* @return
*/
uint16_t PCF8575::digitalReadAll(void){
DEBUG_PRINTLN("Read from buffer");
_wire->requestFrom(_address,(uint8_t)2);// Begin transmission to PCF8575 with the buttons
lastReadMillis = millis();
if(_wire->available()) // If uint16_ts are available to be recieved
{
DEBUG_PRINTLN("Data ready");
uint16_t iInput = _wire->read();// Read a uint16_t
iInput |= _wire->read() << 8;// Read a uint16_t
if ((iInput & readMode)>0){
DEBUG_PRINT("Input ");
DEBUG_PRINTLN((uint16_t)iInput, BIN);
byteBuffered = byteBuffered | (uint16_t)iInput;
DEBUG_PRINT("byteBuffered ");
DEBUG_PRINTLN(byteBuffered, BIN);
}
}
DEBUG_PRINT("Buffer value ");
DEBUG_PRINTLN(byteBuffered, BIN);
uint16_t byteRead = byteBuffered;
if ((readMode & byteBuffered)>0){
byteBuffered = ~readMode & byteBuffered;
DEBUG_PRINT("Buffer hight value readed set readed ");
DEBUG_PRINTLN(byteBuffered, BIN);
}
DEBUG_PRINT("Return value ");
return byteRead;
};
#endif
/**
* Read value of specified pin
* Debounce read more fast than 10millis, non managed for interrupt mode
* @param pin
* @return
*/
uint8_t PCF8575::digitalRead(uint8_t pin){
uint8_t value = LOW;
if ((bit(pin) & writeMode)>0){
DEBUG_PRINTLN("Pin in write mode, return value");
DEBUG_PRINT("Write data ");
DEBUG_PRINT(writeByteBuffered, BIN);
DEBUG_PRINT(" for pin ");
DEBUG_PRINT(pin);
DEBUG_PRINT(" bin value ");
DEBUG_PRINT(bit(pin), BIN);
DEBUG_PRINT(" value ");
DEBUG_PRINTLN(value);
if ((bit(pin) & writeByteBuffered)>0){
value = HIGH;
}else{
value = LOW;
}
return value;
}
DEBUG_PRINT("Read pin ");
DEBUG_PRINTLN(pin);
// Check if pin already HIGH than read and prevent reread of i2c
if ((bit(pin) & byteBuffered)>0){
DEBUG_PRINTLN("Pin already up");
value = HIGH;
}else if ((/*(bit(pin) & byteBuffered)<=0 && */millis() > PCF8575::lastReadMillis+READ_ELAPSED_TIME) /*|| _usingInterrupt*/){
DEBUG_PRINTLN("Read from buffer");
_wire->requestFrom(_address,(uint8_t)2);// Begin transmission to PCF8575 with the buttons
lastReadMillis = millis();
if(_wire->available()) // If bytes are available to be recieved
{
DEBUG_PRINTLN("Data ready");
uint16_t iInput = _wire->read();// Read a uint16_t
iInput |= _wire->read() << 8;// Read a uint16_t
// Serial.println(iInput, BIN);
if ((iInput & readMode)>0){
DEBUG_PRINT("Input ");
DEBUG_PRINTLN((uint16_t)iInput, BIN);
byteBuffered = byteBuffered | (uint16_t)iInput;
DEBUG_PRINT("byteBuffered ");
DEBUG_PRINTLN(byteBuffered, BIN);
if ((bit(pin) & byteBuffered)>0){
value = HIGH;
}
}
}
}
DEBUG_PRINT("Buffer value ");
DEBUG_PRINTLN(byteBuffered, BIN);
// If HIGH set to low to read buffer only one time
if (value==HIGH){
byteBuffered = ~bit(pin) & byteBuffered;
DEBUG_PRINT("Buffer hight value readed set readed ");
DEBUG_PRINTLN(byteBuffered, BIN);
}
DEBUG_PRINT("Return value ");
DEBUG_PRINTLN(value);
return value;
};
/**
* Write on pin
* @param pin
* @param value
*/
void PCF8575::digitalWrite(uint8_t pin, uint8_t value){
DEBUG_PRINTLN("Begin trasmission");
_wire->beginTransmission(_address); //Begin the transmission to PCF8575
if (value==HIGH){
writeByteBuffered = writeByteBuffered | bit(pin);
}else{
writeByteBuffered = writeByteBuffered & ~bit(pin);
}
// DEBUG_PRINT("Write data ");
// DEBUG_PRINT(writeByteBuffered, BIN);
// DEBUG_PRINT(" for pin ");
// DEBUG_PRINT(pin);
// DEBUG_PRINT(" bin value ");
// DEBUG_PRINT(bit(pin), BIN);
// DEBUG_PRINT(" value ");
// DEBUG_PRINTLN(value);
// Serial.print(" --> ");
// Serial.println(writeByteBuffered);
// Serial.println((uint8_t) writeByteBuffered);
// Serial.println((uint8_t) (writeByteBuffered >> 8));
writeByteBuffered = writeByteBuffered & writeMode;
_wire->write((uint8_t) writeByteBuffered);
_wire->write((uint8_t) (writeByteBuffered >> 8));
DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");
_wire->endTransmission();
};

View File

@@ -0,0 +1,230 @@
/*
* PCF8575 GPIO Port Expand
* https://www.mischianti.org/2019/07/22/pcf8575-i2c-16-bit-digital-i-o-expander/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Renzo Mischianti www.mischianti.org All right reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef PCF8575_h
#define PCF8575_h
#include "Wire.h"
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define DEFAULT_SDA SDA;
#define DEFAULT_SCL SCL;
// Uncomment to enable printing out nice debug messages.
// #define PCF8575_DEBUG
// Uncomment for low memory usage this prevent use of complex DigitalInput structure and free 7byte of memory
// #define PCF8575_LOW_MEMORY
// Define where debug output will be printed.
#define DEBUG_PRINTER Serial
// Define to manage original pinout of pcf8575
// like datasheet but not sequential
//#define NOT_SEQUENTIAL_PINOUT
// Setup debug printing macros.
#ifdef PCF8575_DEBUG
#define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
#define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
#else
#define DEBUG_PRINT(...) {}
#define DEBUG_PRINTLN(...) {}
#endif
#define READ_ELAPSED_TIME 10
//#define P0 B00000001
//#define P1 B00000010
//#define P2 B00000100
//#define P3 B00001000
//#define P4 B00010000
//#define P5 B00100000
//#define P6 B01000000
//#define P7 B10000000
//
#ifdef NOT_SEQUENTIAL_PINOUT
#define P00 0
#define P01 1
#define P02 2
#define P03 3
#define P04 4
#define P05 5
#define P06 6
#define P07 7
#define P10 8
#define P11 9
#define P12 10
#define P13 11
#define P14 12
#define P15 13
#define P16 14
#define P17 15
#else
#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 P8 8
#define P9 9
#define P10 10
#define P11 11
#define P12 12
#define P13 13
#define P14 14
#define P15 15
#endif
#include <math.h>
class PCF8575 {
public:
PCF8575(uint8_t address);
PCF8575(uint8_t address, uint8_t interruptPin, void (*interruptFunction)() );
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(TEENSYDUINO)
PCF8575(uint8_t address, int sda, int scl);
PCF8575(uint8_t address, int sda, int scl, uint8_t interruptPin, void (*interruptFunction)());
#endif
#if defined(ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32)
///// changes for second i2c bus
PCF8575(TwoWire *pWire, uint8_t address);
PCF8575(TwoWire *pWire, uint8_t address, uint8_t interruptPin, void (*interruptFunction)() );
#endif
#if defined(ESP32)
PCF8575(TwoWire *pWire, uint8_t address, int sda, int scl);
PCF8575(TwoWire *pWire, uint8_t address, int sda, int scl, uint8_t interruptPin, void (*interruptFunction)());
#endif
void begin();
void pinMode(uint8_t pin, uint8_t mode);
void readBuffer(bool force = true);
uint8_t digitalRead(uint8_t pin);
#ifndef PCF8575_LOW_MEMORY
struct DigitalInput {
#ifdef NOT_SEQUENTIAL_PINOUT
uint8_t p00;
uint8_t p01;
uint8_t p02;
uint8_t p03;
uint8_t p04;
uint8_t p05;
uint8_t p06;
uint8_t p07;
uint8_t p10;
uint8_t p11;
uint8_t p12;
uint8_t p13;
uint8_t p14;
uint8_t p15;
uint8_t p16;
uint8_t p17;
#else
uint8_t p0;
uint8_t p1;
uint8_t p2;
uint8_t p3;
uint8_t p4;
uint8_t p5;
uint8_t p6;
uint8_t p7;
uint8_t p8;
uint8_t p9;
uint8_t p10;
uint8_t p11;
uint8_t p12;
uint8_t p13;
uint8_t p14;
uint8_t p15;
#endif
} digitalInput;
DigitalInput digitalReadAll(void);
#else
uint16_t digitalReadAll(void);
#endif
void digitalWrite(uint8_t pin, uint8_t value);
private:
uint8_t _address;
#if !defined(DEFAULT_SDA)
# if defined(ARDUINO_ARCH_STM32)
# define DEFAULT_SDA PB7
# elif defined(ESP8266)
# define DEFAULT_SDA 4
# elif defined(SDA)
# define DEFAULT_SDA SDA
# else
# error "Error define DEFAULT_SDA, SDA not declared, if you have this error contact the mantainer"
# endif
#endif
#if !defined(DEFAULT_SCL)
# if defined(ARDUINO_ARCH_STM32)
# define DEFAULT_SCL PB6
# elif defined(ESP8266)
# define DEFAULT_SCL 5
# elif defined(SDA)
# define DEFAULT_SCL SCL
# else
# error "Error define DEFAULT_SCL, SCL not declared, if you have this error contact the mantainer"
# endif
#endif
int _sda = DEFAULT_SDA;
int _scl = DEFAULT_SCL;
TwoWire *_wire;
bool _usingInterrupt = false;
uint8_t _interruptPin = 2;
void (*_interruptFunction)(){};
uint16_t writeMode = 0;
uint16_t readMode = 0;
uint16_t byteBuffered = 0;
unsigned long lastReadMillis = 0;
uint16_t writeByteBuffered = 0;
};
#endif

View File

@@ -0,0 +1,35 @@
/*
* PCF8575 GPIO Port Expand
* https://www.mischianti.org/2019/07/22/pcf8575-i2c-16-bit-digital-i-o-expander/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Renzo Mischianti www.mischianti.org All right reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef PCF8575_LIBRARY_H
#define PCF8575_LIBRARY_H
#include "PCF8575.h"
#endif
#pragma once

View File

@@ -0,0 +1,132 @@
<div>
<a href="https://www.mischianti.org/forums/forum/mischiantis-libraries/pcf8575-16bits-i2c-digital-i-o-expander/"><img
src="https://github.com/xreef/LoRa_E32_Series_Library/raw/master/resources/buttonSupportForumEnglish.png" alt="Support forum pcf8575 English"
align="right"></a>
</div>
<div>
<a href="https://www.mischianti.org/it/forums/forum/le-librerie-di-mischianti/pcf8575-expander-digitale-i-o-i2c-a-16bits/"><img
src="https://github.com/xreef/LoRa_E32_Series_Library/raw/master/resources/buttonSupportForumItaliano.png" alt="Forum supporto pcf8575 italiano"
align="right"></a>
</div>
###Additional information and document update here on my site: [pcf8575 Article](https://www.mischianti.org/2019/07/22/pcf8575-i2c-16-bit-digital-i-o-expander/).
###If you need less pins [here](https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/) you can find pcf8574 discrete 8bit version of the IC.
Library to use i2c analog IC with arduino and esp8266. Can read and write digital value with only 2 wire (perfect for ESP-01).
- 16/02/2023: v1.1.0
- Fix STM32 support and add support for Raspberry Pi Pico and other rp2040 boards
- Add support for custom SERCOM interface of Arduino SAMD devices. Force SDA SCL to use GPIO numeration for STM32 bug (https://www.mischianti.org/forums/topic/compatible-with-stm32duino/).
- Force SDA SCL to use GPIO numeration (https://www.mischianti.org/forums/topic/cannot-set-sda-clk-on-esp8266/).
- Fix the SDA SCL type #58 and add basic support for SAMD device.
- 06/04/2022: v1.0.3 Fix package size
Tutorial:
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder PCF8575. Check that the PCF8575 folder contains `PCF8575\\.cpp` and `PCF8575.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.
# Reef complete PCF8575 PCF8575AP digital input and output expander with i2c bus.
I try to simplify the use of this IC, with a minimal set of operation.
PCF8575 address map 0x20 default
Constructor:
you must pas the address of i2c (to check the adress use this guide [I2cScanner](https://playground.arduino.cc/Main/I2cScanner))
```cpp
PCF8575(uint8_t address);
```
for esp8266 if you want specify SDA e SCL pin use this:
```cpp
PCF8575(uint8_t address, uint8_t sda, uint8_t scl);
```
You must set input/output mode:
```cpp
pcf8575.pinMode(P0, OUTPUT);
pcf8575.pinMode(P1, INPUT);
pcf8575.pinMode(P2, INPUT);
```
then IC as you can see in the image have 8 digital input/output:
![PCF8575 schema](https://github.com/xreef/PCF8575_library/blob/master/resources/PCF8575-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):
```cpp
PCF8575::DigitalInput di = PCF8575.digitalReadAll();
Serial.print(di.p0);
Serial.print(" - ");
Serial.print(di.p1);
Serial.print(" - ");
Serial.print(di.p2);
Serial.print(" - ");
Serial.println(di.p3);
```
To follow a request (you can see It on [issue #5](https://github.com/xreef/PCF8575_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:
```cpp
// #define PCF8575_LOW_MEMORY
```
Enable low memory props and gain about 7byte of memory, and you must use the method to read all like so:
```cpp
byte di = pcf8575.digitalReadAll();
Serial.print("READ VALUE FROM PCF: ");
Serial.println(di, BIN);
```
where di is a byte like 11100011110001, so you must do a bitwise operation to get the data, operation that I already do in the "normal" mode, here an example:
```cpp
p0 = ((di & bit(0))>0)?HIGH:LOW;
p1 = ((di & bit(1))>0)?HIGH:LOW;
p2 = ((di & bit(2))>0)?HIGH:LOW;
p3 = ((di & bit(3))>0)?HIGH:LOW;
p4 = ((di & bit(4))>0)?HIGH:LOW;
p5 = ((di & bit(5))>0)?HIGH:LOW;
p6 = ((di & bit(6))>0)?HIGH:LOW;
p7 = ((di & bit(7))>0)?HIGH:LOW;
```
if you want read a single input:
```cpp
int p1Digital = PCF8575.digitalRead(P1); // read P1
```
If you want write a digital value you must do:
```cpp
PCF8575.digitalWrite(P1, HIGH);
```
or:
```cpp
PCF8575.digitalWrite(P1, LOW);
```
You can also use interrupt pin:
You must initialize the pin and the function to call when interrupt raised from PCF8575
```cpp
// Function interrupt
void keyPressedOnPCF8575();
// Set i2c address
PCF8575 pcf8575(0x39, ARDUINO_UNO_INTERRUPT_PIN, keyPressedOnPCF8575);
```
Remember you can't use Serial or Wire on interrupt function.
The better way is to set only a variable to read on loop:
```cpp
void keyPressedOnPCF8575(){
// 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:
![Breadboard](https://github.com/xreef/PCF8575_library/raw/master/resources/testReadWriteLedButton_bb.png)
[![Test pcf8575](https://img.youtube.com/vi/jWeHzBLeN6s/0.jpg)](https://youtu.be/jWeHzBLeN6s "Test pcf8575")

View File

@@ -0,0 +1,30 @@
/*
Blink led on PIN0
by Mischianti Renzo <http://www.mischianti.org>
https://www.mischianti.org/2019/01/02/pcf8575-i2c-digital-i-o-expander-fast-easy-usage/
*/
#include "Arduino.h"
#include "PCF8575.h"
// Set i2c address
PCF8575 pcf8575(0x20);
void setup()
{
Serial.begin(115200);
// Set pinMode to OUTPUT
pcf8575.pinMode(P0, OUTPUT);
pcf8575.begin();
}
void loop()
{
pcf8575.digitalWrite(P0, HIGH);
delay(1000);
pcf8575.digitalWrite(P0, LOW);
delay(1000);
}

View File

@@ -0,0 +1,76 @@
/*
* PCF8575 GPIO Port Expand
* http://nopnop2002.webcrow.jp/WeMos/WeMos-25.html
*
* PCF8575 ----- WeMos
* A0 ----- GRD
* A1 ----- GRD
* A2 ----- GRD
* VSS ----- GRD
* VDD ----- 5V/3.3V
* SDA ----- GPIO_4
* SCL ----- GPIO_5
* INT ----- GPIO_13
*
* P0 ----------------- BUTTON0
* P1 ----------------- BUTTON1
* P2 ----------------- BUTTON2
* P3 ----------------- BUTTON3
* P4 ----------------- BUTTON4
* P5 ----------------- BUTTON5
* P6 ----------------- BUTTON6
* P7 ----------------- BUTTON7
*
*/
#include "Arduino.h"
#include "PCF8575.h" // https://github.com/xreef/PCF8575_library
#define ESP8266_INTERRUPTED_PIN 13
// Set i2c address
PCF8575 pcf8575(0x20);
// Function interrupt
bool keyPressed = false;
void keyPressedOnPCF8575(){
// Serial.println("keyPressedOnPCF8575");
keyPressed = true;
}
void setup()
{
Serial.begin(9600);
pinMode(ESP8266_INTERRUPTED_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ESP8266_INTERRUPTED_PIN), keyPressedOnPCF8575, FALLING);
for(int i=0;i<8;i++) {
pcf8575.pinMode(i, INPUT);
}
pcf8575.begin();
}
void loop()
{
if (keyPressed){
PCF8575::DigitalInput val = pcf8575.digitalReadAll();
if (val.p0==HIGH) Serial.println("KEY0 PRESSED");
if (val.p1==HIGH) Serial.println("KEY1 PRESSED");
if (val.p2==HIGH) Serial.println("KEY2 PRESSED");
if (val.p3==HIGH) Serial.println("KEY3 PRESSED");
if (val.p4==HIGH) Serial.println("KEY4 PRESSED");
if (val.p5==HIGH) Serial.println("KEY5 PRESSED");
if (val.p6==HIGH) Serial.println("KEY6 PRESSED");
if (val.p7==HIGH) Serial.println("KEY7 PRESSED");
if (val.p8==HIGH) Serial.println("KEY8 PRESSED");
if (val.p9==HIGH) Serial.println("KEY9 PRESSED");
if (val.p10==HIGH) Serial.println("KEY10 PRESSED");
if (val.p11==HIGH) Serial.println("KEY11 PRESSED");
if (val.p12==HIGH) Serial.println("KEY12 PRESSED");
if (val.p13==HIGH) Serial.println("KEY13 PRESSED");
if (val.p14==HIGH) Serial.println("KEY14 PRESSED");
if (val.p15==HIGH) Serial.println("KEY15 PRESSED");
keyPressed= false;
}
}

View File

@@ -0,0 +1,28 @@
/*
KeyPressed on PIN1
by Mischianti Renzo <http://www.mischianti.org>
https://www.mischianti.org/2019/01/02/pcf8575-i2c-digital-i-o-expander-fast-easy-usage/
*/
#include "Arduino.h"
#include "PCF8575.h"
// Set i2c address
PCF8575 pcf8575(0x20);
unsigned long timeElapsed;
void setup()
{
Serial.begin(115200);
pcf8575.pinMode(P1, INPUT);
pcf8575.begin();
}
void loop()
{
uint8_t val = pcf8575.digitalRead(P1);
if (val==HIGH) Serial.println("KEY PRESSED");
delay(50);
}

View File

@@ -0,0 +1,35 @@
/*
KeyPressed async
by Mischianti Renzo <http://www.mischianti.org>
https://www.mischianti.org/2019/01/02/pcf8575-i2c-digital-i-o-expander-fast-easy-usage/
*/
#include "Arduino.h"
#include "PCF8575.h"
// Set i2c address
PCF8575 pcf8575(0x20);
unsigned long timeElapsed;
void setup()
{
Serial.begin(115200);
pcf8575.pinMode(P1, INPUT);
pcf8575.begin();
timeElapsed = millis();
}
void loop()
{
// Read and store on buffer all input (pinMode) that are going HIGHT
pcf8575.readBuffer();
if (millis()>timeElapsed+2000){
// read value on buffer than reset value for that pin
uint8_t val = pcf8575.digitalRead(P1);
if (val==HIGH) Serial.println("KEY PRESSED STORED ON BUFFER, NOW READED AND RESETTED.");
timeElapsed = millis();
}
}

View File

@@ -0,0 +1,46 @@
/*
KeyPressed with interrupt
by Mischianti Renzo <http://www.mischianti.org>
https://www.mischianti.org/2019/01/02/pcf8575-i2c-digital-i-o-expander-fast-easy-usage/
*/
#include "Arduino.h"
#include "PCF8575.h"
// For arduino uno only pin 1 and 2 are interrupted
#define ARDUINO_UNO_INTERRUPTED_PIN 2
// Function interrupt
void keyPressedOnPCF8575();
// Set i2c address
PCF8575 pcf8575(0x39, ARDUINO_UNO_INTERRUPTED_PIN, keyPressedOnPCF8575);
unsigned long timeElapsed;
void setup()
{
Serial.begin(115200);
pcf8575.pinMode(P1, INPUT);
pcf8575.begin();
timeElapsed = millis();
}
bool keyPressed = false;
void loop()
{
if (keyPressed){
uint8_t val = pcf8575.digitalRead(P1);
Serial.print("READ VALUE FROM PCF ");
Serial.println(val);
keyPressed= false;
}
}
void keyPressedOnPCF8575(){
// Interrupt called (No Serial no read no wire in this function, and DEBUG disabled on PCF library)
keyPressed = true;
}

View File

@@ -0,0 +1,66 @@
#include "Arduino.h"
/*
* PCF8575 GPIO Port Expand
* Blink all led
* by Mischianti Renzo <http://www.mischianti.org>
*
* https://www.mischianti.org/2019/01/02/pcf8575-i2c-digital-i-o-expander-fast-easy-usage/
*
*
* PCF8575 ----- Esp32
* A0 ----- GRD
* A1 ----- GRD
* A2 ----- GRD
* VSS ----- GRD
* VDD ----- 5V/3.3V
* SDA ----- 21
* SCL ----- 22
*
* P0 ----------------- LED0
* P1 ----------------- LED1
* P2 ----------------- LED2
* P3 ----------------- LED3
* P4 ----------------- LED4
* P5 ----------------- LED5
* P6 ----------------- LED6
* P7 ----------------- LED7
*
*/
#include "Arduino.h"
#include "PCF8575.h" // https://github.com/xreef/PCF8575_library
// Instantiate Wire for generic use at 400kHz
TwoWire I2Cone = TwoWire(0);
// Instantiate Wire for generic use at 100kHz
TwoWire I2Ctwo = TwoWire(1);
// Set i2c address
PCF8575 pcf8575(&I2Ctwo, 0x20);
// PCF8575 pcf8575(&I2Ctwo, 0x20, 21, 22);
// PCF8575(TwoWire *pWire, uint8_t address, uint8_t interruptPin, void (*interruptFunction)() );
// PCF8575(TwoWire *pWire, uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin, void (*interruptFunction)());
void setup()
{
Serial.begin(112560);
I2Cone.begin(16,17,400000); // SDA pin 16, SCL pin 17, 400kHz frequency
// Set pinMode to OUTPUT
for(int i=0;i<8;i++) {
pcf8575.pinMode(i, OUTPUT);
}
pcf8575.begin();
}
void loop()
{
static int pin = 0;
pcf8575.digitalWrite(pin, HIGH);
delay(400);
pcf8575.digitalWrite(pin, LOW);
delay(400);
pin++;
if (pin > 7) pin = 0;
}

View File

@@ -0,0 +1,59 @@
/*
* PCF8575 GPIO Port Expand
* http://nopnop2002.webcrow.jp/WeMos/WeMos-25.html
*
* PCF8575 ----- WeMos
* A0 ----- GRD
* A1 ----- GRD
* A2 ----- GRD
* VSS ----- GRD
* VDD ----- 5V/3.3V
* SDA ----- GPIO_4(PullUp)
* SCL ----- GPIO_5(PullUp)
*
* P0 ----------------- LED0
* P1 ----------------- LED1
* P2 ----------------- LED2
* P3 ----------------- LED3
* P4 ----------------- LED4
* P5 ----------------- LED5
* P6 ----------------- LED6
* P7 ----------------- LED7
* P8 ----------------- LED8
* P9 ----------------- LED9
* P10 ----------------- LED10
* P11 ----------------- LED11
* P12 ----------------- LED12
* P13 ----------------- LED13
* P14 ----------------- LED14
* P15 ----------------- LED15
*
*/
#include "Arduino.h"
#include "PCF8575.h" // https://github.com/xreef/PCF8575_library
// Set i2c address
PCF8575 pcf8575(0x20);
void setup()
{
Serial.begin(9600);
// Set pinMode to OUTPUT
for(int i=0;i<16;i++) {
pcf8575.pinMode(i, OUTPUT);
}
pcf8575.begin();
}
void loop()
{
static int pin = 0;
pcf8575.digitalWrite(pin, HIGH);
delay(1000);
pcf8575.digitalWrite(pin, LOW);
delay(1000);
pin++;
if (pin > 15) pin = 0;
}

View File

@@ -0,0 +1,63 @@
/*
* PCF8575 GPIO Port Expand
* Inverted led test: all led is connected with anodo to the IC
*
* PCF8575 ----- WeMos
* A0 ----- GRD
* A1 ----- GRD
* A2 ----- GRD
* VSS ----- GRD
* VDD ----- 5V/3.3V
* SDA ----- GPIO_4(PullUp)
* SCL ----- GPIO_5(PullUp)
*
* P0 ----------------- LED0
* P1 ----------------- LED1
* P2 ----------------- LED2
* P3 ----------------- LED3
* P4 ----------------- LED4
* P5 ----------------- LED5
* P6 ----------------- LED6
* P7 ----------------- LED7
* P8 ----------------- LED8
* P9 ----------------- LED9
* P10 ----------------- LED10
* P11 ----------------- LED11
* P12 ----------------- LED12
* P13 ----------------- LED13
* P14 ----------------- LED14
* P15 ----------------- LED15
*
*/
#include "Arduino.h"
#include "PCF8575.h" // https://github.com/xreef/PCF8575_library
// Set i2c address
PCF8575 pcf8575(0x20);
void setup()
{
Serial.begin(9600);
// Set pinMode to OUTPUT
for(int i=0;i<16;i++) {
pcf8575.pinMode(i, OUTPUT);
}
for(int i=0;i<16;i++) {
pcf8575.digitalWrite(i, HIGH);
}
pcf8575.begin();
}
void loop()
{
static int pin = 0;
pcf8575.digitalWrite(pin, LOW);
delay(1000);
pcf8575.digitalWrite(pin, HIGH);
delay(1000);
pin++;
if (pin > 15) pin = 0;
}

View File

@@ -0,0 +1,56 @@
/*
Read all data after interrupt
by Mischianti Renzo <http://www.mischianti.org>
https://www.mischianti.org/2019/01/02/pcf8575-i2c-digital-i-o-expander-fast-easy-usage/
*/
#include "Arduino.h"
#include "PCF8575.h"
// For arduino uno only pin 1 and 2 are interrupted
#define ARDUINO_UNO_INTERRUPTED_PIN 2
// Function interrupt
void keyChangedOnPCF8575();
// Set i2c address
PCF8575 pcf8575(0x39, ARDUINO_UNO_INTERRUPTED_PIN, keyChangedOnPCF8575);
unsigned long timeElapsed;
void setup()
{
Serial.begin(115200);
pcf8575.pinMode(P0, INPUT);
pcf8575.pinMode(P1, INPUT);
pcf8575.pinMode(P2, INPUT);
pcf8575.pinMode(P3, INPUT);
pcf8575.begin();
Serial.println("START");
timeElapsed = millis();
}
bool keyChanged = false;
void loop()
{
if (keyChanged){
PCF8575::DigitalInput di = pcf8575.digitalReadAll();
Serial.print("READ VALUE FROM PCF P1: ");
Serial.print(di.p0);
Serial.print(" - ");
Serial.print(di.p1);
Serial.print(" - ");
Serial.print(di.p2);
Serial.print(" - ");
Serial.println(di.p3);
// delay(5);
keyChanged= false;
}
}
void keyChangedOnPCF8575(){
// Interrupt called (No Serial no read no wire in this function, and DEBUG disabled on PCF library)
keyChanged = true;
}

View File

@@ -0,0 +1,54 @@
/*
KeyPressed with interrupt in LOW_MEMORY mode
by Mischianti Renzo <http://www.mischianti.org>
https://www.mischianti.org/2019/01/02/pcf8575-i2c-digital-i-o-expander-fast-easy-usage/
*/
#include "Arduino.h"
#include "PCF8575.h"
// To use in low memory mode and prevent use of 7byte you must decomment the line
// #define PCF8575_LOW_MEMORY
// in the library
// For arduino uno only pin 1 and 2 are interrupted
#define ARDUINO_UNO_INTERRUPTED_PIN 2
// Function interrupt
void keyChangedOnPCF8575();
// Set i2c address
PCF8575 pcf8575(0x20, ARDUINO_UNO_INTERRUPTED_PIN, keyChangedOnPCF8575);
unsigned long timeElapsed;
void setup()
{
Serial.begin(115200);
pcf8575.pinMode(P0, INPUT);
pcf8575.pinMode(P1, INPUT);
pcf8575.pinMode(P2, INPUT);
pcf8575.pinMode(P3, INPUT);
pcf8575.begin();
Serial.println("START");
timeElapsed = millis();
}
bool keyChanged = false;
void loop()
{
if (keyChanged){
byte di = pcf8575.digitalReadAll();
Serial.print("READ VALUE FROM PCF: ");
Serial.println(di, BIN);
// delay(5);
keyChanged= false;
}
}
void keyChangedOnPCF8575(){
// Interrupt called (No Serial no read no wire in this function, and DEBUG disabled on PCF library)
keyChanged = true;
}

View File

@@ -0,0 +1,21 @@
###########################################
# Syntax Coloring Map For PCF8574-library
###########################################
###########################################
# Datatypes (KEYWORD1)
###########################################
PCF8574 KEYWORD1
###########################################
# Methods and Functions (KEYWORD2)
###########################################
begin KEYWORD2
pinMode KEYWORD2
readBuffer KEYWORD2
digitalRead KEYWORD2
digitalReadAll KEYWORD2
digitalWrite KEYWORD2

View File

@@ -0,0 +1,11 @@
name=PCF8575 library
version=1.1.0
author=Renzo Mischianti <renzo.mischianti@gmail.com>
maintainer=Renzo Mischianti <renzo.mischianti@gmail.com>
sentence=PCF8575, library for Arduino, Raspberry Pi Pico and rp2040 boards, esp32, SMT32 and ESP8266.
paragraph=i2c 16bits digital expander with i2c digital expander for Arduino, Raspberry Pi Pico and rp2040 boards, esp32, SMT32 and ESP8266. Can read write digital values with only 2 wire. Very simple and encoder support. Uncommet NOT_SEQUENTIAL_PINOUT define to have pins like datasheet and not sequential one.
category=Signal Input/Output
url=https://www.mischianti.org/2019/07/22/pcf8575-i2c-16-bit-digital-i-o-expander/
repository=https://github.com/xreef/PCF8575_library
architectures=*
includes=PCF8575.h