RollerCAN Unit

Support the following products:

RollerCAN

RollerCAN 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 RollerCANUnit
10
11
12title0 = None
13label0 = None
14label1 = None
15label2 = None
16label3 = None
17label4 = None
18i2c1 = None
19rollercan_0 = None
20
21
22output = None
23mode = None
24
25
26def btnb__event(state):
27    global title0, label0, label1, label2, label3, label4, i2c1, rollercan_0, output, mode
28    output = output ^ (0x01 << 0)
29    rollercan_0.set_motor_output_state(output)
30
31
32def btna__event(state):
33    global title0, label0, label1, label2, label3, label4, i2c1, rollercan_0, output, mode
34    mode = mode + 1
35    if mode > 4:
36        mode = 1
37    rollercan_0.set_motor_mode(mode)
38
39
40def setup():
41    global title0, label0, label1, label2, label3, label4, i2c1, rollercan_0, output, mode
42
43    M5.begin()
44    Widgets.fillScreen(0x222222)
45    title0 = Widgets.Title("RollerCAN I2C Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
46    label0 = Widgets.Label("mode:", 1, 63, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
47    label1 = Widgets.Label("motor state:", 2, 108, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
48    label2 = Widgets.Label("speed:", 2, 152, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
49    label3 = Widgets.Label("mode", 40, 215, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
50    label4 = Widgets.Label("on/off", 126, 215, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
51
52    BtnB.setCallback(type=BtnB.CB_TYPE.WAS_CLICKED, cb=btnb__event)
53    BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btna__event)
54
55    i2c1 = I2C(1, scl=Pin(22), sda=Pin(21), freq=100000)
56    rollercan_0 = RollerCANUnit(i2c1, address=0x64, mode=RollerCANUnit.I2C_MODE)
57    rollercan_0.set_motor_output_state(0)
58    output = 0
59    mode = rollercan_0.get_motor_mode()
60    label0.setText(str((str("mode:") + str(mode))))
61    label1.setText(str((str("motor state:") + str(output))))
62
63
64def loop():
65    global title0, label0, label1, label2, label3, label4, i2c1, rollercan_0, output, mode
66    M5.update()
67    label0.setText(str((str("mode:") + str(mode))))
68    label1.setText(str((str("motor state:") + str(output))))
69    if mode == 1:
70        rollercan_0.set_motor_speed(20000)
71        rollercan_0.set_speed_max_current(400)
72        label2.setText(str((str("speed:") + str((rollercan_0.get_motor_speed_readback())))))
73    elif mode == 2:
74        rollercan_0.set_motor_position(1000)
75        rollercan_0.set_position_max_current(400)
76        label2.setText(str((str("position:") + str((rollercan_0.get_motor_position_readback())))))
77    elif mode == 3:
78        rollercan_0.set_motor_max_current(400)
79        label2.setText(str((str("current:") + str((rollercan_0.get_motor_current_readback())))))
80    elif mode == 4:
81        label2.setText(str((str("encoder:") + str((rollercan_0.get_encoder_value())))))
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")

RollerCAN I2C UIFLOW2 Example:

i2c_example.png

rollercan_i2c_fire_example.m5f2

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

RollerCAN CAN UIFLOW2 Example:

can_example.png

rollercan_can_fire_example.m5f2

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

RollerCAN CANToI2C UIFLOW2 Example:

can_i2c_example.png

rollercan_cantoi2c_fire_example.m5f2

class RollerCANUnit

Constructors

class RollerCANUnit(bus, address, mode)

Initialize the RollerCANUnit object based on communication mode.

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

  • address – The motor’s CAN address. Defaults to _ROLLERCAN_CAN_ADDR.

  • mode – The RollerCAN 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_can_baudrate(bps) None

Set the can baudrate.

Parameters:

bps (int) – Baud rate value.

UIFLOW2:

set_can_baudrate.png

RollerBase.get_can_baudrate() int

Get the can baudrate.

Returns:

The current can baudrate.

UIFLOW2:

get_can_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.

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 RollerCAN(RollerBase)

Constructors

class RollerCAN(bus, address, mode)

Initialize the RollerCAN object.

Parameters:
  • bus – The CAN bus instance.

  • address – The motor’s CAN address. Defaults to _ROLLERCAN_CAN_ADDR.

  • mode – Optional mode for setting specific operational mode.

Methods

RollerCAN.create_frame(register, option, data, is_read)

Create a CAN frame for sending commands.

Parameters:
  • register – The register for command identification.

  • option – Command option to specify the data.

  • data – Data payload for the frame.

  • is_read – Whether this frame is for a read command.

RollerCAN.read(register, length)

Send a read command to a specific register.

Parameters:
  • register – The register address to read from.

  • length – Length of data to read.

RollerCAN.i2c_read(register, length)

Read data from an I2C slave via CAN.

Parameters:
  • register – The I2C register address to read from.

  • length – Number of bytes to read.

RollerCAN.i2c_write(register, data, stop)

Write data to an I2C slave via CAN.

Parameters:
  • register – The I2C register address to write to.

  • data – The data to write.

  • stop – Whether to end the transaction with a stop condition.

RollerCAN.write(register, data)

Write data to a specific register.

Parameters:
  • register – The register address to write to.

  • data – Data payload to send to the register.

RollerCAN.read_response()

Read the response data from the CAN bus.

class RollerCANToI2CBus(RollerBase)

Constructors

class RollerCANToI2CBus(bus, address, mode)

Initialize RollerCANToI2CBus object with CAN bus and address.

Parameters:
  • bus – The CAN bus instance.

  • address – The I2C device address, default is _ROLLERCAN_I2C_ADDR.

  • mode – Optional mode for setting specific operational mode.

Methods

RollerCANToI2CBus.readfrom_mem(addr, mem_addr, nbytes) bytes

Read data from an I2C memory register.

Parameters:
  • addr (int) – I2C device address.

  • mem_addr (int) – Memory register address.

  • nbytes (int) – Number of bytes to read.

RollerCANToI2CBus.readfrom_mem_into(addr, mem_addr, buf) None

Read data from an I2C memory register and store it in the provided buffer.

Parameters:
  • addr (int) – I2C device address.

  • mem_addr (int) – Memory register address.

  • buf (bytearray) – Buffer to store the data.

RollerCANToI2CBus.writeto_mem(addr, mem_addr, buf)

Write data to an I2C memory register.

Parameters:
  • addr (int) – I2C device address.

  • mem_addr (int) – Memory register address.

  • buf (bytearray) – Data to write.

RollerCANToI2CBus.readfrom(addr, nbytes) bytes

Read data from an I2C device.

Parameters:
  • addr (int) – I2C device address.

  • nbytes (int) – Number of bytes to read.

RollerCANToI2CBus.readfrom_into(addr, buf) None

Read data from an I2C device and store it in the provided buffer.

Parameters:
  • addr (int) – I2C device address.

  • buf (bytearray) – Buffer to store the data.

RollerCANToI2CBus.writeto(addr, buf, stop)

Write data to an I2C device in chunks.

Parameters:
  • addr (int) – I2C device address.

  • buf (bytes|bytearray) – Data to write.

  • stop (bool) – Whether to end the transaction with a stop condition.

RollerCANToI2CBus.scan() list

Scan for I2C devices on the bus.