diff --git a/PCF8575.cpp b/PCF8575.cpp index 3f5e694..bac65f8 100644 --- a/PCF8575.cpp +++ b/PCF8575.cpp @@ -154,10 +154,18 @@ PCF8575::PCF8575(uint8_t address, uint8_t interruptPin, void (*interruptFunctio }; #endif +bool PCF8575::begin(uint8_t address){ + _address = address; + return PCF8575::begin(); +} + + /** * wake up i2c controller */ -void PCF8575::begin(){ +bool PCF8575::begin(){ + this->transmissionStatus = 4; + #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); @@ -196,7 +204,7 @@ void PCF8575::begin(){ _wire->write((uint8_t) (~(usedPin >> 8))); DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor."); - _wire->endTransmission(); + this->transmissionStatus = _wire->endTransmission(); } // If using interrupt set interrupt value to pin @@ -208,6 +216,8 @@ void PCF8575::begin(){ // inizialize last read lastReadMillis = millis(); + + return this->isLastTransmissionSuccess(); } /** diff --git a/PCF8575.h b/PCF8575.h index af9c65b..f1b8117 100644 --- a/PCF8575.h +++ b/PCF8575.h @@ -132,7 +132,8 @@ class PCF8575 { PCF8575(TwoWire *pWire, uint8_t address, int sda, int scl, uint8_t interruptPin, void (*interruptFunction)()); #endif - void begin(); + bool begin(); + bool begin(uint8_t address); void pinMode(uint8_t pin, uint8_t mode); void readBuffer(bool force = true); @@ -182,6 +183,11 @@ class PCF8575 { uint16_t digitalReadAll(void); #endif void digitalWrite(uint8_t pin, uint8_t value); + bool isLastTransmissionSuccess(){ + DEBUG_PRINT(F("STATUS --> ")); + DEBUG_PRINTLN(transmissionStatus); + return transmissionStatus==0; + } private: uint8_t _address; @@ -225,6 +231,9 @@ class PCF8575 { uint16_t writeByteBuffered = 0; + uint8_t transmissionStatus = 0; + + }; #endif diff --git a/README.md b/README.md index eb8a74b..f1a0878 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Library to use i2c analog IC with arduino and esp8266. Can read and write digital value with only 2 wire (perfect for ESP-01). + - 01/02/2024: v1.1.2 Add the possibility to insert address at begin() function and return status of begin operation - 10/07/2023: v1.1.1 Add support for Arduino UNO R4 - 16/02/2023: v1.1.0 - Fix STM32 support and add support for Raspberry Pi Pico and other rp2040 boards diff --git a/library.json b/library.json index d2cbb42..0faa36a 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "PCF8575 library", - "version": "1.1.1", + "version": "1.1.2", "keywords": "digital, i2c, encoder, expander, pcf8575, pcf8575a, esp32, esp8266, stm32, SAMD, Arduino, wire, Raspberry, rp2040", "description": "PCF8575 library. i2c digital expander for 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/2019/07/22/pcf8575-i2c-16-bit-digital-i-o-expander/", diff --git a/library.properties b/library.properties index b848e10..e3d2f16 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PCF8575 library -version=1.1.1 +version=1.1.2 author=Renzo Mischianti maintainer=Renzo Mischianti sentence=PCF8575, library for Arduino, Raspberry Pi Pico and rp2040 boards, esp32, SMT32 and ESP8266.