Chain BUS

Chain BUS is a communication bus module that allows multiple devices to connect and communicate with each other in the M5Chain series devices.

API

ChainBUS

class chain.chain.ChainBus(id, tx, rx, verbose=False)

Bases: object

Create a Chain bus instance.

Parameters:
  • id (int) – UART ID.

  • tx (int) – TX pin.

  • rx (int) – RX pin.

  • verbose (bool) – Enable verbose mode. Default is False.

UiFlow2 Code Block:

get_device_num.png

MicroPython Code Block:

from chain import ChainBus

chainbus_0 = ChainBus(2, 32, 33, verbose=True)
send(device_id, cmd, payload, timeout_ms)

Send custom command to device.

Parameters:
  • device_id (int) – Device ID.

  • cmd (int) – Command.

  • payload (bytes) – Data.

  • timeout_ms (int) – receive timeout in milliseconds.

Returns:

Response data.

Return type:

bytes

UiFlow2 Code Block:

send.png

MicroPython Code Block:

chainbus_0.send(1, 0x20, b"ÿ", 3000)
get_device_num(timeout_ms=3000, retries=3)

Get connected device number.

Returns:

Number of connected devices.

Return type:

int

Parameters:
  • timeout_ms (int)

  • retries (int)

UiFlow2 Code Block:

get_device_num.png

MicroPython Code Block:

num = chainbus_0.get_device_num()
deinit()

Deinitialize the Chain bus.