Skip to content

Commit

Permalink
fix #7 + getAddress() + update examples (#8)
Browse files Browse the repository at this point in the history
* fix #7 + getAddress() + update examples
  • Loading branch information
RobTillaart committed Dec 29, 2022
1 parent e0f18ea commit 5bf06af
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jsoncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 42 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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?
8 changes: 7 additions & 1 deletion TCA9555.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -55,6 +55,12 @@ bool TCA9555::isConnected()
}


uint8_t TCA9555::getAddress()
{
return _address;
}


//////////////////////////////////////////////////////////
//
// 1 PIN INTERFACE
Expand Down
6 changes: 4 additions & 2 deletions TCA9555.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -34,6 +34,7 @@ class TCA9555
#endif
bool begin();
bool isConnected();
uint8_t getAddress();


// 1 PIN INTERFACE
Expand Down Expand Up @@ -87,6 +88,7 @@ class TCA9555
//
class TCA9535 : public TCA9555
{
public:
TCA9535(uint8_t address, TwoWire *wire = &Wire);
};

Expand Down
41 changes: 41 additions & 0 deletions examples/TCA9535_digitalRead/TCA9535_digitalRead.ino
Original file line number Diff line number Diff line change
@@ -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 --

65 changes: 65 additions & 0 deletions examples/TCA9535_digitalWrite/TCA9535_digitalWrite.ino
Original file line number Diff line number Diff line change
@@ -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 --
4 changes: 2 additions & 2 deletions examples/TCA9555_digitalRead/TCA9555_digitalRead.ino
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
4 changes: 2 additions & 2 deletions examples/TCA9555_digitalWrite/TCA9555_digitalWrite.ino
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
4 changes: 2 additions & 2 deletions examples/TCA9555_setPolarity/TCA9555_setPolarity.ino
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TCA9555
version=0.1.3
version=0.1.4
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for I2C TCA9555 16 channel port expander - 16 IO-lines
Expand Down
Loading

0 comments on commit 5bf06af

Please sign in to comment.