I2C

Provide I2C functionality for pycm devices.

class mauzr.platform.pycom.i2c.Bus(core, cfgbase='i2c', **kwargs)

Bases: object

Manage an I2C bus.

Parameters:
  • core (object) – Core instance.
  • cfgbase (str) – Configuration entry for this unit.
  • kwargs (dict) – Keyword arguments that will be merged into the config.

Configuration:

  • baudrate (int) - Baudrate of the bus.
  • pins (tuple) - Pins to use for the bus (SDA, SCL) as tuple of strings.
read(address, amount)

Read data from a device.

Parameters:
  • address (object) – The address of the device.
  • amount (int) – How much data to receive at most.
Returns:

Bytes read.

Return type:

bytes

read_register(address, register, amount=None, fmt=None)

Read data from an register of a device.

Parameters:
  • address (object) – The address of the device.
  • register (byte) – Address of the register.
  • amount (int) – How much data to receive at most.
  • fmt (str) – Optional data format passed to struct.unpack() with the received buffer.
Returns:

The received bytes or the unpacked datatype if fmt was given.

Return type:

object

write(address, data)

Write data to a device.

Parameters:
  • address (object) – The address of the device.
  • data (bytes) – Data to write.
Returns:

Number of bytes written.

Return type:

int