Skip to content

Commit f97e507

Browse files
committed
0.4.2 PCF8574
1 parent 1d7e0f8 commit f97e507

File tree

7 files changed

+63
-54
lines changed

7 files changed

+63
-54
lines changed

libraries/PCF8574/CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ 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.2] - 2025-04-18
10+
- sync last commits
11+
- update readme.md
12+
13+
914
## [0.4.1] - 2023-09-23
1015
- Update readme with advanced interrupts insights
1116
- kudos to ddowling for testing.
1217
- add example
1318
- fix URL examples
1419
- add Wire1 example (ESP32 + RP2040)
1520

16-
1721
## [0.4.0] - 2023-09-23
1822
- refactor API, begin()
1923
- update readme.md
@@ -39,7 +43,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3943
## [0.3.6] - 2022-10-19
4044
- fix example PCF8574_rotaryEncoder.ino
4145
- add RP2040 to build-CI
42-
- simplified changelog.md
46+
- simplified changelog.md
4347

4448
## [0.3.5] - 2022-06-17
4549
- add select(), selectN(), selectNone() and selectAll()
@@ -49,7 +53,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4953
- add CHANGELOG.md
5054
- fix **begin(int sda, int scl)** int parameters for ESP alike.
5155

52-
## [0.3.3] - 2021-12-23
56+
## [0.3.3] - 2021-12-23
5357
- update library.json, license, readme, minor edits
5458

5559
## [0.3.2] - 2021-07-04
@@ -91,7 +95,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
9195
- Fix/refactor ButtonRead8() - see https://github.com/RobTillaart/Arduino/issues/38
9296
- missing begin() => mask parameter
9397

94-
## [0.1.07] - 2016-05-02
98+
## [0.1.07] - 2016-05-02
9599
- (manually merged) Septillion
96100
- added dataOut so a write() doesn't read first,
97101
possibly corrupting a input pin;

libraries/PCF8574/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2013-2024 Rob Tillaart
3+
Copyright (c) 2013-2025 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libraries/PCF8574/PCF8574.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// FILE: PCF8574.cpp
33
// AUTHOR: Rob Tillaart
44
// DATE: 02-febr-2013
5-
// VERSION: 0.4.1
5+
// VERSION: 0.4.2
66
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
77
// URL: https://github.com/RobTillaart/PCF8574
88
// http://forum.arduino.cc/index.php?topic=184800
@@ -12,14 +12,8 @@
1212

1313

1414
PCF8574::PCF8574(const uint8_t deviceAddress, TwoWire *wire)
15-
{
16-
_address = deviceAddress;
17-
_wire = wire;
18-
_dataIn = 0;
19-
_dataOut = 0xFF;
20-
_buttonMask = 0xFF;
21-
_error = PCF8574_OK;
22-
}
15+
: _address {deviceAddress}, _wire {wire}
16+
{}
2317

2418

2519
bool PCF8574::begin(uint8_t value)
@@ -36,20 +30,12 @@ bool PCF8574::isConnected()
3630
return ( _wire->endTransmission() == 0);
3731
}
3832

39-
4033
bool PCF8574::setAddress(const uint8_t deviceAddress)
4134
{
4235
_address = deviceAddress;
4336
return isConnected();
4437
}
4538

46-
47-
uint8_t PCF8574::getAddress()
48-
{
49-
return _address;
50-
}
51-
52-
5339
// removed _wire->beginTransmission(_address);
5440
// with @100 KHz -> 265 micros()
5541
// without @100 KHz -> 132 micros()

libraries/PCF8574/PCF8574.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// FILE: PCF8574.h
44
// AUTHOR: Rob Tillaart
55
// DATE: 02-febr-2013
6-
// VERSION: 0.4.1
6+
// VERSION: 0.4.2
77
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
88
// URL: https://github.com/RobTillaart/PCF8574
99
// http://forum.arduino.cc/index.php?topic=184800
@@ -13,7 +13,7 @@
1313
#include "Wire.h"
1414

1515

16-
#define PCF8574_LIB_VERSION (F("0.4.1"))
16+
#define PCF8574_LIB_VERSION (F("0.4.2"))
1717

1818
#ifndef PCF8574_INITIAL_VALUE
1919
#define PCF8574_INITIAL_VALUE 0xFF
@@ -27,7 +27,7 @@
2727
class PCF8574
2828
{
2929
public:
30-
explicit PCF8574(const uint8_t deviceAddress = 0x20, TwoWire *wire = &Wire);
30+
PCF8574(const uint8_t deviceAddress = 0x20, TwoWire *wire = &Wire);
3131

3232
bool begin(uint8_t value = PCF8574_INITIAL_VALUE);
3333
bool isConnected();
@@ -36,8 +36,7 @@ class PCF8574
3636
// note: setting the address corrupt internal buffer values
3737
// a read8() / write8() call updates them.
3838
bool setAddress(const uint8_t deviceAddress);
39-
uint8_t getAddress();
40-
39+
uint8_t getAddress() const { return _address; }
4140

4241
uint8_t read8();
4342
uint8_t read(const uint8_t pin);
@@ -54,7 +53,7 @@ class PCF8574
5453
uint8_t readButton8(const uint8_t mask);
5554
uint8_t readButton(const uint8_t pin);
5655
void setButtonMask(const uint8_t mask) { _buttonMask = mask; };
57-
uint8_t getButtonMask() { return _buttonMask; };
56+
uint8_t getButtonMask() const { return _buttonMask; };
5857

5958

6059
// rotate, shift, toggle, reverse expect all lines are output
@@ -78,11 +77,12 @@ class PCF8574
7877

7978

8079
private:
80+
int _error {PCF8574_OK};
8181
uint8_t _address;
82-
uint8_t _dataIn;
83-
uint8_t _dataOut;
84-
uint8_t _buttonMask;
85-
int _error;
82+
uint8_t _dataIn {0};
83+
uint8_t _dataOut {0xFF};
84+
uint8_t _buttonMask {0xFF};
85+
8686

8787
TwoWire* _wire;
8888
};

libraries/PCF8574/README.md

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ Arduino library for PCF8574 - 8 channel I2C IO expander.
1616

1717
## Description
1818

19-
Related to the PCF8575 16 channel IO expander library https://github.com/RobTillaart/PCF8575
20-
2119
This library gives easy control over the 8 pins of a PCF8574 and PCF8574A chip.
2220
These chips are identical in behaviour although there are two distinct address ranges.
2321

@@ -36,7 +34,7 @@ The library allows to read and write both single pins or 8 pins at once.
3634
Furthermore some additional functions are implemented that are playful and useful.
3735

3836

39-
#### Interrupts intro
37+
### Interrupts intro
4038

4139
The PCF8574 has an interrupt output line (INT) to notify an MCU that one of the input lines has changed.
4240
This can be used to prevent active polling of the PCF8574, which can be more efficient.
@@ -61,7 +59,7 @@ In practice if you have faster polling than your signals changes this would not
6159
be a problem. E.g. tactile switches and a polling frequency > 100 Hz will work.
6260

6361

64-
#### Interrupts library
62+
### Interrupts library
6563

6664
The library cannot handle the PCF8574 interrupts as it has no code for it.
6765
The user should catch the interrupt in his own code to set a flag and can use
@@ -84,7 +82,7 @@ A minimal example that shows catching missed interrupts:
8482
- **PCF8574_interrupt_advanced.ino**
8583

8684

87-
#### 0.4.0 Breaking change
85+
### 0.4.0 Breaking change
8886

8987
Version 0.4.0 introduced a breaking change.
9088
You cannot set the pins in **begin()** any more.
@@ -93,24 +91,27 @@ The user has to call **Wire.begin()** and can optionally set the Wire pins
9391
before calling **begin()**.
9492

9593

96-
#### Related
94+
### Related
9795

9896
16 bit port expanders
9997

100-
- https://github.com/RobTillaart/MCP23017_RT
101-
- https://github.com/RobTillaart/MCP23S17
102-
- https://github.com/RobTillaart/PCA9671
103-
- https://github.com/RobTillaart/PCF8575
98+
- https://github.com/RobTillaart/MCP23017_RT I2C 16 IO lines.
99+
- https://github.com/RobTillaart/MCP23S17 SPI 16 IO lines.
100+
- https://github.com/RobTillaart/PCF8575 I2C 16 IO lines.
101+
- https://github.com/RobTillaart/PCA9671 I2C 16 IO lines. - successor PCF8575
104102

105103

106104
8 bit port expanders
107105

108-
- https://github.com/RobTillaart/MCP23008
109-
- https://github.com/RobTillaart/MCP23S08
110-
- https://github.com/RobTillaart/PCF8574
106+
- https://github.com/RobTillaart/MCP23008 I2C 8 IO lines.
107+
- https://github.com/RobTillaart/MCP23S08 SPI 8 IO lines.
108+
- https://github.com/RobTillaart/PCF8574 I2C 8 IO lines.
109+
111110

111+
## I2C
112112

113-
## I2C Clock
113+
114+
### Performance
114115

115116
Tested on UNO with **PCF8574_performance** showed that the PCF8574 still works at 500 KHz and failed at 600 KHz.
116117
These values are outside the specs of the datasheet so they are not recommended.
@@ -126,6 +127,24 @@ However when performance is needed you can try to overclock the chip.
126127
| 600000 | crash | crash |
127128

128129

130+
### I2C multiplexing
131+
132+
Sometimes you need to control more devices than possible with the default
133+
address range the device provides.
134+
This is possible with an I2C multiplexer e.g. TCA9548 which creates up
135+
to eight channels (think of it as I2C subnets) which can use the complete
136+
address range of the device.
137+
138+
Drawback of using a multiplexer is that it takes more administration in
139+
your code e.g. which device is on which channel.
140+
This will slow down the access, which must be taken into account when
141+
deciding which devices are on which channel.
142+
Also note that switching between channels will slow down other devices
143+
too if they are behind the multiplexer.
144+
145+
- https://github.com/RobTillaart/TCA9548
146+
147+
129148
## Interface
130149

131150
```cpp
@@ -136,7 +155,7 @@ However when performance is needed you can try to overclock the chip.
136155
the include of "pcf8574.h" to overrule the default value used with the **begin()** call.
137156

138157

139-
#### Constructor
158+
### Constructor
140159

141160
- **PCF8574(uint8_t deviceAddress = 0x20, TwoWire \*wire = &Wire)** Constructor with optional address, default 0x20,
142161
and the optional Wire interface as parameter.
@@ -148,7 +167,7 @@ so one might need to call **read8()** and/or **write8()**. Returns true if addre
148167
- **uint8_t getAddress()** Returns the device address.
149168

150169

151-
#### Read and Write
170+
### Read and Write
152171

153172
- **uint8_t read8()** reads all 8 pins at once. This one does the actual reading.
154173
- **uint8_t read(uint8_t pin)** reads a single pin; pin = 0..7
@@ -160,7 +179,7 @@ value is HIGH(1) or LOW (0)
160179
- **uint8_t valueOut()** returns the last written data.
161180

162181

163-
#### Button
182+
### Button
164183

165184
The **"button"** functions are to be used when you mix input and output on one IC.
166185
It does not change / affect the pins used for output by masking these.
@@ -177,7 +196,7 @@ Note this can be a subset of the pins set with **setButtonMask()** if one wants
177196
Background - https://github.com/RobTillaart/Arduino/issues/38
178197

179198

180-
#### Special
199+
### Special
181200

182201
- **void toggle(const uint8_t pin)** toggles a single pin
183202
- **void toggleMask(const uint8_t mask = 0xFF)** toggles a selection of pins,
@@ -191,7 +210,7 @@ Fills the lower lines with zero's.
191210
- **void reverse()** reverse the "bit pattern" of the lines, swapping pin 7 with 0, 6 with 1, 5 with 2 etc.
192211

193212

194-
#### Select
213+
### Select
195214

196215
Some convenience wrappers.
197216

@@ -205,7 +224,7 @@ This can typical be used to implement a VU meter.
205224
- **void selectAll()** sets all pins to HIGH.
206225

207226

208-
#### Miscellaneous
227+
### Miscellaneous
209228

210229
- **int lastError()** returns the last error from the lib. (see .h file).
211230

libraries/PCF8574/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/PCF8574.git"
1717
},
18-
"version": "0.4.1",
18+
"version": "0.4.2",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

libraries/PCF8574/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=PCF8574
2-
version=0.4.1
2+
version=0.4.2
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=Arduino library for PCF8574 - 8 channel I2C IO expander

0 commit comments

Comments
 (0)