diff --git a/.github/workflows/arduino-lint.yml b/.github/workflows/arduino-lint.yml index b2ca058..8a26f14 100644 --- a/.github/workflows/arduino-lint.yml +++ b/.github/workflows/arduino-lint.yml @@ -6,7 +6,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: arduino/arduino-lint-action@v1 with: library-manager: update diff --git a/.github/workflows/arduino_test_runner.yml b/.github/workflows/arduino_test_runner.yml index 096b975..fadfa90 100644 --- a/.github/workflows/arduino_test_runner.yml +++ b/.github/workflows/arduino_test_runner.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: ruby-version: 2.6 diff --git a/.github/workflows/jsoncheck.yml b/.github/workflows/jsoncheck.yml index 04603d0..37a1129 100644 --- a/.github/workflows/jsoncheck.yml +++ b/.github/workflows/jsoncheck.yml @@ -10,7 +10,7 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: json-syntax-check uses: limitusus/json-syntax-check@v1 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index f1bd3d9..a5a74ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.1.4] - 2022-12-29 +- Fix #7 missing public: +- add unit test for TCA9535 constructor +- add examples for TCA9535 +- update examples +- add **getAddress()** (debugging) +- update readme.md +- update GitHub actions -> v3 + + ## [0.1.3] - 2022-11-25 - Add RP2040 support to build-CI. - Add CHANGELOG.md diff --git a/README.md b/README.md index 48983a0..4137f20 100644 --- a/README.md +++ b/README.md @@ -29,24 +29,35 @@ input and not driven. This reduces power consumption when the I/O is held low._ There is a TCA9535 class which is a (convenience) wrapper around the TCA9555 class. This allows one to create TCA9535 objects. +## Hardware + +#### I2C addresses + +Allowed addresses are 0x20..0x27. to be set with pin A0, A1, A2. + ## Interface Check the datasheet for details +```cpp +#include "TCA9555.h" +``` -### Constructor +#### Constructor -- **TCA9555(uint8_t address, TwoWire \*wire = &Wire)** constructor, with default Wire interface. Can be overruled with Wire0..WireN. +- **TCA9555(uint8_t address, TwoWire \*wire = &Wire)** constructor, with default Wire interface. +Can be overruled with Wire0..WireN. - **TCA9535(uint8_t address, TwoWire \*wire = &Wire)** idem. - **bool begin()** for UNO, returns true if successful. - **bool begin(uint8_t sda, uint8_t scl)** for ESP32, returns true if successful. - **bool isConnected()** returns true if connected, false otherwise. +- **uint8_t getAddress()** returns set address, (debugging). -### 1 pin interface +#### 1 pin interface - **bool pinMode(uint8_t pin, uint8_t mode)** idem. - **bool digitalWrite(uint8_t pin, uint8_t value)** pin = 0..15, value = LOW(0) HIGH (!0), returns true if successful. @@ -55,7 +66,7 @@ Check the datasheet for details - **uint8_t getPolarity(uint8_t pin)** returns 1 if a pin is inverted. -### 8 pin interface +#### 8 pin interface port = 0..1 mask = 0..255 @@ -68,7 +79,7 @@ Especially useful if one needs to trigger multiple pins at the exact same time. - **uint8_t getPolarity(uint8_t port)** returns a mask with a 1 for every INPUT pin that is inverted. -### 16 pin interface +#### 16 pin interface Be aware that the 16 pins interface does two calls to the 8 pins interface. So it is impossible to switch pins from the 2 groups of 8 at exactly the same time @@ -82,20 +93,20 @@ Returns true upon success. - **uint16_t getPolarity()** returns a mask of 16 bits with a 1 for every INPUT pin that is inverted. -### Error codes +#### Error codes - **int lastError()** Above functions set an error flag that can be read with this function. Reading it will reset the flag to **TCA9555_OK**. -| DESCRIPTION | VALUE | -|:---------------------|:-----:| -| TCA9555_OK | 0x00 | -| TCA9555_PIN_ERROR | 0x81 | -| TCA9555_I2C_ERROR | 0x82 | -| TCA9555_VALUE_ERROR | 0x83 | -| TCA9555_PORT_ERROR | 0x84 | -| TCA9555_INVALID_READ | -100 | +| Description | Value | +|:-----------------------|:-------:| +| TCA9555_OK | 0x00 | +| TCA9555_PIN_ERROR | 0x81 | +| TCA9555_I2C_ERROR | 0x82 | +| TCA9555_VALUE_ERROR | 0x83 | +| TCA9555_PORT_ERROR | 0x84 | +| TCA9555_INVALID_READ | -100 | ## Operation @@ -107,17 +118,31 @@ See examples #### Must + - buy TCA9555 / TCA9535 - test all functionality (initial version is written with no hardware around) + #### Should -- INPUT_PULLUP mappen op INPUT (pinMode ?) + +- investigate map INPUT_PULLUP on INPUT (pinMode ?) - investigate internal pull up etc. -- add TCA9535 error codes - investigate TCA9535 differences - - elaborate derived class + - pull up resistors + - elaborate derived class +- add **getType()** to distinguish derived classes. + - int or uint8_t => 4 or 2 digits, define? + - or even a string (no)? + - constructor + #### Could + - rethink class hierarchy + -5535 has less functions so should be base class? +- valid address range? +#### Wont (unless) +- add TCA9535 error codes + - better reuse them? diff --git a/TCA9555.cpp b/TCA9555.cpp index 9ebe4cd..2d0e5ab 100644 --- a/TCA9555.cpp +++ b/TCA9555.cpp @@ -1,7 +1,7 @@ // // FILE: TCA9555.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.3 +// VERSION: 0.1.4 // PURPOSE: Arduino library for I2C TCA9555 16 channel port expander // DATE: 2021-06-09 // URL: https://github.com/RobTillaart/TCA9555 @@ -55,6 +55,12 @@ bool TCA9555::isConnected() } +uint8_t TCA9555::getAddress() +{ + return _address; +} + + ////////////////////////////////////////////////////////// // // 1 PIN INTERFACE diff --git a/TCA9555.h b/TCA9555.h index b8b0b05..5eb59c8 100644 --- a/TCA9555.h +++ b/TCA9555.h @@ -2,7 +2,7 @@ // // FILE: TCA9555.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.3 +// VERSION: 0.1.4 // PURPOSE: Arduino library for I2C TCA9555 16 channel port expander // DATE: 2021-06-09 // URL: https://github.com/RobTillaart/TCA9555 @@ -12,7 +12,7 @@ #include "Wire.h" -#define TCA9555_LIB_VERSION (F("0.1.3")) +#define TCA9555_LIB_VERSION (F("0.1.4")) #define TCA9555_OK 0x00 #define TCA9555_PIN_ERROR 0x81 @@ -34,6 +34,7 @@ class TCA9555 #endif bool begin(); bool isConnected(); + uint8_t getAddress(); // 1 PIN INTERFACE @@ -87,6 +88,7 @@ class TCA9555 // class TCA9535 : public TCA9555 { +public: TCA9535(uint8_t address, TwoWire *wire = &Wire); }; diff --git a/examples/TCA9535_digitalRead/TCA9535_digitalRead.ino b/examples/TCA9535_digitalRead/TCA9535_digitalRead.ino new file mode 100644 index 0000000..1692fb3 --- /dev/null +++ b/examples/TCA9535_digitalRead/TCA9535_digitalRead.ino @@ -0,0 +1,41 @@ +// +// FILE: TCA9535_digitalRead.ino +// AUTHOR: Rob Tillaart +// PUPROSE: test TCA9555 library +// URL: https://github.com/RobTillaart/TCA9555 + + +#include "Wire.h" +#include "TCA9555.h" + + +TCA9535 TCA(0x27); + + +void setup() +{ + Serial.begin(115200); + Serial.print("TCA9555_LIB_VERSION: "); + Serial.println(TCA9555_LIB_VERSION); + + Wire.begin(); + TCA.begin(); + + Serial.println("TEST digitalRead(pin)"); + for (int pin = 0; pin < 16; pin++) + { + int val = TCA.digitalRead(pin); + Serial.print(val); + Serial.print('\t'); + } + Serial.println(); +} + + +void loop() +{ +} + + +// -- END OF FILE -- + diff --git a/examples/TCA9535_digitalWrite/TCA9535_digitalWrite.ino b/examples/TCA9535_digitalWrite/TCA9535_digitalWrite.ino new file mode 100644 index 0000000..86a0986 --- /dev/null +++ b/examples/TCA9535_digitalWrite/TCA9535_digitalWrite.ino @@ -0,0 +1,65 @@ +// +// FILE: TCA9535_digitalWrite.ino +// AUTHOR: Rob Tillaart +// PUPROSE: test TCA9555 library - TCA9535 derived class +// URL: https://github.com/RobTillaart/TCA9555 + + +#include "Wire.h" +#include "TCA9555.h" + + +TCA9535 TCA(0x27); + + +void setup() +{ + Serial.begin(115200); + Serial.print("TCA9555_LIB_VERSION: "); + Serial.println(TCA9555_LIB_VERSION); + + Wire.begin(); + TCA.begin(); + + Wire.setClock(50); + + Serial.println("TEST digitalWrite(0)"); + for (int i = 0; i < 16; i++) + { + TCA.digitalWrite(0, i % 2); // alternating HIGH/LOW + Serial.print(i % 2); + Serial.print('\t'); + delay(250); + } + Serial.println(); + Serial.println(); + + Serial.println("TEST digitalWrite(pin)"); + for (int pin = 0; pin < 16; pin++) + { + TCA.digitalWrite(pin, 1 - pin % 2); // alternating HIGH/LOW + Serial.print(1 - pin % 2); + Serial.print('\t'); + } + Serial.println(); + Serial.println(); + + Serial.println("TEST read back"); + + for (int pin = 0; pin < 16; pin++) + { + int val = TCA.digitalRead(pin); + Serial.print(val); + Serial.print('\t'); + } + Serial.println(); + Serial.println(); +} + + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/examples/TCA9555_digitalRead/TCA9555_digitalRead.ino b/examples/TCA9555_digitalRead/TCA9555_digitalRead.ino index 03916af..71b64b7 100644 --- a/examples/TCA9555_digitalRead/TCA9555_digitalRead.ino +++ b/examples/TCA9555_digitalRead/TCA9555_digitalRead.ino @@ -1,12 +1,12 @@ // // FILE: TCA9555_digitalRead.ino // AUTHOR: Rob Tillaart -/// DATE: 2021-06-09 // PUPROSE: test TCA9555 library +// URL: https://github.com/RobTillaart/TCA9555 -#include "TCA9555.h" #include "Wire.h" +#include "TCA9555.h" TCA9555 TCA(0x27); diff --git a/examples/TCA9555_digitalWrite/TCA9555_digitalWrite.ino b/examples/TCA9555_digitalWrite/TCA9555_digitalWrite.ino index 1498e99..a4492b1 100644 --- a/examples/TCA9555_digitalWrite/TCA9555_digitalWrite.ino +++ b/examples/TCA9555_digitalWrite/TCA9555_digitalWrite.ino @@ -1,12 +1,12 @@ // // FILE: TCA9555_digitalWrite.ino // AUTHOR: Rob Tillaart -// DATE: 2021-06-09 // PUPROSE: test TCA9555 library +// URL: https://github.com/RobTillaart/TCA9555 -#include "TCA9555.h" #include "Wire.h" +#include "TCA9555.h" TCA9555 TCA(0x27); diff --git a/examples/TCA9555_setPolarity/TCA9555_setPolarity.ino b/examples/TCA9555_setPolarity/TCA9555_setPolarity.ino index 9c68141..099d5ef 100644 --- a/examples/TCA9555_setPolarity/TCA9555_setPolarity.ino +++ b/examples/TCA9555_setPolarity/TCA9555_setPolarity.ino @@ -1,12 +1,12 @@ // // FILE: TCA9555_setPolarity.ino // AUTHOR: Rob Tillaart -/// DATE: 2021-06-09 // PUPROSE: test TCA9555 library +// URL: https://github.com/RobTillaart/TCA9555 -#include "TCA9555.h" #include "Wire.h" +#include "TCA9555.h" TCA9555 TCA(0x27); diff --git a/library.json b/library.json index 7ca842a..7f7ae8c 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/TCA9555.git" }, - "version": "0.1.3", + "version": "0.1.4", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index 7178c93..5ecd9d4 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TCA9555 -version=0.1.3 +version=0.1.4 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for I2C TCA9555 16 channel port expander - 16 IO-lines diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp index c062d31..030d556 100644 --- a/test/unit_test_001.cpp +++ b/test/unit_test_001.cpp @@ -48,7 +48,7 @@ unittest_teardown() } -unittest(test_constructor) +unittest(test_constructor_TCA9555) { TCA9555 TCA(0x22); @@ -57,6 +57,15 @@ unittest(test_constructor) } +unittest(test_constructor_TCA9535) +{ + TCA9535 TCA(0x22); + + assertTrue(TCA.begin()); + assertTrue(TCA.isConnected()); +} + + unittest(test_constants) { assertEqual(0x00, TCA9555_OK);