I2C

class brainstem.entity.I2C(module, index)[source]

The I2C class is the interface the I2C busses on BrainStem modules.

The class provides a way to send read and write commands to I2C devices on the entitie’s bus.

Useful Constants:
  • I2C_DEFAULT_SPEED (0)

  • I2C_SPEED_100Khz (1)

  • I2C_SPEED_400Khz (2)

  • I2C_SPEED_1000Khz (3)

getSpeed()[source]

Get the current speed setting of the I2C object.

Returns:

returns a Result object containing one of the constants representing the I2C objects current speed setting.

read(address, length)[source]

Send I2C read command, on the I2C BUS represented by the entity.

Param:

address (int): The I2C address (7bit <XXXX-XXX0>) of the device to read.

Param:

length (int): The length of the data to read in bytes.

Returns:

Result object, containing NO_ERROR and read data or a non zero Error code.

Return type:

Result

setPullup(bEnable)[source]

Set software controlled I2C pullup state.

Sets the software controlled pullup on the bus for stems with software controlled pullup capabilities. Check the device datasheet for more information. This setting is saved by a system.save.

Param:

bEnable (bool): The desired state of the pullup.

Returns:

Return NO_ERROR on success, or one of the common sets of return error codes on failure.

Return type:

Result.error

setSpeed(value)[source]

Set the current speed setting of the I2C object.

Param:

value (int): The constant representing the bus speed setting to apply or this object.

Returns:

returns NO_ERROR on success or PARAMETER_ERROR on failure.

write(address, length, *args)[source]

Send I2C write command, on the I2C BUS represented by the entity.

Param:

address (int): The I2C address (7bit <XXXX-XXX0>) of the device to write.

Param:

length (int): The length of the data to write in bytes.

Param:
data (*int | list): variable number of args of either int or list|tuple of ints.

(int values from 0 to 255)

Returns:

Return NO_ERROR on success, or one of the common sets of return error codes on failure.

Return type:

Result.error