Roller485Unit

Support the following products:

Roller485

Roller485 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 Roller485Unit
10
11
12title0 = None
13label0 = None
14label1 = None
15label2 = None
16label3 = None
17label4 = None
18i2c1 = None
19roller485_0 = None
20
21
22output = None
23mode = None
24
25
26def btn_b_was_clicked_event(state):
27    global title0, label0, label1, label2, label3, label4, i2c1, roller485_0, output, mode
28    output = output ^ (0x01 << 0)
29    roller485_0.set_motor_output_state(output)
30
31
32def btn_a_was_clicked_event(state):
33    global title0, label0, label1, label2, label3, label4, i2c1, roller485_0, output, mode
34    mode = mode + 1
35    if mode > 4:
36        mode = 1
37
38
39def setup():
40    global title0, label0, label1, label2, label3, label4, i2c1, roller485_0, output, mode
41
42    M5.begin()
43    Widgets.fillScreen(0x222222)
44    title0 = Widgets.Title("Roller485 I2C Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
45    label0 = Widgets.Label("mode:", 1, 63, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
46    label1 = Widgets.Label("motor state:", 2, 108, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
47    label2 = Widgets.Label("speed:", 2, 152, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
48    label3 = Widgets.Label("mode", 40, 215, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
49    label4 = Widgets.Label("on/off", 126, 215, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
50
51    BtnB.setCallback(type=BtnB.CB_TYPE.WAS_CLICKED, cb=btn_b_was_clicked_event)
52    BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btn_a_was_clicked_event)
53
54    i2c1 = I2C(1, scl=Pin(22), sda=Pin(21), freq=100000)
55    roller485_0 = Roller485Unit(i2c1, address=0x64, mode=Roller485Unit.I2C_MODE)
56    roller485_0.set_motor_output_state(0)
57    output = roller485_0.get_motor_output_state()
58    mode = roller485_0.get_motor_mode()
59    label0.setText(str((str("mode:") + str(mode))))
60    label1.setText(str((str("motor state:") + str(output))))
61
62
63def loop():
64    global title0, label0, label1, label2, label3, label4, i2c1, roller485_0, output, mode
65    M5.update()
66    label0.setText(str((str("mode:") + str(mode))))
67    label1.setText(str((str("motor state:") + str(output))))
68    if mode == 1:
69        roller485_0.set_motor_speed(20000)
70        roller485_0.set_speed_max_current(400)
71        label2.setText(str((str("speed:") + str((roller485_0.get_motor_speed_readback())))))
72    elif mode == 2:
73        roller485_0.set_motor_position(1000)
74        roller485_0.set_position_max_current(400)
75        label2.setText(str((str("position:") + str((roller485_0.get_motor_position_readback())))))
76    elif mode == 3:
77        roller485_0.set_motor_max_current(400)
78        label2.setText(str((str("current:") + str((roller485_0.get_motor_current_readback())))))
79    elif mode == 4:
80        label2.setText(str((str("encoder:") + str((roller485_0.get_encoder_value())))))
81    roller485_0.set_motor_mode(mode)
82
83
84if __name__ == "__main__":
85    try:
86        setup()
87        while True:
88            loop()
89    except (Exception, KeyboardInterrupt) as e:
90        try:
91            from utility import print_error_msg
92
93            print_error_msg(e)
94        except ImportError:
95            print("please update to latest firmware")

Roller485 I2C UIFLOW2 Example:

i2c_example.png

roller485_i2c_fire_example.m5f2

Roller485 RS485 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 Roller485Unit
 10from unit import RS485Unit
 11
 12
 13title0 = None
 14label0 = None
 15label1 = None
 16label2 = None
 17label3 = None
 18label4 = None
 19rs485_0 = None
 20roller485_0 = None
 21
 22
 23output = None
 24mode = None
 25
 26
 27def btn_b_was_clicked_event(state):
 28    global title0, label0, label1, label2, label3, label4, rs485_0, roller485_0, output, mode
 29    output = output ^ (0x01 << 0)
 30    roller485_0.set_motor_output_state(output)
 31
 32
 33def btn_a_was_clicked_event(state):
 34    global title0, label0, label1, label2, label3, label4, rs485_0, roller485_0, output, mode
 35    mode = mode + 1
 36    if mode > 4:
 37        mode = 1
 38
 39
 40def setup():
 41    global title0, label0, label1, label2, label3, label4, rs485_0, roller485_0, output, mode
 42
 43    M5.begin()
 44    Widgets.fillScreen(0x222222)
 45    title0 = Widgets.Title(
 46        "Roller485 RS485 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18
 47    )
 48    label0 = Widgets.Label("mode:", 1, 63, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 49    label1 = Widgets.Label("motor state:", 2, 108, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 50    label2 = Widgets.Label("speed:", 2, 152, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 51    label3 = Widgets.Label("mode", 40, 215, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 52    label4 = Widgets.Label("on/off", 126, 215, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 53
 54    BtnB.setCallback(type=BtnB.CB_TYPE.WAS_CLICKED, cb=btn_b_was_clicked_event)
 55    BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btn_a_was_clicked_event)
 56
 57    rs485_0 = RS485Unit(2, port=(13, 15))
 58    rs485_0.init(
 59        tx_pin=None,
 60        rx_pin=None,
 61        baudrate=115200,
 62        data_bits=None,
 63        stop_bits=None,
 64        parity=None,
 65        ctrl_pin=None,
 66    )
 67    roller485_0 = Roller485Unit(rs485_0, address=0, mode=Roller485Unit.RS485_MODE)
 68    roller485_0.set_motor_output_state(0)
 69    output = 0
 70    mode = roller485_0.get_motor_mode()
 71    label0.setText(str((str("mode:") + str(mode))))
 72    label1.setText(str((str("motor state:") + str(output))))
 73
 74
 75def loop():
 76    global title0, label0, label1, label2, label3, label4, rs485_0, roller485_0, output, mode
 77    M5.update()
 78    label0.setText(str((str("mode:") + str(mode))))
 79    label1.setText(str((str("motor state:") + str(output))))
 80    if mode == 1:
 81        roller485_0.set_motor_speed(20000)
 82        roller485_0.set_speed_max_current(400)
 83        label2.setText(str((str("speed:") + str((roller485_0.get_motor_speed_readback())))))
 84    elif mode == 2:
 85        roller485_0.set_motor_position(1000)
 86        roller485_0.set_position_max_current(400)
 87        label2.setText(str((str("position:") + str((roller485_0.get_motor_position_readback())))))
 88    elif mode == 3:
 89        roller485_0.set_motor_max_current(400)
 90        label2.setText(str((str("current:") + str((roller485_0.get_motor_current_readback())))))
 91    elif mode == 4:
 92        label2.setText(str((str("encoder:") + str((roller485_0.get_encoder_value())))))
 93    roller485_0.set_motor_mode(mode)
 94
 95
 96if __name__ == "__main__":
 97    try:
 98        setup()
 99        while True:
100            loop()
101    except (Exception, KeyboardInterrupt) as e:
102        try:
103            from utility import print_error_msg
104
105            print_error_msg(e)
106        except ImportError:
107            print("please update to latest firmware")

Roller485 RS485 UIFLOW2 Example:

rs485_example.png

roller485_485_fire_example.m5f2

Roller485 RS485ToI2C 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 Roller485Unit
 10from unit import RS485Unit
 11from unit import ENVUnit
 12
 13
 14title0 = None
 15label5 = None
 16label0 = None
 17label6 = None
 18label1 = None
 19label2 = None
 20label3 = None
 21label4 = None
 22env2_0 = None
 23rs485_0 = None
 24roller485_0 = None
 25
 26
 27output = None
 28mode = None
 29
 30
 31def btn_b_was_clicked_event(state):
 32    global \
 33        title0, \
 34        label5, \
 35        label0, \
 36        label6, \
 37        label1, \
 38        label2, \
 39        label3, \
 40        label4, \
 41        env2_0, \
 42        rs485_0, \
 43        roller485_0, \
 44        output, \
 45        mode
 46    output = output ^ (0x01 << 0)
 47    roller485_0.set_motor_output_state(output)
 48
 49
 50def btn_a_was_clicked_event(state):
 51    global \
 52        title0, \
 53        label5, \
 54        label0, \
 55        label6, \
 56        label1, \
 57        label2, \
 58        label3, \
 59        label4, \
 60        env2_0, \
 61        rs485_0, \
 62        roller485_0, \
 63        output, \
 64        mode
 65    mode = mode + 1
 66    if mode > 4:
 67        mode = 1
 68
 69
 70def setup():
 71    global \
 72        title0, \
 73        label5, \
 74        label0, \
 75        label6, \
 76        label1, \
 77        label2, \
 78        label3, \
 79        label4, \
 80        env2_0, \
 81        rs485_0, \
 82        roller485_0, \
 83        output, \
 84        mode
 85
 86    M5.begin()
 87    Widgets.fillScreen(0x222222)
 88    title0 = Widgets.Title(
 89        "Roller485 485ToI2C Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18
 90    )
 91    label5 = Widgets.Label("temp:", 182, 66, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 92    label0 = Widgets.Label("mode:", 1, 63, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 93    label6 = Widgets.Label("humi:", 182, 131, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 94    label1 = Widgets.Label("motor state:", 2, 108, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 95    label2 = Widgets.Label("speed:", 2, 152, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 96    label3 = Widgets.Label("mode", 40, 215, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 97    label4 = Widgets.Label("on/off", 126, 215, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 98
 99    BtnB.setCallback(type=BtnB.CB_TYPE.WAS_CLICKED, cb=btn_b_was_clicked_event)
100    BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btn_a_was_clicked_event)
101
102    rs485_0 = RS485Unit(2, port=(13, 15))
103    rs485_0.init(
104        tx_pin=None,
105        rx_pin=None,
106        baudrate=115200,
107        data_bits=None,
108        stop_bits=None,
109        parity=None,
110        ctrl_pin=None,
111    )
112    roller485_0 = Roller485Unit(rs485_0, address=0, mode=Roller485Unit.RS485_TO_I2C_MODE)
113    env2_0 = ENVUnit(i2c=roller485_0, type=2)
114    roller485_0.set_motor_output_state(0)
115    output = 0
116    mode = roller485_0.get_motor_mode()
117    label0.setText(str((str("mode:") + str(mode))))
118    label1.setText(str((str("motor state:") + str(output))))
119
120
121def loop():
122    global \
123        title0, \
124        label5, \
125        label0, \
126        label6, \
127        label1, \
128        label2, \
129        label3, \
130        label4, \
131        env2_0, \
132        rs485_0, \
133        roller485_0, \
134        output, \
135        mode
136    M5.update()
137    label0.setText(str((str("mode:") + str(mode))))
138    label1.setText(str((str("motor state:") + str(output))))
139    label5.setText(str((str("temp:") + str((env2_0.read_temperature())))))
140    label6.setText(str((str("humi:") + str((env2_0.read_pressure())))))
141    if mode == 1:
142        roller485_0.set_motor_speed(20000)
143        roller485_0.set_speed_max_current(400)
144        label2.setText(str((str("speed:") + str((roller485_0.get_motor_speed_readback())))))
145    elif mode == 2:
146        roller485_0.set_motor_position(1000)
147        roller485_0.set_position_max_current(400)
148        label2.setText(str((str("position:") + str((roller485_0.get_motor_position_readback())))))
149    elif mode == 3:
150        roller485_0.set_motor_max_current(400)
151        label2.setText(str((str("current:") + str((roller485_0.get_motor_current_readback())))))
152    elif mode == 4:
153        label2.setText(str((str("encoder:") + str((roller485_0.get_encoder_value())))))
154    roller485_0.set_motor_mode(mode)
155
156
157if __name__ == "__main__":
158    try:
159        setup()
160        while True:
161            loop()
162    except (Exception, KeyboardInterrupt) as e:
163        try:
164            from utility import print_error_msg
165
166            print_error_msg(e)
167        except ImportError:
168            print("please update to latest firmware")

Roller485 RS485ToI2C UIFLOW2 Example:

rs485_i2c_example.png

roller485_485toi2c_fire_example.m5f2

class Roller485Unit

Constructors

class Roller485Unit(bus, address, mode)

Initialize the Roller485Unit object based on communication mode.

Parameters:
  • bus – The I2C/RS485 bus instance.

  • address – The motor’s RS485 address. Defaults to _ROLLER485_RS485_ADDR.

  • mode – The Roller485 communication mode.

UIFLOW2:

init.png

class RollerBase

Constructors

class RollerBase

Methods

RollerBase.set_motor_output_state(ctrl) None

Set the motor output state.

Parameters:

ctrl (int) – Control value for the motor output.

UIFLOW2:

set_motor_output_state.png

RollerBase.get_motor_output_state() bool

Get the motor output status.

Returns:

True if the motor output is active, False otherwise.

UIFLOW2:

get_motor_output_state.png

RollerBase.set_motor_mode(mode) None

Set the motor mode.

Parameters:

mode (int) – The mode to set for the motor.

UIFLOW2:

set_motor_mode.png

RollerBase.get_motor_mode() int

Get the motor mode.

Returns:

The current motor mode.

UIFLOW2:

get_motor_mode.png

RollerBase.set_motor_over_range_protect_state(state) None

Set the motor over range protection state.

Parameters:

state (int) – Protection state value (1 to enable, 0 to disable).

UIFLOW2:

set_motor_over_range_protect_state.png

RollerBase.get_motor_over_range_protect_state() bool

Get the motor over range protection status.

Returns:

True if protection is enabled, False otherwise.

UIFLOW2:

get_motor_over_range_protect_state.png

RollerBase.remove_motor_jam_protect() None

Set the motor jam release protection.

UIFLOW2:

remove_motor_jam_protect.png

RollerBase.get_motor_status() int

Get the motor status.

Returns:

The current status of the motor.

UIFLOW2:

get_motor_status.png

RollerBase.get_motor_error_code() int

Get the motor error code.

Returns:

The current error code of the motor.

UIFLOW2:

get_motor_error_code.png

RollerBase.set_button_change_mode(state) None

Set the button change mode.

Parameters:

state (int) – Change mode state value (1 to enable, 0 to disable).

UIFLOW2:

set_button_change_mode.png

RollerBase.get_button_change_mode() int

Get the button change mode.

Returns:

The current button change mode value.

UIFLOW2:

get_button_change_mode.png

RollerBase.set_motor_jam_protect_state(state) None

Set the motor jam protection enable/disable.

Parameters:

state (int) – Protection state value (1 to enable, 0 to disable).

UIFLOW2:

set_motor_jam_protect_state.png

RollerBase.get_motor_jam_protect_state() bool

Get the motor jam protection status.

Returns:

True if jam protection is enabled, False otherwise.

UIFLOW2:

get_motor_jam_protect_state.png

RollerBase.set_motor_id(id) None

Set the motor ID.

Parameters:

id (int) – The ID to assign to the motor.

UIFLOW2:

set_motor_id.png

RollerBase.get_motor_id() int

Get the motor ID.

Returns:

The current motor ID.

UIFLOW2:

get_motor_id.png

RollerBase.set_485_baudrate(bps) None

Set the 485 baudrate.

Parameters:

bps (int) – Baud rate value.

UIFLOW2:

set_485_baudrate.png

RollerBase.get_485_baudrate() int

Get the 485 baudrate.

Returns:

The current 485 baudrate.

UIFLOW2:

get_485_baudrate.png

RollerBase.set_rgb_brightness(bright) None

Set RGB brightness.

Parameters:

bright (int) – Brightness value.

UIFLOW2:

set_rgb_brightness.png

RollerBase.get_rgb_brightness() int

Get RGB brightness.

Returns:

The current RGB brightness value.

UIFLOW2:

get_rgb_brightness.png

RollerBase.set_motor_speed(speed) None

Set the motor speed and max current setting.

Parameters:

speed (int) – The speed value to set.

UIFLOW2:

set_motor_speed.png

RollerBase.get_motor_speed() int

Get the motor speed and max current setting.

Returns:

The current motor speed.

UIFLOW2:

get_motor_speed.png

RollerBase.set_speed_max_current(current) None

Set the motor speed and max current setting.

Parameters:

current (int) – The max current value to set.

UIFLOW2:

set_speed_max_current.png

RollerBase.get_speed_max_current() int

Get the motor speed and max current setting.

Returns:

The current max current setting.

UIFLOW2:

get_speed_max_current.png

RollerBase.get_motor_speed_readback() float

Get the motor speed readback.

Returns:

The readback value of the motor speed.

UIFLOW2:

get_motor_speed_readback.png

RollerBase.set_motor_speed_pid(p, i, d) None

Set the motor speed PID.

Parameters:
  • p (float) – Proportional gain.

  • i (float) – Integral gain.

  • d (float) – Derivative gain.

UIFLOW2:

set_motor_speed_pid.png

RollerBase.get_motor_speed_pid() tuple

Get the motor speed PID.

Returns:

A tuple containing the PID values.

UIFLOW2:

get_motor_speed_pid.png

RollerBase.set_motor_position(position) None

Set the motor position and max current setting.

Parameters:

position (int) – The position value to set.

UIFLOW2:

set_motor_position.png

RollerBase.get_motor_position() int

Get the motor position and max current setting.

Returns:

The current motor position.

UIFLOW2:

get_motor_position.png

RollerBase.set_position_max_current(current) None

Set the motor position and max current setting.

Parameters:

current (int) – The max current value to set.

UIFLOW2:

set_position_max_current.png

RollerBase.get_position_max_current() int

Get the motor position and max current setting.

Returns:

The current max current setting.

UIFLOW2:

get_position_max_current.png

RollerBase.get_motor_position_readback() float

Get the motor position readback.

Returns:

The readback value of the motor position.

UIFLOW2:

get_motor_position_readback.png

RollerBase.get_motor_position_pid() tuple

Get the motor position PID.

Returns:

A tuple containing the PID values for position.

UIFLOW2:

get_motor_position_pid.png

RollerBase.set_motor_position_pid(p, i, d) None

Set the motor position PID.

Parameters:
  • p (float) – Proportional gain.

  • i (float) – Integral gain.

  • d (float) – Derivative gain.

UIFLOW2:

set_motor_position_pid.png

RollerBase.set_motor_max_current(current) None

Set the motor max current.

Parameters:

current (int) – The maximum current for the motor, multiplied by 100 before sending.

UIFLOW2:

set_motor_max_current.png

RollerBase.get_motor_max_current() int

Get the motor max current.

Returns:

The motor max current, divided by 100 after reading.

UIFLOW2:

get_motor_max_current.png

RollerBase.get_motor_current_readback() float

Get the motor current readback.

Returns:

The motor current readback value, divided by 100 after reading.

UIFLOW2:

get_motor_current_readback.png

RollerBase.set_rgb_color(rgb) None

Set the system RGB color.

Parameters:

rgb (int) – The RGB color value, where the format is 0xRRGGBB.

UIFLOW2:

set_rgb_color.png

RollerBase.get_rgb_color() tuple

Get the system RGB color.

Returns:

The RGB color as a tuple (R, G, B).

UIFLOW2:

get_rgb_color.png

RollerBase.set_rgb_mode(mode) None

Set the system RGB mode.

Parameters:

mode (int) – The RGB mode value.

UIFLOW2:

set_rgb_mode.png

RollerBase.get_rgb_mode() int

Get the system RGB mode.

Returns:

The current RGB mode value.

UIFLOW2:

get_rgb_mode.png

RollerBase.get_vin_voltage() int

Get the system VIN voltage.

Returns:

The system VIN voltage value, multiplied by 10 after reading.

UIFLOW2:

get_vin_voltage.png

RollerBase.get_temperature_value() int

Get the system temperature.

Returns:

The current system temperature value.

UIFLOW2:

get_temperature_value.png

RollerBase.set_encoder_value(count) None

Set the system encoder value.

Parameters:

count (int) – The encoder count value.

UIFLOW2:

set_encoder_value.png

RollerBase.get_encoder_value() int

Get the system encoder value.

Returns:

The current encoder value.

UIFLOW2:

get_encoder_value.png

RollerBase.save_param_to_flash() None

Save the motor data to flash.

UIFLOW2:

save_param_to_flash.png

RollerBase.get_firmware_version() int

Get the device firmware version.

Returns:

The current firmware version.

UIFLOW2:

get_firmware_version.png

RollerBase.set_i2c_address(addr) None

Set the I2C address.

Parameters:

addr (int) – The new I2C address. Must be between 0x08 and 0x77.

UIFLOW2:

set_i2c_address.png

RollerBase.get_i2c_address() int

Get the current I2C address.

Returns:

The current I2C address.

UIFLOW2:

get_i2c_address.png

class RollerI2C(RollerBase)

Constructors

class RollerI2C(i2c, address)

Initialize the RollerI2C object.

Parameters:
  • i2c (I2C|PAHUBUnit) – I2C bus instance or PAHUBUnit instance.

  • address (int) – I2C address of the device. Defaults to _ROLLER485_I2C_ADDR.

UIFLOW2:

init.png

Methods

RollerI2C.read(register, length) bytes

Read data from a specified register on the I2C device.

Parameters:
  • register – The name of the register to read from.

  • length – The number of bytes to read.

Returns:

The data read from the device as a bytes object.

RollerI2C.write(register, bytes) None

Write data to a specified register on the I2C device.

Parameters:
  • register – The name of the register to write to.

  • bytes – The data to write to the register as a bytes object.

class Roller485(RollerBase)

Constructors

class Roller485(bus, address)

Initialize the Roller485 object.

Parameters:
  • bus – The RS485 bus instance.

  • address (int) – The motor’s RS485 address. Defaults to _ROLLER485_RS485_ADDR.

Methods

Roller485.read(register, length) bytes

Read data from a specified register via RS485.

Parameters:
  • register – The name of the register to read from.

  • length – The number of bytes to read.

Roller485.create_frame(cmd, motor_id, *datas) None

Create a command frame with the given command and motor ID.

Parameters:
  • cmd – The command byte.

  • motor_id – The ID of the motor.

  • datas – Additional data bytes to include in the frame.

Roller485.write(register, bytes) bool

Write data to a specified register via RS485.

Parameters:
  • register – The name of the register to write to.

  • bytes – The data to write to the register as a bytes object.

Returns:

The response after writing the data.

Roller485.send_command(cmd, id, data, buf_len) bool

Send a command via RS485.

Parameters:
  • cmd – The command byte.

  • id – The motor ID.

  • data – The data to send along with the command.

  • buf_len – The length of the buffer.

Roller485.read_response(cmd, id) tuple[Literal[True], Any]

Send a command via RS485.

Parameters:
  • cmd – The command byte.

  • id – The motor ID.

Returns:

A tuple (success, response). Success is True if the response is valid, and response is the data read.

Roller485._crc8(buffer) int

Calculate CRC8 checksum.

Parameters:

buffer – The data buffer to compute the checksum for.

Returns:

The computed CRC8 value.

class Roller485ToI2CBus(RollerBase)

Constructors

class Roller485ToI2CBus(bus, address, mode)

Initialize the Roller485ToI2CBus object.

Parameters:
  • bus – The RS485 bus instance.

  • address – The motor’s RS485 address. Defaults to _ROLLER485_RS485_ADDR.

Methods

Roller485ToI2CBus.readfrom_mem(addr, mem_addr, nbytes) bytes

Read data from a specific register of the I2C slave device.

Parameters:
  • addr – The I2C slave address to read from.

  • mem_addr – Memory register address.

  • nbytes – The number of bytes to read.

Returns:

The data read from the register.

Throws Exception:

If the read operation fails.

Roller485ToI2CBus.readfrom_mem_into(addr, mem_addr, buf)

Read data from a specific register of the I2C slave device.

Parameters:
  • addr – The I2C slave address to read from.

  • mem_addr – Memory register address.

  • buf – Buffer to store the data.

Roller485ToI2CBus.writeto_mem(addr, mem_addr, buf) Literal[True]

Write data to a specific register of the I2C slave device.

Parameters:
  • addr – The I2C slave address to write to.

  • mem_addr – Memory register address.

  • buf – The data bytes to write.

Returns:

True if the write operation is successful.

Throws Exception:

If the write operation fails.

Roller485ToI2CBus.readfrom(addr, nbytes) bytes

Read data from the I2C slave device via RS485.

Parameters:
  • addr – The I2C slave address to read from.

  • nbytes – The number of bytes to read.

Returns:

The data read from the I2C slave.

Throws Exception:

If the read operation fails.

Roller485ToI2CBus.readfrom_into(addr, buf)

Read data from the I2C slave device via RS485.

Parameters:
  • addr – I2C device address.

  • buf – Buffer to store the data.

Roller485ToI2CBus.writeto(addr, buf, stop) Literal[True]

Write data to the I2C slave device via RS485.

Parameters:
  • addr – The I2C slave address to write to.

  • buf – The data bytes to write.

  • stop – Whether to send a stop bit after writing.

Returns:

True if the write operation is successful.

Throws Exception:

If the write operation fails.

Roller485ToI2CBus.scan(addr, buf, stop) List

Scan for I2C devices on the bus.

Returns:

A list of addresses of the found I2C devices.