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:
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:
class Relay4Unit
Constructors
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:
- 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:
- Relay4Unit.get_led_state(n: int) int
Get the state of the LED.
- 参数:
n (int) – The number of the LED.
UIFLOW2:
- 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: