Skip to content

Commit d0fac87

Browse files
committed
0.4.3 TCA9555
1 parent 1f26ff8 commit d0fac87

File tree

16 files changed

+389
-59
lines changed

16 files changed

+389
-59
lines changed

libraries/TCA9555/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.4.3] - 2025-05-05
10+
- updated examples after HW test
11+
- add TCA9555_blink.ino
12+
- add TCA9555_performance.ino
13+
- minor edits
14+
915
## [0.4.2] - 2025-04-17
1016
- update readme.md
1117
- add derived class CAT9555

libraries/TCA9555/README.md

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ Arduino library for TCA9555 16 channel I2C port expander.
1616

1717
## Description
1818

19-
This library gives easy control over the 16 pins of a TCA9555 chip.
19+
This library gives easy control over the 16 pins of a TCA9555 device.
2020

2121
The pins can be used for INPUT (default) and OUTPUT, and allow to set polarity.
2222

2323
The pins can be set per single pin, or with a mask to set either 8 or 16 pins
2424
in one call.
2525
Note that for the 16 bit interface settings are not perfectly simultaneous
26-
as the 16 bit interface does in fact 2 calls to the 8 bit interface.
26+
as the 16 bit interface does in fact 2 calls to the 8 bit interface.
27+
28+
The TCA9555 has an interrupt pin, however the library does not support this.
2729

2830

2931
### TCA9535
@@ -58,18 +60,19 @@ Feedback of working types is welcome.
5860

5961
16 bit port expanders
6062

61-
- https://github.com/RobTillaart/MCP23017_RT
62-
- https://github.com/RobTillaart/MCP23S17 (SPI)
63-
- https://github.com/RobTillaart/PCA9671
64-
- https://github.com/RobTillaart/PCF8575
65-
- https://github.com/RobTillaart/TCA9555
63+
- https://github.com/RobTillaart/MCP23017_RT I2C 16 IO lines.
64+
- https://github.com/RobTillaart/MCP23S17 SPI 16 IO lines.
65+
- https://github.com/RobTillaart/PCF8575 I2C 16 IO lines.
66+
- https://github.com/RobTillaart/PCA9671 I2C 16 IO lines. - successor PCF8575
67+
- https://github.com/RobTillaart/TCA9555 I2C 16 IO lines.
68+
6669

6770
8 bit port expanders
6871

69-
- https://github.com/RobTillaart/MCP23008
70-
- https://github.com/RobTillaart/MCP23S08 (SPI)
71-
- https://github.com/RobTillaart/PCF8574
72-
- https://github.com/RobTillaart/TCA9554
72+
- https://github.com/RobTillaart/MCP23008 I2C 8 IO lines.
73+
- https://github.com/RobTillaart/MCP23S08 SPI 8 IO lines.
74+
- https://github.com/RobTillaart/PCF8574 I2C 8 IO lines.
75+
- https://github.com/RobTillaart/TCA9554 I2C 8 IO lines.
7376

7477

7578
### 0.3.0 Breaking change
@@ -131,10 +134,34 @@ too if they are behind the multiplexer.
131134
- https://github.com/RobTillaart/TCA9548
132135

133136

137+
### I2C Performance
138+
139+
Tested with TCA9555_performance.ino + UNO 0.4.3
140+
141+
Note above 800 I2C fails, up to 800 KHz seems OK.
142+
143+
144+
| CLOCK | read1 | read8 | read16 | write1 | write8 | write16 |
145+
|:-------:|:--------:|:--------:|:---------:|:--------:|:--------:|:---------:|
146+
| 50 | 860.16 | 860.16 | 1720.32 | 860.16 | 619.64 | 1239.24 |
147+
| 100 | 463.65 | 463.52 | 926.19 | 464.67 | 334.57 | 669.16 |
148+
| 200 | 267.16 | 267.16 | 534.27 | 267.17 | 191.75 | 382.86 |
149+
| 300 | 196.83 | 196.80 | 393.46 | 195.89 | 141.23 | 281.26 |
150+
| 400 | 169.58 | 169.55 | 335.65 | 168.63 | 119.48 | 238.75 |
151+
| 500 | 147.34 | 147.34 | 294.45 | 147.91 | 104.74 | 208.94 |
152+
| 600 | 137.38 | 137.36 | 274.30 | 137.76 | 96.87 | 194.70 |
153+
| 700 | 129.12 | 129.12 | 257.11 | 130.34 | 91.43 | 182.86 |
154+
| 800 | 124.89 | 124.88 | 249.77 | 125.39 | 87.87 | 175.54 |
155+
| 900 | 48.78 | 48.76 | 97.55 | 100.94 | 52.38 | 104.50 |
156+
157+
134158
### INT pin interrupts
135159

136160
The interrupt pin is not supported by the library.
137-
Needs investigation (+ examples).
161+
There is an example showing how interrupts can be used.
162+
163+
Note that the device generates interrupts on **CHANGING** pins,
164+
so no option to select falling or rising.
138165

139166

140167
## Interface
@@ -230,28 +257,27 @@ Reading it will reset the flag to **TCA9555_OK**.
230257
#### Must
231258

232259
- update documentation
233-
- buy TCA9555 / TCA9535 / PCA9555 / PCA9535
234-
- test all functionality
235260
- keep TCA9554/TCA9555 in sync
236261

237262
#### Should
238263

239-
- investigate INT = interrupt pin
264+
- investigate optimizing the "16 pins" interface.
265+
- read /write multiple bytes in one call, is it supported? (YES!)
266+
- expected gain ~33%
267+
- **setPolarity()** ==> **setPolarity1()** ? get idem.
268+
- uniformity
240269
- investigate map INPUT_PULLUP on INPUT (pinMode ?)
241270
- investigate internal pull up etc.
242271
- investigate TCA9535 differences
243272
- pull up resistors
244273
- elaborate derived class
245-
- **setPolarity()** ==> **setPolarity1()** ? get idem.
246-
- uniformity
247274

248275
#### Could
249276

250277
- rethink class hierarchy
251278
- TCA9535 has less functions so should be base class
252279
- add performance example for I2C.
253-
- investigate optimizing the "16 pins" interface.
254-
- read /write multiple bytes in one call, is it supported?
280+
- buy TCA9535 / PCA9555 / PCA9535 to test
255281

256282
#### Wont (unless)
257283

libraries/TCA9555/TCA9555.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: TCA9555.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.4.2
4+
// VERSION: 0.4.3
55
// PURPOSE: Arduino library for I2C TCA9555 16 channel port expander
66
// DATE: 2021-06-09
77
// URL: https://github.com/RobTillaart/TCA9555
@@ -63,6 +63,8 @@ uint8_t TCA9555::getAddress()
6363
//
6464
// 1 PIN INTERFACE
6565
//
66+
// pin = 0..15
67+
// mode = INPUT, OUTPUT
6668
bool TCA9555::pinMode1(uint8_t pin, uint8_t mode)
6769
{
6870
if (pin > 15)
@@ -95,6 +97,8 @@ bool TCA9555::pinMode1(uint8_t pin, uint8_t mode)
9597
}
9698

9799

100+
// pin = 0..15
101+
// value = LOW(0), HIGH(not 0)
98102
bool TCA9555::write1(uint8_t pin, uint8_t value)
99103
{
100104
if (pin > 15)
@@ -111,7 +115,7 @@ bool TCA9555::write1(uint8_t pin, uint8_t value)
111115
uint8_t val = readRegister(OPR);
112116
uint8_t prevVal = val;
113117
uint8_t mask = 1 << pin;
114-
if (value) val |= mask; // all values are HIGH.
118+
if (value) val |= mask; // all values <> 0 are HIGH.
115119
else val &= ~mask;
116120
if (val != prevVal)
117121
{
@@ -122,7 +126,8 @@ bool TCA9555::write1(uint8_t pin, uint8_t value)
122126
}
123127

124128

125-
uint8_t TCA9555::read1(uint8_t pin) // pin = 0..15
129+
// pin = 0..15
130+
uint8_t TCA9555::read1(uint8_t pin)
126131
{
127132
if (pin > 15)
128133
{
@@ -143,6 +148,8 @@ uint8_t TCA9555::read1(uint8_t pin) // pin = 0..15
143148
}
144149

145150

151+
// pin = 0..15
152+
// value = LOW(0), HIGH ?
146153
bool TCA9555::setPolarity(uint8_t pin, uint8_t value)
147154
{
148155
if (pin > 15)
@@ -175,6 +182,7 @@ bool TCA9555::setPolarity(uint8_t pin, uint8_t value)
175182
}
176183

177184

185+
// pin = 0..15
178186
uint8_t TCA9555::getPolarity(uint8_t pin)
179187
{
180188
if (pin > 15)
@@ -194,6 +202,7 @@ uint8_t TCA9555::getPolarity(uint8_t pin)
194202
//
195203
// 8 PIN INTERFACE
196204
//
205+
// port = 0..1
197206
bool TCA9555::pinMode8(uint8_t port, uint8_t mask)
198207
{
199208
if (port > 1)
@@ -207,7 +216,9 @@ bool TCA9555::pinMode8(uint8_t port, uint8_t mask)
207216
}
208217

209218

210-
bool TCA9555::write8(uint8_t port, uint8_t mask) // port = 0..1
219+
// port = 0..1
220+
// mask = 0x00..0xFF
221+
bool TCA9555::write8(uint8_t port, uint8_t mask)
211222
{
212223
if (port > 1)
213224
{
@@ -220,6 +231,7 @@ bool TCA9555::write8(uint8_t port, uint8_t mask) // port = 0..1
220231
}
221232

222233

234+
// port = 0..1
223235
int TCA9555::read8(uint8_t port)
224236
{
225237
if (port > 1)
@@ -233,6 +245,8 @@ int TCA9555::read8(uint8_t port)
233245
}
234246

235247

248+
// port = 0..1
249+
// mask = 0x00..0xFF
236250
bool TCA9555::setPolarity8(uint8_t port, uint8_t mask)
237251
{
238252
if (port > 1)
@@ -246,6 +260,7 @@ bool TCA9555::setPolarity8(uint8_t port, uint8_t mask)
246260
}
247261

248262

263+
// port = 0..1
249264
uint8_t TCA9555::getPolarity8(uint8_t port)
250265
{
251266
if (port > 1)
@@ -263,6 +278,7 @@ uint8_t TCA9555::getPolarity8(uint8_t port)
263278
//
264279
// 16 PIN INTERFACE
265280
//
281+
// mask = 0x0000..0xFFFF
266282
bool TCA9555::pinMode16(uint16_t mask)
267283
{
268284
bool b = true;
@@ -272,6 +288,7 @@ bool TCA9555::pinMode16(uint16_t mask)
272288
}
273289

274290

291+
// mask = 0x0000..0xFFFF
275292
bool TCA9555::write16(uint16_t mask)
276293
{
277294
bool b = true;
@@ -290,6 +307,7 @@ uint16_t TCA9555::read16()
290307
}
291308

292309

310+
// mask = 0x0000..0xFFFF
293311
bool TCA9555::setPolarity16(uint16_t mask)
294312
{
295313
bool b = true;

libraries/TCA9555/TCA9555.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: TCA9555.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.4.2
5+
// VERSION: 0.4.3
66
// PURPOSE: Arduino library for I2C TCA9555 16 channel port expander
77
// DATE: 2021-06-09
88
// URL: https://github.com/RobTillaart/TCA9555
@@ -12,7 +12,7 @@
1212
#include "Wire.h"
1313

1414

15-
#define TCA9555_LIB_VERSION (F("0.4.2"))
15+
#define TCA9555_LIB_VERSION (F("0.4.3"))
1616

1717
#define TCA9555_OK 0x00
1818
#define TCA9555_PIN_ERROR 0x81

libraries/TCA9555/examples/TCA9535_digitalRead/TCA9535_digitalRead.ino

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "TCA9555.h"
99

10-
10+
// adjust address if needed
1111
TCA9535 TCA(0x27);
1212

1313

@@ -26,21 +26,21 @@ void setup()
2626
Serial.println("Set pinMode16 INPUT");
2727
TCA.pinMode16(0xFFFF);
2828

29+
Serial.println("TEST read1(pin)");
30+
}
31+
2932

33+
void loop()
34+
{
3035
Serial.println("TEST read1(pin)");
3136
for (int pin = 0; pin < 16; pin++)
3237
{
3338
int val = TCA.read1(pin);
3439
Serial.print(val);
35-
Serial.print('\t');
40+
Serial.print(' ');
3641
}
3742
Serial.println();
38-
Serial.println("\ndone...");
39-
}
40-
41-
42-
void loop()
43-
{
43+
delay(1000);
4444
}
4545

4646

libraries/TCA9555/examples/TCA9535_digitalWrite/TCA9535_digitalWrite.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "TCA9555.h"
99

10-
10+
// adjust address if needed
1111
TCA9535 TCA(0x27);
1212

1313

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// FILE: TCA9555_blink.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: quick test TCA9555
5+
// URL: https://github.com/RobTillaart/TCA9555
6+
7+
8+
#include "TCA9555.h"
9+
10+
// adjust address if needed
11+
TCA9555 TCA(0x20);
12+
13+
14+
void setup()
15+
{
16+
Serial.begin(115200);
17+
Serial.println(__FILE__);
18+
Serial.print("TCA9555_LIB_VERSION: ");
19+
Serial.println(TCA9555_LIB_VERSION);
20+
Serial.println();
21+
22+
Wire.begin();
23+
TCA.begin();
24+
25+
Wire.setClock(50000);
26+
27+
Serial.println("pinMode16(0x0000)");
28+
TCA.pinMode16(0x0000);
29+
}
30+
31+
32+
void loop()
33+
{
34+
TCA.write16(0xFFFF);
35+
Serial.println("HIGH");
36+
delay(2000);
37+
38+
TCA.write16(0x0000);
39+
Serial.println("LOW");
40+
delay(1000);
41+
Serial.println();
42+
}
43+
44+
45+
// -- END OF FILE --

0 commit comments

Comments
 (0)