Relay4 Unit

4-Relay unit is an integrated 4-way relay module which can be controlled by I2C protocol. The maximum control voltage of each relay is AC-250V/DC-28V, the rated current is 10A and the instantaneous current can hold up to 16A. Each relay can be controlled independently, each on it’s own. Each relay has status (LED) indictor as well to show the state of the relay at any given time.

Support the following products:

Relay4Unit

Micropython Example:

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from unit import RelayUnit
 9import time
10
11
12relay_0 = None
13
14
15def setup():
16    global relay_0
17
18    M5.begin()
19    Widgets.fillScreen(0x222222)
20
21    relay_0 = RelayUnit((36, 26))
22    print(relay_0.get_status())
23    relay_0.on()
24    time.sleep(1)
25    relay_0.off()
26    time.sleep(1)
27    relay_0.set_status(True)
28    time.sleep(1)
29
30
31def loop():
32    global relay_0
33    M5.update()
34
35
36if __name__ == "__main__":
37    try:
38        setup()
39        while True:
40            loop()
41    except (Exception, KeyboardInterrupt) as e:
42        try:
43            from utility import print_error_msg
44
45            print_error_msg(e)
46        except ImportError:
47            print("please update to latest firmware")

UIFLOW2 Example:

example.png

cores3_relay4_example.m5f2

class Relay4Unit

Constructors

class Relay4Unit(i2c: I2C, address: int | list | tuple = 0x26)

Initialize the Relay4Unit object.

参数:
  • i2c (I2C) – I2C port to use.

  • address (int) – I2C address of the Relay4Unit.

UIFLOW2:

init.png

Methods

Relay4Unit.set_mode(mode: int)

Set the mode of the relay.

参数:

mode (int) –

The mode of the relay

Options: - Relay4Unit.ASYNC_MODE: async - Relay4Unit.SYNC_MODE: sync

UIFLOW2:

set_mode.png

Relay4Unit.get_mode() int

Get the mode of the relay.

返回:

The mode of the relay

Options: - Relay4Unit.ASYNC_MODE: async - Relay4Unit.SYNC_MODE: sync

UIFLOW2:

get_mode.png

Relay4Unit.get_led_state(n: int) int

Get the state of the LED.

参数:

n (int) – The number of the LED.

UIFLOW2:

get_led_state.png

Relay4Unit.set_led_state(n: int, state: int) None

Set the state of the LED.

参数:
  • n (int) – The number of the LED.

  • state (int) – The state of the LED.

UIFLOW2:

set_led_state.png

Relay4Unit.get_relay_state(n: int) int

Get the state of the relay.

参数:

n (int) – The number of the relay.

返回:

The state of the relay.

UIFLOW2:

get_relay_state.png

Relay4Unit.set_relay_state(n: int, state: int) None

Set the state of the relay.

参数:
  • n (int) – The number of the relay.

  • state (int) – The state of the relay.

UIFLOW2:

set_relay_state.png

Relay4Unit.set_relay_all(state: int) None

Set the state of all the relay.

参数:

state (int) – The state of the relay.

UIFLOW2:

set_relay_all.png