Skip to content

Commit 9fae267

Browse files
committed
Add support for 16 Channel I2C Electromagnetic Relay Module IoT
Using PCF8575 chip
1 parent 4c5c7bd commit 9fae267

File tree

9 files changed

+127
-11
lines changed

9 files changed

+127
-11
lines changed

docs/_hardware/16-channel_relay.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: 16 Channel I2C Electromagnetic Relay Module IoT
3+
categories: [Hardware, Relay]
4+
tags: [relay, i2c, 16channel]
5+
6+
image:
7+
path: /assets/img/16 Channel I2C Electromagnetic Relay Module PCF8575.webp
8+
src: /assets/img/16 Channel I2C Electromagnetic Relay Module PCF8575.webp
9+
alt: '16 Channel I2C Electromagnetic Relay Module PCF8575 header image'
10+
11+
device_hardware: GPIO
12+
device_address:
13+
'Enter the IO Expender type, the relay number (starting at 1), and then the
14+
I2C address with optional I2C bus number: `pcf8575-1,0x4c,3`'
15+
---
16+
17+
## Information
18+
19+
The IOT Electronic 16 Channel I2C Solid State Relay Module provides 16 isolated
20+
channels for Arduino and Raspberry projects, supporting 100-240V AC control.
21+
22+
This IOT Electronic 16 Channel I2C Solid State Relay Module offers robust
23+
control for your microcontroller projects. Designed for compatibility with
24+
Arduino, Raspberry, and other microcontrollers, it provides 16 isolated solid
25+
state relay channels.
26+
27+
### Key Features
28+
29+
- Control 16 independent channels using an I2C interface.
30+
- Built around the efficient **PCF8575** I2C expander chip.
31+
- Designed for compatibility with Arduino, Raspberry, and various
32+
microcontrollers.
33+
34+
### Device Specifications
35+
36+
- PCB Board Dimension: 210mm x 72mm
37+
- Compatibility: DRG-01 DIN rail plastic holder
38+
- Isolation: Full opto and air isolation from high voltage
39+
- Operation DC Voltage: 3.3V and 5.0V
40+
- Maximum Current @5.0V: 450mA
41+
- AC Controlling Voltage Range: 100…240VAC
42+
- AC Voltage Frequency Range: 50…60Hz
43+
- Minimum AC Current per Channel: 30mA
44+
- Maximum AC Current per Channel: 2A
45+
- I2C Device Slave Address: Changeable
46+
- Expandability: Connect up to 8 devices to one I2C bus, controlling up to 128
47+
channels
48+
- Indicators: Red LED indicators for each SSR relay channel
49+
50+
This versatile relay module simplifies projects requiring multiple high-voltage
51+
switching capabilities. Its I2C interface allows for easy integration and
52+
expansion, enabling control of up to 128 channels with multiple modules. The
53+
opto and air isolation ensure safety and reliability when dealing with AC loads
54+
up to 240V, making the IOT Electronic 16 Channel I2C Solid State Relay Module an
55+
excellent choice for demanding applications.
56+
57+
### Ideal for
58+
59+
- Makers and hobbyists working with Arduino and Raspberry Pi.
60+
- Automation projects requiring multi-channel AC switching.
61+
- Industrial control applications needing isolated relay outputs.
62+
- Projects where space-saving and expandability are crucial.
63+
- Electronics enthusiasts building custom control systems.
64+
65+
[16 Channel I2C Electromagnetic Relay Module PCF8575](https://www.tindie.com/products/bugrovs2012/16-channel-i2c-electromagnetic-relay-module-iot/#product-description)
66+
67+
{% include_relative _relay_detail.md %}

docs/_hardware/hd30a-4-channel_relay.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: HD30A 4 Channel Electromagnetic I2C Relay 12V 30A
2+
title: HD30A 4/8 Channel Electromagnetic I2C Relay 12V 30A
33
categories: [Hardware, Relay]
4-
tags: [relay, HD30A]
4+
tags: [relay, HD30A, 4channel, 8channel]
55

66
image:
77
path: /assets/img/HD30A_4_Channel_Electromagnetic_I2C_Relay_12V_30A.webp
@@ -43,4 +43,7 @@ are used quality screw terminals KF-128-3P. Each relay is indicated with led
4343

4444
[HD30A 4CH/8CH Channel Electromagnetic relay](https://www.tindie.com/products/bugrovs2012/hd30a-4-channel-electromagnetic-i2c-relay-12v-30a/)
4545

46+
Other relay boards with a **PCF8574** chip should work.
47+
[8 Channel I2C Electromagnetic Relay Module](https://www.tindie.com/products/bugrovs2012/8-channel-i2c-electromagnetic-relay-module/)
48+
4649
{% include_relative _relay_detail.md %}

docs/_hardware/io-expander.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: IO Expander
33
categories: [Hardware, Button, I2C]
4-
tags: [button, expander, pcf8574]
4+
tags: [button, expander, pcf8574, pcf8575]
55
permalink: /hardware/io-expander/
66

77
image:
@@ -10,19 +10,26 @@ image:
1010
alt: 'PCF8574 IO Expander'
1111
---
1212

13-
With the IO expander pcf8574 you can add more GPIO
13+
With the IO expander pcf8574/5 you can add more GPIO
1414
[relays](/TerrariumPI/hardware/#relays) and
1515
[buttons](/TerrariumPI/hardware/#buttons) to TerrariumPI. This IO expander does
1616
only support on/off actions. So it is not possible to use this IO expander with
1717
a DHT sensor. You cannot read out the extra GPIO ports.
1818

19+
## PCF8575 Bug
20+
21+
At the moment it is **not** possible to use a pcf8575 IO expander to add more
22+
buttons. Due to a
23+
[bug in the used library](https://github.com/rp3tya/PCF8575/issues/5), we can
24+
only support [relays](/TerrariumPI/hardware/#relays) with this IO expander.
25+
1926
## Addressing
2027

2128
In order to use this IO expander, enter the following address in the GPIO relay
2229
or button address field.\
23-
`pcf8574-<IO expander port>,<I2C Address>,[I2C Bus number]`
30+
`pcf857[4/5]-<IO expander port>,<I2C Address>,[I2C Bus number]`
2431

25-
`<IO expander port>` is mandatory and is a number from 1 till max ports.
32+
`<IO expander port>` is mandatory and is a number from **1** till max ports.
2633

2734
`<I2C Address>` is mandatory and specified
2835
[here](/TerrariumPI/hardware/#i2c-bus).

docs/_tabs/hardware.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Either use [pcf857**4**](/TerrariumPI/hardware/io-expander/) or
100100
[pcf857**5**](/TerrariumPI/hardware/io-expander/) to select the used IO
101101
expander.
102102

103-
`<IO expander port>` is mandatory and is a number from 0 till max ports - 1.
103+
`<IO expander port>` is mandatory and is a number from **1** till max ports.
104104

105105
`<I2C Address>` is mandatory and specified [here](#i2c-bus).
106106

31.6 KB
Loading

hardware/button/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ def __init__(self, button_id, _, address, name="", callback=None):
6666
"Create a new button based on type"
6767

6868
self._device = {"device": None, "id": None, "address": None, "name": None, "state": None}
69-
7069
self._checker = {"running": False, "thread": None}
71-
7270
self._inverse = False
7371

7472
self.id = button_id

hardware/io_expander.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
# pip install i2crelay (git)
88
from i2crelay import I2CRelayBoard
9+
# pip install pcf8575
10+
from pcf8575 import PCF8575
911

1012

1113
class terrariumIOExpanderException(TypeError):
@@ -18,7 +20,7 @@ class terrariumIOExpander(object):
1820

1921
@classproperty
2022
def available_hardware(__cls__):
21-
return {"PCF8574": lambda: terrariumPCF8574IOExpander}
23+
return {"PCF8574": lambda: terrariumPCF8574IOExpander, "PCF8575": lambda: terrariumPCF8575IOExpander}
2224

2325
# Return polymorph IO expander....
2426
def __new__(cls, hardware_type, address):
@@ -85,3 +87,39 @@ class terrariumPCF8574IOExpander(terrariumIOExpander):
8587

8688
def _load_device(self, address):
8789
return I2CRelayBoard(address[1], address[0])
90+
91+
92+
class terrariumPCF8575IOExpander(terrariumIOExpander):
93+
HARDWARE = "PCF8575"
94+
NAME = "PCF8575 Expander (16 ports)"
95+
96+
# Work around bug: https://github.com/rp3tya/PCF8575/issues/5
97+
# Alternative in comments https://www.tindie.com/products/bugrovs2012/16-channel-i2c-electromagnetic-relay-module-iot/
98+
# Keep own internal state
99+
# Relays starting at number 1 (human counting)
100+
def __set_relay(self, port, action):
101+
self.__internal_state[port-1] = action
102+
self.__device.port = self.__internal_state
103+
104+
def __get_relay(self, port):
105+
return self.__internal_state[port-1]
106+
107+
def _load_device(self, address):
108+
device = PCF8575(address[1], address[0])
109+
# Force all relays to off position
110+
self.__internal_state = 16 * [False]
111+
device.port = self.__internal_state
112+
113+
return device
114+
115+
def switch_on(self, port):
116+
self.__set_relay(port, True)
117+
118+
def switch_off(self, port):
119+
self.__set_relay(port, False)
120+
121+
def is_on(self, port):
122+
return self.__get_relay(port) == True
123+
124+
def is_off(self, port):
125+
return not self.is_on(port)

hardware/relay/gpio_relay.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def _load_hardware(self):
2424
device = None
2525
if address[0].lower().startswith("pcf8574-"):
2626
device = terrariumIOExpander("PCF8574", ",".join(address[1:]))
27+
elif address[0].lower().startswith("pcf8575-"):
28+
device = terrariumIOExpander("PCF8575", ",".join(address[1:]))
2729

2830
if device is not None:
2931
device.set_port(int(address[0].split("-")[1]))

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ piexif==1.1.3
3535

3636
# Hardware / sensors packages
3737
gpiozero==2.0.1
38-
# Github version is more updated
38+
# Github versions are more updated
3939
git+https://github.com/oweidner/i2crelay
40+
git+https://github.com/rp3tya/PCF8575
4041
smbus2==0.5.0
4142
smbus==1.1.post2
4243
# Github version has some serious patches which we need. Pyipi version is outdated

0 commit comments

Comments
 (0)