Compare commits

...

8 Commits

8 changed files with 187 additions and 48 deletions

View File

@ -5,7 +5,97 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.make.core.makeBuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
<dictionary>
<key>org.eclipse.cdt.core.errorOutputParser</key>
<value>org.eclipse.cdt.autotools.core.ErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.VCErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.MakeErrorParser;</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.append_environment</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.build.arguments</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.build.command</key>
<value>make</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.build.target.auto</key>
<value>all</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.build.target.clean</key>
<value>clean</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.build.target.inc</key>
<value>all</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.environment</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.stopOnError</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
<value>true</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.autotools.core.genmakebuilderV2</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>io.sloeber.core.inoToCpp</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.codan.core.codanBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>io.sloeber.arduinonature</nature>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.autotools.core.autotoolsNatureV2</nature>
<nature>org.eclipse.cdt.make.core.makeNature</nature>
<nature>org.eclipse.cdt.codan.core.codanNature</nature>
<nature>org.eclipse.cdt.make.core.cfgSupportNature</nature>
</natures>
</projectDescription>

View File

@ -53,14 +53,14 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio
_usingInterrupt = true;
};
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(__STM32F1__) && !defined(TEENSYDUINO)
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(TEENSYDUINO) && !defined(ARDUINO_ARCH_RENESAS)
/**
* Constructor
* @param address: i2c address
* @param sda: sda pin
* @param scl: scl pin
*/
PCF8574::PCF8574(uint8_t address, uint8_t sda, uint8_t scl){
PCF8574::PCF8574(uint8_t address, int sda, int scl){
_wire = &Wire;
_address = address;
@ -76,7 +76,7 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio
* @param interruptPin: pin to set interrupt
* @param interruptFunction: function to call when interrupt raised
*/
PCF8574::PCF8574(uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin, void (*interruptFunction)() ){
PCF8574::PCF8574(uint8_t address, int sda, int scl, uint8_t interruptPin, void (*interruptFunction)() ){
_wire = &Wire;
_address = address;
@ -90,7 +90,7 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio
};
#endif
#ifdef ESP32
#if defined(ESP32) || defined(ARDUINO_ARCH_SAMD)|| defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_RENESAS)
/**
* Constructor
* @param address: i2c address
@ -115,14 +115,15 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio
_interruptFunction = interruptFunction;
_usingInterrupt = true;
};
#endif
#if defined(ESP32)
/**
* Constructor
* @param address: i2c address
* @param sda: sda pin
* @param scl: scl pin
*/
PCF8574::PCF8574(TwoWire *pWire, uint8_t address, uint8_t sda, uint8_t scl){
PCF8574::PCF8574(TwoWire *pWire, uint8_t address, int sda, int scl){
_wire = pWire;
_address = address;
@ -138,7 +139,7 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio
* @param interruptPin: pin to set interrupt
* @param interruptFunction: function to call when interrupt raised
*/
PCF8574::PCF8574(TwoWire *pWire, uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin, void (*interruptFunction)() ){
PCF8574::PCF8574(TwoWire *pWire, uint8_t address, int sda, int scl, uint8_t interruptPin, void (*interruptFunction)() ){
_wire = pWire;
_address = address;
@ -180,15 +181,29 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio
}
bool PCF8574::begin(uint8_t address){
_address = address;
return PCF8574::begin();
}
/**
* wake up i2c controller
*/
bool PCF8574::begin(){
this->transmissionStatus = 4;
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(__STM32F1__) && !defined(TEENSYDUINO)
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(TEENSYDUINO) && !defined(ARDUINO_ARCH_RENESAS)
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

View File

@ -2,7 +2,7 @@
* PCF8574 GPIO Port Expand
*
* AUTHOR: Renzo Mischianti
* VERSION: 2.3.2
* VERSION: 2.3.7
*
* https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/
*
@ -109,21 +109,23 @@ public:
PCF8574(uint8_t address);
PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunction)() );
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(__STM32F1__) && !defined(TEENSYDUINO)
PCF8574(uint8_t address, uint8_t sda, uint8_t scl);
PCF8574(uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin, void (*interruptFunction)());
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(TEENSYDUINO) && !defined(ARDUINO_ARCH_RENESAS)
PCF8574(uint8_t address, int sda, int scl);
PCF8574(uint8_t address, int sda, int scl, uint8_t interruptPin, void (*interruptFunction)());
#endif
#ifdef ESP32
#if defined(ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_RENESAS)
///// changes for second i2c bus
PCF8574(TwoWire *pWire, uint8_t address);
PCF8574(TwoWire *pWire, uint8_t address, uint8_t sda, uint8_t scl);
PCF8574(TwoWire *pWire, uint8_t address, uint8_t interruptPin, void (*interruptFunction)() );
PCF8574(TwoWire *pWire, uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin, void (*interruptFunction)());
#endif
#if defined(ESP32)
PCF8574(TwoWire *pWire, uint8_t address, int sda, int scl);
PCF8574(TwoWire *pWire, uint8_t address, int sda, int scl, uint8_t interruptPin, void (*interruptFunction)());
#endif
bool begin();
bool begin(uint8_t address);
void pinMode(uint8_t pin, uint8_t mode, uint8_t output_start = HIGH);
void encoder(uint8_t pinA, uint8_t pinB);
@ -201,7 +203,7 @@ private:
uint8_t _address;
#if !defined(DEFAULT_SDA)
# if defined(__STM32F1__)
# if defined(ARDUINO_ARCH_STM32)
# define DEFAULT_SDA PB7
# elif defined(ESP8266)
# define DEFAULT_SDA 4
@ -212,7 +214,7 @@ private:
# endif
#endif
#if !defined(DEFAULT_SCL)
# if defined(__STM32F1__)
# if defined(ARDUINO_ARCH_STM32)
# define DEFAULT_SCL PB6
# elif defined(ESP8266)
# define DEFAULT_SCL 5
@ -223,8 +225,8 @@ private:
# endif
#endif
uint8_t _sda = DEFAULT_SDA;
uint8_t _scl = DEFAULT_SCL;
int _sda = DEFAULT_SDA;
int _scl = DEFAULT_SCL;
TwoWire *_wire;

View File

@ -2,7 +2,7 @@
* PCF8574 GPIO Port Expand
*
* AUTHOR: Renzo Mischianti
* VERSION: 2.3.2
* VERSION: 2.3.7
*
* https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/
*

View File

@ -9,35 +9,30 @@
align="right"></a>
</div>
#
#
#
#
#
#
### 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 the pcf8575 16bit version of the IC.
# PCF8574 PCF8574AP digital input and output expander with i2c bus.
#### Complete documentation on my site: [pcf8574 Article](https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/).
### Version 2.2
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:
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.
#### 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.
## Changelog
28/07/2022: v2.3.2 Fix the SDA SCL type #58 and add basic support for SAMD device.
26/04/2022: v2.3.1 Fix example for esp32 and double begin issue #56.
06/04/2022: v2.3.0 Fix package size
30/12/2021: v2.2.4 Minor fix and remove deprecated declaration
23/11/2020: v2.2.2 Add multiple implementation for encoder management (you can enable by uncomment relative define)
- 01/02/2024: v2.3.7 Add the possibility to insert address at begin()
- 10/07/2023: v2.3.6 Support for Arduino UNO R4
- 08/02/2023: v2.3.5 Fix STM32 support and add support for Raspberry Pi Pico and other rp2040 boards
- 10/08/2022: v2.3.4 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/).
- 28/07/2022: v2.3.3 Force SDA SCL to use GPIO numeration (https://www.mischianti.org/forums/topic/cannot-set-sda-clk-on-esp8266/).
- 28/07/2022: v2.3.2 Fix the SDA SCL type #58 and add basic support for SAMD device.
- 26/04/2022: v2.3.1 Fix example for esp32 and double begin issue #56.
- 06/04/2022: v2.3.0 Fix package size
- 30/12/2021: v2.2.4 Minor fix and remove deprecated declaration
- 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 operations.
Tested with esp8266, esp32, Arduino, Arduino SAMD (Nano 33 IoT, MKR etc.), STM32 and rp2040 (Raspberry Pi Pico and similar)
PCF8574P address map 0x20-0x27
PCF8574AP address map 0x38-0x3f

View File

@ -0,0 +1,37 @@
/*
KeyPressed on PIN1
by Mischianti Renzo <http://www.mischianti.org>
https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/
*/
#include "Arduino.h"
#include "PCF8574.h"
TwoWire aWire(&sercom3, 20, 21);
// Set i2c address
PCF8574 pcf8574(&aWire, 0x38);
unsigned long timeElapsed;
void setup()
{
Serial.begin(115200);
delay(1000);
pcf8574.pinMode(P0, OUTPUT);
pcf8574.pinMode(P1, INPUT);
Serial.print("Init pcf8574...");
if (pcf8574.begin()){
Serial.println("OK");
}else{
Serial.println("KO");
}
}
void loop()
{
uint8_t val = pcf8574.digitalRead(P1);
if (val==HIGH) Serial.println("KEY PRESSED");
delay(50);
}

View File

@ -1,8 +1,8 @@
{
"name": "PCF8574 library",
"version": "2.3.2",
"keywords": "digital, i2c, encoder, expander, pcf8574, pcf8574a, esp32, esp8266, stm32, SAMD, Arduino, wire",
"description": "i2c digital expander for Arduino, esp32, SMT32 and ESP8266. Can read write digital values with only 2 wire. Very simple to use and encoder support.",
"version": "2.3.7",
"keywords": "digital, i2c, encoder, expander, pcf8574, pcf8574a, esp32, esp8266, stm32, SAMD, Arduino, wire, rp2040, Raspberry",
"description": "Most starred PCF8574 library. 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 to use and encoder support.",
"homepage": "https://www.mischianti.org/category/my-libraries/pcf8574/",
"authors":
[

View File

@ -1,10 +1,10 @@
name=PCF8574 library
version=2.3.2
version=2.3.7
author=Renzo Mischianti <renzo.mischianti@gmail.com>
maintainer=Renzo Mischianti <renzo.mischianti@gmail.com>
sentence=PCF8574, library for Arduino, ESP8266, smt32 and esp32
paragraph=i2c digital expander for Arduino, esp32, SMT32 and ESP8266. Can read write digital values with only 2 wire. Very simple to use and encoder support.
category=Sensors
sentence=Most starred PCF8574 library for Arduino (standard and SAMD), Raspberry Pi Pico and rp2040 boards, ESP8266, smt32 and esp32
paragraph=Most starred PCF8574 library. i2c digital expander for Arduino (standard and SAMD), esp32, Raspberry Pi Pico and rp2040 boards, SMT32 and ESP8266. Can read write digital values with only 2 wire. Very simple to use and encoder support.
category=Signal Input/Output
url=https://www.mischianti.org/category/my-libraries/pcf8574/
repository=https://github.com/xreef/PCF8574_library
architectures=*