ExtEncoder Unit

The following products are supported:

ExtEncoderUnit

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 hardware import *
 9from unit import ExtEncoderUnit
10
11
12label0 = None
13i2c0 = None
14extencoder_0 = None
15
16
17def setup():
18    global label0, i2c0, extencoder_0
19
20    M5.begin()
21    Widgets.fillScreen(0x222222)
22    label0 = Widgets.Label("label0", 132, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
23
24    i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
25    extencoder_0 = ExtEncoderUnit(i2c0, 0x59)
26
27
28def loop():
29    global label0, i2c0, extencoder_0
30    M5.update()
31    if extencoder_0.get_rotary_status():
32        label0.setText(str(extencoder_0.get_rotary_value()))
33
34
35if __name__ == "__main__":
36    try:
37        setup()
38        while True:
39            loop()
40    except (Exception, KeyboardInterrupt) as e:
41        try:
42            from utility import print_error_msg
43
44            print_error_msg(e)
45        except ImportError:
46            print("please update to latest firmware")

UIFLOW2 Example:

example.png

cores3_extencoder_example.m5f2

class ExtEncoderUnit

Constructors

class ExtEncoderUnit(i2c, address: int | list | tuple = 0x59)

Creates a ExtEncoderUnit object.

UIFLOW2:

init.png

Methods

ExtEncoderUnit.get_rotary_status() bool

Gets the rotation status of the ExtEncoderUnit object.

UIFLOW2:

get_rotary_status.png

ExtEncoderUnit.get_rotary_value() int

Gets the rotation value of the ExtEncoderUnit object.

UIFLOW2:

get_rotary_value.png

ExtEncoderUnit.get_rotary_increments() int

Gets the rotation increment of the ExtEncoderUnit object. Can be used to determine the direction of rotation.

UIFLOW2:

get_rotary_increments.png

ExtEncoderUnit.reset_rotary_value() None

Resets the rotation value of the ExtEncoderUnit object.

UIFLOW2:

reset_rotary_value.png

ExtEncoderUnit.set_rotary_value(new_value: int) None

Sets the rotation value of the ExtEncoderUnit object.

参数:

new_value (int) – adjust the current value.

UIFLOW2:

set_rotary_value.png

ExtEncoderUnit.get_perimeter() int

Gets the perimeter of the ExtEncoderUnit object. The unit is millimeters.

UIFLOW2:

get_perimeter.png

ExtEncoderUnit.set_perimeter(perimeter: int) None

Sets the perimeter of the ExtEncoderUnit object.

参数:

perimeter (int) – the perimeter of the ExtEncoderUnit object. The unit is millimeters.

UIFLOW2:

set_perimeter.png

ExtEncoderUnit.get_pulse() int

pluse per round.

UIFLOW2:

get_pulse.png

ExtEncoderUnit.set_pulse(pulse: int) None

Sets the pulse per round.

参数:

pulse (int) – the pulse per round.

UIFLOW2:

set_pulse.png

ExtEncoderUnit.get_zero_mode() int

Gets the zero mode of the ExtEncoderUnit object.

UIFLOW2:

get_zero_mode.png

ExtEncoderUnit.set_zero_mode(mode: int) None

Sets the zero mode of the ExtEncoderUnit object.

参数:

mode (int) – the zero mode of the ExtEncoderUnit object.

UIFLOW2:

set_zero_mode.png

ExtEncoderUnit.get_meter_value() int

Gets the meter value of the ExtEncoderUnit object. The unit is millimeters.

UIFLOW2:

get_meter_value.png

ExtEncoderUnit.get_zero_pulse_value() int

Gets the zero pulse value of the ExtEncoderUnit object.

UIFLOW2:

get_zero_pulse_value.png

ExtEncoderUnit.set_zero_pulse_value(value: int) None

Sets the zero pulse value of the ExtEncoderUnit object.

参数:

value (int) – the zero pulse value of the ExtEncoderUnit object.

UIFLOW2:

set_zero_pulse_value.png

ExtEncoderUnit.get_firmware_version() int

Gets the firmware version of the ExtEncoderUnit object.

UIFLOW2:

get_firmware_version.png

ExtEncoderUnit.set_address(address) int

Sets the I2C address of the ExtEncoderUnit object.

UIFLOW2:

set_address.png