Limit Unit

The Unit Limit is a travel switch unit that provides a limit trigger signal to the MCU or other master peripherals by pulling the digital signal interface from 3.3V high to 0V low when the switch handle is closed by an external force. It is suitable for all kinds of moving machinery and equipment to control its stroke and carry out terminal limit protection.

Support the following products:

LimitUnit

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 LIMITUnit
 9
10
11title0 = None
12label1 = None
13label0 = None
14limit_0 = None
15
16
17def setup():
18    global title0, label1, label0, limit_0
19
20    M5.begin()
21    Widgets.fillScreen(0x222222)
22    title0 = Widgets.Title(
23        "LimitUnit Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18
24    )
25    label1 = Widgets.Label(
26        "Button State:", 395, 150, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18
27    )
28    label0 = Widgets.Label(
29        "Limit Counter Value:", 1, 102, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18
30    )
31
32    limit_0 = LIMITUnit((33, 32), True, type=2)
33    limit_0.count_reset()
34
35
36def loop():
37    global title0, label1, label0, limit_0
38    M5.update()
39    label0.setText(str((str("Limit Counter Value:") + str((limit_0.count_value)))))
40
41
42if __name__ == "__main__":
43    try:
44        setup()
45        while True:
46            loop()
47    except (Exception, KeyboardInterrupt) as e:
48        try:
49            from utility import print_error_msg
50
51            print_error_msg(e)
52        except ImportError:
53            print("please update to latest firmware")

UIFLOW2 Example:

example.png

limit_core2_example.m5f2

class LimitUnit

Constructors

class LimitUnit(pin_num, active_low, pullup_active)

Initialize a Limit instance with the specified pin, active-low configuration, and pull-up resistor state.

Parameters:
  • pin_num – The GPIO pin number connected to the limit.

  • active_low (bool) – Determines whether the limit signal is active-low. Default is True.

  • pullup_active (bool) – Specifies whether the internal pull-up resistor is enabled. Default is True.

UIFLOW2:

init.png

Methods

LimitUnit.count_reset()

Reset the count value to zero.

UIFLOW2:

count_reset.png

LimitUnit.isHolding()

Check if the limit is currently being held.

UIFLOW2:

isHolding.png

LimitUnit.setCallback(type, cb)

Set a callback function for a specified limit event type.

Parameters:
  • type – The event type (e.g., WAS_CLICKED, WAS_DOUBLECLICKED).

  • cb – The callback function to be executed for the event.

UIFLOW2:

setCallback.png

LimitUnit.tick(pin)

Monitor the state transitions of a limit based on its pin state and trigger appropriate handlers.

UIFLOW2:

tick.png