I2C

Provide I2C functionality for linux.

class mauzr.platform.raspberry.i2c.Bus(core, path)

Bases: object

Manage an I2C bus.

Parameters:
  • core (object) – Core instance.
  • path (str) – Path to the device file.
READ = 0

Indicate a read action in a transaction.

WRITE = 1

Indicate a write action in a transaction.

static base_address(address)
Parameters:address (byte) – The address to extract from.
Returns:Device address from a combined address.
Return type:int
read(address, amount=None, fmt=None)

Read data from a device.

Parameters:
  • address (object) – The address of the device.
  • amount (int) – How much data to receive at most.
  • fmt (str) – May be specified instead of amount. Use struct and fmt to return list of values. If only one values is read it is returned directly.
Returns:

Bytes, object or list of objects read.

Return type:

object

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

transaction(address, actions)

Perform an I2C transaction.

Parameters:
  • address (object) – Address of the device to communicate with.
  • actions (tuple) – Tuple of actions to perform.
Returns:

Transaction results

Return type:

tuple

Raises:

ValueError – If action is invalid.

write(address, data)

Write data to a device.

Parameters:
  • address (object) – The address of the device.
  • data (bytes) – Data to write.
class mauzr.platform.raspberry.i2c.MultiMultiplexerBus(path)

Bases: mauzr.platform.raspberry.i2c.Bus

Manage an I2C with multiple TCA9548A attached.

Parameters:path (str) – Path of the bus.
static base_address(address)
Parameters:address (byte) – The address to extract from.
Returns:Device address from a combined address.
Return type:int
class mauzr.platform.raspberry.i2c.MultiplexerBus(path, multiplexer_address)

Bases: mauzr.platform.raspberry.i2c.Bus

Manage an I2C with an TCA9548A attached.

Parameters:
  • path (str) – Path of the bus.
  • multiplexer_address (byte) – Address of the multiplexer
static base_address(address)
Parameters:address (byte) – The address to extract from.
Returns:Device address from a combined address.
Return type:int