ACSSR Unit
Support the following products:
Micropython I2C 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 hardware import * 9from unit import ACSSRUnit 10 11 12label0 = None 13rect0 = None 14label1 = None 15title0 = None 16label3 = None 17i2c0 = None 18acssr_0 = None 19 20 21touch_x = None 22touch_y = None 23x = None 24y = None 25w = None 26h = None 27state = None 28ret = None 29 30 31# Describe this function... 32def is_touch(touch_x, touch_y, x, y, w, h): 33 global state, ret, label0, rect0, label1, title0, label3, i2c0, acssr_0 34 ret = False 35 if touch_x >= x and touch_x <= x + w: 36 if touch_y >= y and touch_y <= y + h: 37 ret = True 38 return ret 39 40 41# Describe this function... 42def display_ui(state): 43 global touch_x, touch_y, x, y, w, h, ret, label0, rect0, label1, title0, label3, i2c0, acssr_0 44 if state: 45 rect0.setColor(color=0x00FF00, fill_c=0x00FF00) 46 label3.setColor(0xFFFFFF, 0x00FF00) 47 label3.setText(str("On")) 48 acssr_0.fill_color(0x00FF00) 49 else: 50 rect0.setColor(color=0xFF0000, fill_c=0xFF0000) 51 label3.setColor(0xFFFFFF, 0xFF0000) 52 label3.setText(str("Off")) 53 acssr_0.fill_color(0xFF0000) 54 55 56def setup(): 57 global \ 58 label0, \ 59 rect0, \ 60 label1, \ 61 title0, \ 62 label3, \ 63 i2c0, \ 64 acssr_0, \ 65 ret, \ 66 state, \ 67 touch_x, \ 68 x, \ 69 w, \ 70 touch_y, \ 71 y, \ 72 h 73 74 M5.begin() 75 Widgets.fillScreen(0x222222) 76 label0 = Widgets.Label("label0", 188, 30, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 77 rect0 = Widgets.Rectangle(130, 105, 60, 30, 0x00FF00, 0x00FF00) 78 label1 = Widgets.Label( 79 "Firmware Version:", 8, 30, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 80 ) 81 title0 = Widgets.Title("ACSSR Unit", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 82 label3 = Widgets.Label("On", 147, 111, 1.0, 0xFFFFFF, 0x00FF00, Widgets.FONTS.DejaVu18) 83 84 i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000) 85 print(i2c0.scan()) 86 acssr_0 = ACSSRUnit(i2c0, 0x50) 87 label0.setText(str(acssr_0.get_firmware_version())) 88 state = acssr_0.value() 89 display_ui(state) 90 91 92def loop(): 93 global \ 94 label0, \ 95 rect0, \ 96 label1, \ 97 title0, \ 98 label3, \ 99 i2c0, \ 100 acssr_0, \ 101 ret, \ 102 state, \ 103 touch_x, \ 104 x, \ 105 w, \ 106 touch_y, \ 107 y, \ 108 h 109 M5.update() 110 if M5.Touch.getCount(): 111 if is_touch( 112 (M5.Touch.getTouchPointRaw())[0], (M5.Touch.getTouchPointRaw())[1], 130, 105, 60, 30 113 ): 114 state = not state 115 acssr_0(state) 116 display_ui(state) 117 118 119if __name__ == "__main__": 120 try: 121 setup() 122 while True: 123 loop() 124 except (Exception, KeyboardInterrupt) as e: 125 try: 126 from utility import print_error_msg 127 128 print_error_msg(e) 129 except ImportError: 130 print("please update to latest firmware")
Micropython Modbus Example:
Connect an ISO485 Unit to CoreS3 Port C (RX=18, TX=17) and configure the ACSSR for Modbus mode, 115200 baud, 8N1, device address
0x04.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 ACSSRUnit, ISO485Unit 9import modbus 10 11 12label0 = None 13rect0 = None 14label1 = None 15title0 = None 16label3 = None 17iso485_0 = None 18modbusrtumaster_0 = None 19acssr_0 = None 20 21 22touch_x = None 23touch_y = None 24x = None 25y = None 26w = None 27h = None 28state = None 29ret = None 30 31 32# Describe this function... 33def is_touch(touch_x, touch_y, x, y, w, h): 34 global state, ret, label0, rect0, label1, title0, label3, iso485_0, acssr_0 35 ret = False 36 if touch_x >= x and touch_x <= x + w: 37 if touch_y >= y and touch_y <= y + h: 38 ret = True 39 return ret 40 41 42# Describe this function... 43def display_ui(state): 44 global \ 45 touch_x, \ 46 touch_y, \ 47 x, \ 48 y, \ 49 w, \ 50 h, \ 51 ret, \ 52 label0, \ 53 rect0, \ 54 label1, \ 55 title0, \ 56 label3, \ 57 iso485_0, \ 58 acssr_0 59 if state: 60 rect0.setColor(color=0x00FF00, fill_c=0x00FF00) 61 label3.setColor(0xFFFFFF, 0x00FF00) 62 label3.setText(str("On")) 63 acssr_0.fill_color(0x00FF00) 64 else: 65 rect0.setColor(color=0xFF0000, fill_c=0xFF0000) 66 label3.setColor(0xFFFFFF, 0xFF0000) 67 label3.setText(str("Off")) 68 acssr_0.fill_color(0xFF0000) 69 70 71def setup(): 72 global modbusrtumaster_0 73 global \ 74 label0, \ 75 rect0, \ 76 label1, \ 77 title0, \ 78 label3, \ 79 iso485_0, \ 80 acssr_0, \ 81 ret, \ 82 state, \ 83 touch_x, \ 84 x, \ 85 w, \ 86 touch_y, \ 87 y, \ 88 h 89 90 M5.begin() 91 Widgets.fillScreen(0x222222) 92 label0 = Widgets.Label("label0", 188, 30, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 93 rect0 = Widgets.Rectangle(130, 105, 60, 30, 0x00FF00, 0x00FF00) 94 label1 = Widgets.Label( 95 "Firmware Version:", 8, 30, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 96 ) 97 title0 = Widgets.Title("ACSSR Modbus", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 98 label3 = Widgets.Label("On", 147, 111, 1.0, 0xFFFFFF, 0x00FF00, Widgets.FONTS.DejaVu18) 99 100 # ISO485 Unit on CoreS3 Port C: RX=18, TX=17. 101 # Configure the ACSSR hardware for Modbus mode before running. 102 iso485_0 = ISO485Unit(2, port=(18, 17)) 103 iso485_0.init(baudrate=115200, data_bits=8, stop_bits=1, parity=None) 104 modbusrtumaster_0 = modbus.ModbusRTUMaster(uart=iso485_0) 105 acssr_0 = ACSSRUnit(modbusrtumaster_0, address=0x04) 106 label0.setText(str(acssr_0.get_firmware_version())) 107 state = acssr_0.value() 108 display_ui(state) 109 110 111def loop(): 112 global \ 113 label0, \ 114 rect0, \ 115 label1, \ 116 title0, \ 117 label3, \ 118 iso485_0, \ 119 acssr_0, \ 120 ret, \ 121 state, \ 122 touch_x, \ 123 x, \ 124 w, \ 125 touch_y, \ 126 y, \ 127 h 128 M5.update() 129 if M5.Touch.getCount(): 130 if is_touch( 131 (M5.Touch.getTouchPointRaw())[0], (M5.Touch.getTouchPointRaw())[1], 130, 105, 60, 30 132 ): 133 state = not state 134 acssr_0(state) 135 display_ui(state) 136 137 138if __name__ == "__main__": 139 try: 140 setup() 141 while True: 142 loop() 143 except (Exception, KeyboardInterrupt) as e: 144 try: 145 from utility import print_error_msg 146 147 print_error_msg(e) 148 except ImportError: 149 print("please update to latest firmware")
UIFLOW2 I2C Example:
UIFLOW2 Modbus Example:
cores3_acssr_modbus_example.m5f2
class ACSSRUnit
Constructors
- class ACSSRUnit(bus, address=0x50)
Factory returning the driver selected by the bus object. It does not change the ACSSR hardware’s communication mode.
- Parameters:
bus – A
machine.I2Cinstance, or a configured Modbus master providingread_coilsand the register/coil operations used below.address (int) – Device address. The factory default is
0x50in both modes. For a Modbus device at its default address, explicitly passaddress=0x04.
- Returns:
unit.acssr.ACSSRI2CUnitformachine.I2C;unit.acssr.ACSSRModbusUnitfor a Modbus master.
The implementation class
ACSSRModbusUnithas a default address of0x04, but the factory always forwards its ownaddressargument. Selecting a bus does not select that implementation default.from unit import ACSSRUnit, ISO485Unit from modbus import ModbusRTUMaster # I2C: use the configured I2C bus. acssr_i2c = ACSSRUnit(i2c0, address=0x50) # Modbus: CoreS3 Port C, ISO485 Unit, ACSSR in Modbus mode. rs485 = ISO485Unit(2, port=(18, 17)) rs485.init(baudrate=115200, data_bits=8, stop_bits=1, parity=None) master = ModbusRTUMaster(uart=rs485) acssr_modbus = ACSSRUnit(master, address=0x04)
Use methods on the returned instance, such as
acssr_modbus.value(). The factory class itself does not define the instance methods below.UIFLOW2:

Methods
ACSSRUnit is a factory: it returns an ACSSRI2CUnit for an I2C bus or an
ACSSRModbusUnit for a Modbus bus. The methods below belong to the returned
object and are available in both modes.
- ACSSRUnit.__call__([x])
Turn on the relay if x is True, otherwise turn off the relay.
- Parameters:
x – True or False.
UIFLOW2:

- ACSSRUnit.value([x])
Turn on the relay if x is True, otherwise turn off the relay.
- Parameters:
x – True or False.
UIFLOW2:

- ACSSRUnit.fill_color(rgb: int = 0) None
Set the color of the LED.
- Parameters:
rgb – RGB color value. Default is 0.
UIFLOW2:








