ACSSR Unit

Support the following products:

ACSSR Unit

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:

  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")

UIFLOW2 I2C Example:

i2c_example.png

UIFLOW2 Modbus Example:

modbus_example.png

cores3_acssr_i2c_example.m5f2

cores3_acssr_modbus_example.m5f2

class ACSSRUnit

Constructors

class ACSSRUnit(bus, address=None)

Create an ACSSRUnit object.

Parameters:
  • bus – I2C bus or Modbus.

  • address – Slave address. Default is 0x50 in I2C mode. Default is 0x04 in Modbus mode.

UIFLOW2:

init.png

Methods

ACSSRUnit.on() None

Turn on the relay.

UIFLOW2:

on.png

ACSSRUnit.off() None

Turn off the relay.

UIFLOW2:

off.png

ACSSRUnit.__call__([x])

Turn on the relay if x is True, otherwise turn off the relay.

Parameters:

x – True or False.

UIFLOW2:

call.png

ACSSRUnit.value([x])

Turn on the relay if x is True, otherwise turn off the relay.

Parameters:

x – True or False.

UIFLOW2:

value.png

ACSSRUnit.fill_color(rgb: int = 0) None

Set the color of the LED.

Parameters:

rgb – RGB color value. Default is 0.

UIFLOW2:

fill_color.png

ACSSRUnit.get_firmware_version() int

Get the firmware version of the unit.

Returns:

Firmware version.

UIFLOW2:

get_firmware_version.png

ACSSRUnit.set_address(new_address: int) None

Set the I2C address of the unit.

Parameters:

new_address – New I2C address. The range is 0x01-0x7f.

UIFLOW2:

set_address.png

set_address1.png