Skip to content

Commit 7a055f7

Browse files
committed
Merge branch 'pcf8574' of git-barbudor:barbudor/docs into pcf8574
2 parents 1ea0d1c + 2cf039e commit 7a055f7

File tree

8 files changed

+148
-3
lines changed

8 files changed

+148
-3
lines changed

docs/Blinds-and-Shutters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ To enable additional shutters, `ShutterRelay<x> <value>` must be executed for ea
7474

7575
Disabling a shutter in the middle of the defined set of shutters will disable all other higher numbered shutters. If the disabled shutter is restored, the higher numbered shutters previously declared will also be restored. When a shutter is added or removed, a list of the active shutters, with their parameters, is output to the log. If you intend to remove shutters, explicitly remove each one beginning with the highest numbered shutter.
7676

77-
With four shutters, eight `Relay<x>` components are needed. If manual operation switches (`Switch<x>` or `Button<x>` pairs) are also used, additional input GPIO are required. The ESP82xx device may not have enough free GPIO to support all the shutter connections required. A GPIO expander such as a PCF8574 or [MCP230xx](MCP230xx) can be used with additional effort.
77+
With four shutters, eight `Relay<x>` components are needed. If manual operation switches (`Switch<x>` or `Button<x>` pairs) are also used, additional input GPIO are required. The ESP82xx device may not have enough free GPIO to support all the shutter connections required. A GPIO expander such as a [PCF8574](PCF8574) or [MCP230xx](MCP230xx) can be used with additional effort.
7878

7979
Using manual operation `Switch<x>` pairs may require setting `SwitchMode<x> 4` (inverse follow) for proper switch behavior.
8080

docs/Commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ SetOption77<a class="cmnd" id="setoption77"></a>|Do not power off if a slider is
448448
SetOption78<a class="cmnd" id="setoption78"></a>|Version check on Tasmota upgrade<BR>`0` = enabled _(default)_<BR>`1` = disabled
449449
SetOption79<a class="cmnd" id="setoption79"></a>|Reset counters at TelePeriod time<BR>`0` = disabled _(default)_<BR>`1` = enabled
450450
SetOption80<a class="cmnd" id="setoption80"></a>|[Blinds and shutters](Blinds-and-Shutters) support<BR>`0` = disable blinds and shutters support *(default)*<BR>`1` = enable blinds and shutters support
451-
SetOption81<a class="cmnd" id="setoption81"></a>|Set PCF8574 component behavior for all ports<BR>`0` = set as regular state *(default)*<BR>`1` = set as inverted state
451+
SetOption81<a class="cmnd" id="setoption81"></a>|Set [PCF8574](PCF8574) component behavior for all ports<BR>`0` = set as regular state *(default)*<BR>`1` = set as inverted state
452452
SetOption82<a class="cmnd" id="setoption82"></a>|Reduce the CT range from 153..500 to 200.380 to accomodate with Alexa range<BR>`0` = CT ranges from 153 to 500 *(default)*<BR>`1` = CT ranges from 200 to 380 (although you can still set in from 153 to 500)
453453
SetOption83<a class="cmnd" id="setoption83"></a>|Uses Zigbee device friendly name instead of 16 bits short addresses as JSON key when reporting values and commands<BR>`0` = JSON key as short address<BR>`1` = JSON key as friendly name<BR>See [`ZbName <device>,<name>`](#zbname)
454454
SetOption84<a class="cmnd" id="setoption84"></a>|(Experimental) When using AWS IoT, sends a device shadow update (alternative to retained)<BR>`0` = don't update device shadow (default)<BR>`1` = update device shadow<BR>Note: if the `Topic` contains `'/'` they are replaced with `'_'`

docs/PCF8574.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# PCF8574 / PCF8574A GPIO Expander
2+
3+
## TL;DR;
4+
5+
PCF8574 IO expander allows to add up to 32 digital IO pins to Tasmota
6+
7+
!!! Warning
8+
The driver for PCF8574 is not included in any of Tasmota prebuild binaries. See [compiling for PCF8574](#compiling-for-pcf8574).
9+
10+
## Introduction
11+
12+
PCF8574 and PCF8574A are I2C 8-bit IOport extender originally designed by Philips (now NXP) but also
13+
now available from various manufacturer.
14+
15+
* PCF8574 and PCF8574A at [NXP](https://www.nxp.com/docs/en/data-sheet/PCF8574_PCF8574A.pdf)
16+
* [PCF8574](https://www.ti.com/lit/ds/symlink/pcf8574.pdf) and [PCF8574A](https://www.ti.com/lit/ds/symlink/pcf8574a.pdf) at Texas Instruments
17+
18+
As usual when using an electronic part, reading the datasheet is highly recommended as the below
19+
document only focus on Tasmota integration.
20+
21+
A few different breakout boards are available although some are dedicated to be mounted as a backpack on
22+
standard 16x2 or 16x4 LCD displays and are not suitable for general I/Os (but works well with tasmota-display).
23+
24+
![PCF8574 breakout modules](_media/pcf8574_module.png)
25+
26+
* On the left: generic modules suitable for extending IO
27+
* On the right: specific module to control a LCD display (not the purpose of this doc page)
28+
29+
## Supported I2C addresses and number of PCF8574
30+
31+
PCF8574 and PCF8574A are identical functionally and each can be configured to work on 1 of 8 possible I2C address.
32+
PCF8574 can use one address of 0x20 to 0x27 and PCF8574A can use one of 0x38 to 0x3F.
33+
34+
As of today, Tasmota driver supports :
35+
36+
* Up to 4 PCF8574 OR PCF8574A is supported by Tasmota allowing up to 32 additional GPIO pins.
37+
* Addresses 0x27 and 0x38 are excluded to avoid conflict with other I2C peripheral which can't
38+
be differentiated at run-time.
39+
* if USE_MCP230xx_ADDR is defined, this address is reserved for MCP230XX IO expander.
40+
41+
## Enabling the driver
42+
43+
Once the firmware with the PCF8574 driver has been loaded, be sure to have it enabled with `I2Cdriver22 1`.
44+
45+
## Compiling for PCF8574
46+
47+
The PCF8574 driver is not included by default in any Tasmota [build](https://github.com/arendst/Tasmota/blob/development/BUILDS.md).
48+
In order to use it you must [compile](https://tasmota.github.io/docs/Compile-your-build/) your own tasmota build
49+
by adding the following lines to your `user_config_override.h`:
50+
``` c++
51+
#define USE_I2C // Add support for I2C
52+
#define USE_PCF8574 // [I2cDriver2] Enable PCF8574 I/O Expander (I2C addresses 0x20 - 0x26 and 0x39 - 0x3F) (+1k9 code)
53+
// #define USE_PCF8574_SENSOR // enable PCF8574 inputs and outputs in SENSOR message
54+
// #define USE_PCF8574_DISPLAYINPUT // enable PCF8574 inputs display in Web page
55+
// #define USE_PCF8574_MQTTINPUT // enable MQTT message & rule process on input change detection : stat/%topic%/PCF8574_INP = {"Time":"2021-03-07T16:19:23+01:00","PCF8574-1_INP":{"D1":1}}
56+
```
57+
58+
* The first 2 lines are mandatory to enable I2C support and including the driver in the build.
59+
* By default only "outputs" feature are enabled
60+
* The 3 other lines allows to add optional features to support inputs
61+
62+
## PCF8574 configuration
63+
64+
PCF8574 can be configured from Tasmota web GUI in "Configure" => "Configure PCF8574"
65+
![PCF8574 configuration screen](_media/pcf8574_configure.png)
66+
67+
* Each IO port can be configured as Input or Output in a similar way as an native GPIO of the ESP.
68+
* If you are using outputs to drive relays, it is possible to choose if the relay is activated by a
69+
HIGH signal (checkbox "Invert Ports" unchecked) or a LOW signal (checkbox checked). The selection
70+
applies to all output ports. This checkbox can also be controlled by [SetOption81](Commands#setoption81).
71+
72+
Once configuration is complete. It must be saved by clicking on the green "Save" button. Like for
73+
general ESP GPIO configuration, this will trigger a reboot of the ESP.
74+
75+
!!! note
76+
It is not possible to change pin definition at run-time.
77+
78+
## PCF8574 Ouputs
79+
80+
A PCF8574 pin configured as an output support all features of a Tasmora `Relay` component.
81+
82+
* It is assigned a Power index and can be controlled by [Power](Commands#power) command (on, off, toggle).
83+
Power indexes of PCF8574 outputs are assigned after the ESP GPIO configured as `Relay`. For example,
84+
if you have Relay 1 (Power1) to Relay 4 (Power4) configured on the ESP's GPIO, PCF8574 outputs will start at Power5.
85+
* A state text and an on/off button is automatically created on the Web GUI and syncs with the pin state.
86+
* All `Power` features are supported including `PowerOnState`, `PulseTime`, `Blink`, `SetOption0`, ...
87+
88+
![PCF8574 power GUI](_media/pcf8574_powergui.png)
89+
90+
## PCF8574 Inputs
91+
92+
In order to use PCF8574 inputs, you must add at least one of the following build-time option in
93+
your `user_config_override.h`:
94+
95+
``` c++
96+
#define USE_PCF8574_SENSOR // enable PCF8574 inputs and outputs in SENSOR message
97+
#define USE_PCF8574_DISPLAYINPUT // enable PCF8574 inputs display in Web page
98+
#define USE_PCF8574_MQTTINPUT // enable MQTT message & rule process on input change detection : stat/%topic%/PCF8574_INP = {"Time":"2021-03-07T16:19:23+01:00","PCF8574-1_INP":{"D1":1}}
99+
```
100+
101+
### PCF8574 in SENSOR message
102+
103+
Enabling `USE_PCF8574_SENSOR` adds a `PCF8574-xx` field into the JSON payload of the `tele/topic/SENSOR`
104+
message. The form of the message is:
105+
``` json
106+
{"Time":"2021-03-11T19:50:58+01:00","PCF8574-1":{"D0":1,"D1":1,"D2":1,"D3":1,"D4":0,"D5":0,"D6":0,"D7":0}}
107+
```
108+
109+
As you can see, all pins are listed, including both inputs and outputs. The value reported is the
110+
digital level of the pin. If "Invert Ports" has been enabled, `Power ON` will be reported as 0 as
111+
the pin is at a LOW level.
112+
113+
As for any sensor published in the `tele/topic/SENSOR` message, it is possible to use Rules triggers such as:
114+
```
115+
ON tele-PCF8574-1#D0 DO something_with %value% ENDON
116+
```
117+
Numerical operators such as `==` can be used to compare to 0 or 1. See also [change detection](#input-change-detection).
118+
119+
### PCF8574 inputs pins in the Web GUI
120+
121+
Enabling `USE_PCF8574_DISPLAYINPUT` will add the state of PCF8574 inpupts displayed as sensors
122+
in the Web GUI. Outputs are not represented here as they are already shown as Power.
123+
124+
![PCF8574 inputs GUI](_media/pcf8574_inputgui.png)
125+
126+
Value of pin is updated in almost "real-time".
127+
128+
### Input change detection
129+
130+
While reporting the pin level in SENSOR or on the GUI is interresting, it is more interresting to
131+
detect pin change. This is enabled by `USE_PCF8574_MQTTINPUT`. When this feature is enabled at
132+
build time, a test will be performed every 50ms to detect if an input pin has changed. In that case,
133+
Tasmota will publish on `stat/topic/PCF8574_INP` a JSON payload with the PCF8574 index
134+
and the pin level:
135+
``` json
136+
20:19:39.385 MQT: stat/topic/PCF8574_INP = {"Time":"2021-03-11T20:19:39+01:00","PCF8574-1_INP":{"D0":0}}
137+
20:19:39.584 MQT: stat/topic/PCF8574_INP = {"Time":"2021-03-11T20:19:39+01:00","PCF8574-1_INP":{"D0":1}}
138+
```
139+
140+
This can be catched in rules such as:
141+
142+
* Implementing a Power push "Button":
143+
``` haskel
144+
ON PCF8574-1_INP#D0=0 DO Power2 toggle ENDON
145+
```

docs/Supported-Peripherals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Name|Description
6565
[**PAJ7620**](PAJ7620) | Gesture & Proximity Detection Sensor
6666
[**PIR**](PIR-Motion-Sensors#am312) | Passive Infrared Sensor (gpio)
6767
[**PCA9685**](PCA9685) | 16-channel, 12-bit PWM LED controller (I^2^C)
68-
**PCF8574** | 8-port IO Expander (I^2^C)
68+
[**PCF8574(A)**](PCF8574) 8-port IO Expander (I^2^C)
6969
**PMS3003<BR>[PMS5003](https://www.superhouse.tv/38-diy-air-quality-Sensor-part-1-basic-model/)<BR>PMS7003** | Particle Concentration Sensor (serial)
7070
[**PN532**](PN532) | NFC/RFID controller
7171
[**PZEM-004<BR>PZEM-016**](PZEM-0XX) | Energy Monitor (serial)

docs/_media/pcf8574_configure.png

18.5 KB
Loading

docs/_media/pcf8574_inputgui.png

2.43 KB
Loading

docs/_media/pcf8574_module.png

159 KB
Loading

docs/_media/pcf8574_powergui.png

3.92 KB
Loading

0 commit comments

Comments
 (0)