diff --git a/CHANGELOG.md b/CHANGELOG.md index cf059c6..32a719e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [0.1.10] - 2023-09-24 -- fix Wire1 support for ESP32 (again) +- refactor API, begin() +- update examples +- update readme.md + +---- +## [0.1.10] - 2023-09-24 +- fix Wire1 support for ESP32 (again) ## [0.1.9] - 2023-09-23 - add Wire1 support for ESP32 diff --git a/PCF8575.cpp b/PCF8575.cpp index a9ede28..b3819fb 100644 --- a/PCF8575.cpp +++ b/PCF8575.cpp @@ -2,7 +2,7 @@ // FILE: PCF8575.cpp // AUTHOR: Rob Tillaart // DATE: 2020-07-20 -// VERSION: 0.1.10 +// VERSION: 0.2.0 // PURPOSE: Arduino library for PCF8575 - 16 channel I2C IO expander // URL: https://github.com/RobTillaart/PCF8575 @@ -21,25 +21,8 @@ PCF8575::PCF8575(const uint8_t deviceAddress, TwoWire *wire) } -#if defined (ESP8266) || defined(ESP32) -bool PCF8575::begin(int dataPin, int clockPin, uint16_t value) -{ - if ((dataPin < 255) && (clockPin < 255)) - { - _wire->begin(dataPin, clockPin); - } else { - _wire->begin(); - } - if (! isConnected()) return false; - PCF8575::write16(value); - return true; -} -#endif - - bool PCF8575::begin(uint16_t value) { - _wire->begin(); if (! isConnected()) return false; PCF8575::write16(value); return true; diff --git a/PCF8575.h b/PCF8575.h index b9da661..d7b1294 100644 --- a/PCF8575.h +++ b/PCF8575.h @@ -3,7 +3,7 @@ // FILE: PCF8575.h // AUTHOR: Rob Tillaart // DATE: 2020-07-20 -// VERSION: 0.1.10 +// VERSION: 0.2.0 // PURPOSE: Arduino library for PCF8575 - 16 channel I2C IO expander // URL: https://github.com/RobTillaart/PCF8575 @@ -12,7 +12,7 @@ #include "Wire.h" -#define PCF8575_LIB_VERSION (F("0.1.10")) +#define PCF8575_LIB_VERSION (F("0.2.0")) #ifndef PCF8575_INITIAL_VALUE @@ -30,9 +30,6 @@ class PCF8575 // deviceAddress base = 0x20 + depends on address bits explicit PCF8575(const uint8_t deviceAddress = 0x20, TwoWire *wire = &Wire); -#if defined (ESP8266) || defined(ESP32) - bool begin(int sda, int scl, uint16_t value = PCF8575_INITIAL_VALUE); -#endif bool begin(uint16_t value = PCF8575_INITIAL_VALUE); bool isConnected(); diff --git a/README.md b/README.md index 7593d46..b723747 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,15 @@ The library allows to read and write both single pins or 16 pins at once. Furthermore some additional functions are implemented that are playful and useful. +#### 0.2.0 Breaking change + +Version 0.2.0 introduced a breaking change. +You cannot set the pins in **begin()** any more. +This reduces the dependency of processor dependent Wire implementations. +The user has to call **Wire.begin()** and can optionally set the Wire pins +before calling **begin()**. + + #### Interrupts The PCF8575 has an interrupt output line (INT) to notify an MCU that one of the input lines has changed. diff --git a/examples/PCF8575_Wire2/PCF8575_Wire2.ino b/examples/PCF8575_Wire2/PCF8575_Wire2.ino index bf702f2..5ee2dec 100644 --- a/examples/PCF8575_Wire2/PCF8575_Wire2.ino +++ b/examples/PCF8575_Wire2/PCF8575_Wire2.ino @@ -2,12 +2,12 @@ // FILE: PCF8575_Wire2.ino // AUTHOR: Rob Tillaart // DATE: 2021-01-03 -// PUPROSE: demo +// PURPOSE: demo #include "PCF8575.h" -// adjust addresses if needed +// adjust addresses if needed PCF8575 PCF(0x39, &Wire2); @@ -18,6 +18,8 @@ void setup() Serial.print("PCF8575_LIB_VERSION:\t"); Serial.println(PCF8575_LIB_VERSION); + Wire.begin(); + if (!PCF.begin()) { Serial.println("could not initialize..."); @@ -75,5 +77,5 @@ void doToggle() } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/examples/PCF8575_array/PCF8575_array.ino b/examples/PCF8575_array/PCF8575_array.ino index 12ac3df..47c0aa6 100644 --- a/examples/PCF8575_array/PCF8575_array.ino +++ b/examples/PCF8575_array/PCF8575_array.ino @@ -2,12 +2,12 @@ // FILE: PCF8575_array.ino // AUTHOR: Rob Tillaart // DATE: 2021-12-13 -// PUPROSE: demo array of PCF - not tested +// PURPOSE: demo array of PCF - not tested #include "PCF8575.h" -// adjust addresses if needed +// adjust addresses if needed PCF8575 A(0x38); PCF8575 B(0x39); PCF8575 C(0x3A); @@ -22,6 +22,8 @@ void setup() Serial.print("PCF8575_LIB_VERSION:\t"); Serial.println(PCF8575_LIB_VERSION); + Wire.begin(); + for (int i = 0; i < 3; i++) { PCF[i].begin(); @@ -52,5 +54,5 @@ void loop() } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/examples/PCF8575_interrupt/PCF8575_interrupt.ino b/examples/PCF8575_interrupt/PCF8575_interrupt.ino index ec70bad..0ecb43d 100644 --- a/examples/PCF8575_interrupt/PCF8575_interrupt.ino +++ b/examples/PCF8575_interrupt/PCF8575_interrupt.ino @@ -2,9 +2,9 @@ // FILE: PCF8575_interrupt.ino // AUTHOR: Rob Tillaart // DATE: 2021-01-03 -// PUPROSE: test PCF8575 library +// PURPOSE: test PCF8575 library // -// TEST SETUP +// TEST SETUP // Connect INT pin of the PCF8575 to UNO pin 2 // // (from figure 4 datasheet @@ -19,7 +19,7 @@ PCF8575 PCF(0x38); //////////////////////////////////// // -// INTERRUPT ROUTINE + FLAG +// INTERRUPT ROUTINE + FLAG // const int IRQPIN = 2; @@ -33,15 +33,17 @@ void pcf_irq() //////////////////////////////////// // -// MAIN CODE +// MAIN CODE // void setup() { Serial.begin(115200); Serial.println(__FILE__); - Serial.print("PCF8575_LIB_VERSION: "); + Serial.print("PCF8575_LIB_VERSION:\t"); Serial.println(PCF8575_LIB_VERSION); + Wire.begin(); + PCF.begin(); pinMode(IRQPIN, INPUT_PULLUP); @@ -62,10 +64,10 @@ void loop() Serial.print('\t'); Serial.println(x, HEX); } - // do other things here + // do other things here delay(10); } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/examples/PCF8575_isConnected/PCF8575_isConnected.ino b/examples/PCF8575_isConnected/PCF8575_isConnected.ino index 8c564a0..938333f 100644 --- a/examples/PCF8575_isConnected/PCF8575_isConnected.ino +++ b/examples/PCF8575_isConnected/PCF8575_isConnected.ino @@ -2,12 +2,12 @@ // FILE: PCF8575_isConnected.ino // AUTHOR: Rob Tillaart // DATE: 2021-01-03 -// PUPROSE: demo device detection +// PURPOSE: demo device detection #include "PCF8575.h" -// adjust addresses if needed +// adjust addresses if needed PCF8575 PCF(0x39); @@ -18,6 +18,8 @@ void setup() Serial.print("PCF8575_LIB_VERSION:\t"); Serial.println(PCF8575_LIB_VERSION); + Wire.begin(); + if (!PCF.begin()) { Serial.println("could not initialize..."); @@ -38,5 +40,5 @@ void loop() } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/examples/PCF8575_performance/PCF8575_performance.ino b/examples/PCF8575_performance/PCF8575_performance.ino index a3b500b..24799da 100644 --- a/examples/PCF8575_performance/PCF8575_performance.ino +++ b/examples/PCF8575_performance/PCF8575_performance.ino @@ -2,7 +2,7 @@ // FILE: PCF8575_performance.ino // AUTHOR: Rob Tillaart // DATE: 2021-01-24 -// PUPROSE: test PCF8575 library +// PURPOSE: test PCF8575 library #include "PCF8575.h" @@ -21,6 +21,8 @@ void setup() Serial.print("PCF8575_LIB_VERSION:\t"); Serial.println(PCF8575_LIB_VERSION); + Wire.begin(); + PCF.begin(); Serial.println(PCF.isConnected()); @@ -50,5 +52,5 @@ void loop() } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/examples/PCF8575_select/PCF8575_select.ino b/examples/PCF8575_select/PCF8575_select.ino index 391e770..a3a12e6 100644 --- a/examples/PCF8575_select/PCF8575_select.ino +++ b/examples/PCF8575_select/PCF8575_select.ino @@ -2,8 +2,7 @@ // FILE: PCF8575_select.ino // AUTHOR: Rob Tillaart // DATE: 2022-06-18 -// PUPROSE: demo PCF8575 library select functions - +// PURPOSE: demo PCF8575 library select functions #include "PCF8575.h" @@ -20,6 +19,8 @@ void setup() Serial.print("PCF8575_LIB_VERSION:\t"); Serial.println(PCF8575_LIB_VERSION); + Wire.begin(); + PCF.begin(); Serial.println(PCF.isConnected()); Serial.println(); @@ -29,14 +30,14 @@ void setup() PCF.selectNone(); delay(1000); - // VU meter up + // VU meter up for (int i = 0; i < 15; i++) { PCF.selectN(i); delay(100); } - // VU meter down + // VU meter down for (int i = 15; i >= 0; i--) { PCF.selectN(i); @@ -47,7 +48,7 @@ void setup() void loop() { - // night rider + // night rider for (int i = 0; i < 15; i++) { PCF.select(i); @@ -61,4 +62,5 @@ void loop() } -// -- END OF FILE -- +// -- END OF FILE -- + diff --git a/examples/PCF8575_test/PCF8575_test.ino b/examples/PCF8575_test/PCF8575_test.ino index cfa4281..64b17b1 100644 --- a/examples/PCF8575_test/PCF8575_test.ino +++ b/examples/PCF8575_test/PCF8575_test.ino @@ -2,7 +2,7 @@ // FILE: PCF8575_test.ino // AUTHOR: Rob Tillaart // DATE: 2020-07-20 -// PUPROSE: test PCF8575 library +// PURPOSE: test PCF8575 library // URL: https://github.com/RobTillaart/PCF8575 @@ -15,9 +15,11 @@ void setup() { Serial.begin(115200); Serial.println(__FILE__); - Serial.print("PCF8575_test version: "); + Serial.print("PCF8575_LIB_VERSION:\t"); Serial.println(PCF8575_LIB_VERSION); + Wire.begin(); + PCF.begin(); uint16_t x = PCF.read16(); @@ -76,5 +78,5 @@ void printHex(uint16_t x) } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/examples/PCF8575_test1/PCF8575_test1.ino b/examples/PCF8575_test1/PCF8575_test1.ino index bef1d61..d609065 100644 --- a/examples/PCF8575_test1/PCF8575_test1.ino +++ b/examples/PCF8575_test1/PCF8575_test1.ino @@ -2,14 +2,14 @@ // FILE: pcf8575_test.ino // AUTHOR: Rob Tillaart // DATE: 2021-01-03 -// PUPROSE: demo +// PURPOSE: demo #include "PCF8575.h" -// adjust addresses if needed -PCF8575 PCF_38(0x38); // add switches to lines (used as input) -PCF8575 PCF_39(0x39); // add leds to lines (used as output) +// adjust addresses if needed +PCF8575 PCF_38(0x38); // add switches to lines (used as input) +PCF8575 PCF_39(0x39); // add leds to lines (used as output) void setup() @@ -19,6 +19,8 @@ void setup() Serial.print("PCF8575_LIB_VERSION:\t"); Serial.println(PCF8575_LIB_VERSION); + Wire.begin(); + PCF_38.begin(); PCF_39.begin(); @@ -65,12 +67,12 @@ void setup() void loop() { - // echos the lines + // echos the lines uint16_t value = PCF_38.read16(); PCF_39.write16(value); delay(100); } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/examples/PCF8575_test2/PCF8575_test2.ino b/examples/PCF8575_test2/PCF8575_test2.ino index 9294cdb..38d8e1e 100644 --- a/examples/PCF8575_test2/PCF8575_test2.ino +++ b/examples/PCF8575_test2/PCF8575_test2.ino @@ -2,13 +2,13 @@ // FILE: pcf8575_test2.ino // AUTHOR: Rob Tillaart // DATE: 2021-01-03 -// PUPROSE: demo rotateLeft, -Right and toggleMask +// PURPOSE: demo rotateLeft, -Right and toggleMask #include "PCF8575.h" -// adjust addresses if needed -PCF8575 PCF(0x39); // add LEDs to lines (used as output) +// adjust addresses if needed +PCF8575 PCF(0x39); // add LEDs to lines (used as output) void setup() @@ -18,6 +18,8 @@ void setup() Serial.print("PCF8575_LIB_VERSION:\t"); Serial.println(PCF8575_LIB_VERSION); + Wire.begin(); + PCF.begin(); PCF.write(0, 1); @@ -51,8 +53,8 @@ void setup() delay(100); } - // 0010 0111 -> 0x27 - // 1110 0100 + // 0010 0111 -> 0x27 + // 1110 0100 PCF.write16(0x2755); for (int i = 0; i < 255; i++) { @@ -67,5 +69,5 @@ void loop() } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/library.json b/library.json index 8826e48..a545844 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/PCF8575.git" }, - "version": "0.1.10", + "version": "0.2.0", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index 194c411..93f5fa9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PCF8575 -version=0.1.10 +version=0.2.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for PCF8575 - 16 channel I2C IO expander diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp index 22b91a4..af97f6a 100644 --- a/test/unit_test_001.cpp +++ b/test/unit_test_001.cpp @@ -63,6 +63,7 @@ unittest(test_begin) { PCF8575 PCF(0x38); + Wire.begin(); PCF.begin(); int readValue = PCF.read16(); @@ -78,6 +79,8 @@ unittest(test_read) PCF8575 PCF(0x38); int readValue; + Wire.begin(); + PCF.begin(); for (int i = 0; i < 8; i++) {