I2C

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

I2CClass: Interface the I2C buses on BrainStem modules. The class provides a way to send read and write commands to I2C devices on the entities bus.

getSpeed()[source]

Get I2C bus speed. This call gets the communication speed for I2C transactions through this API. Speed is an enumeration value which can take the following values. 1 - 100Khz 2 - 400Khz 3 - 1MHz - The speed setting value.

Returns:

Result object containing the requested value when the results error is set to NO_ERROR(0)

Return type:

Result

read(address, readLength)[source]

Read from a device on this I2C bus.

Parameters:
  • address (const int) –

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

  • readLength (const int) –

    • The length of the data to read in bytes.

Returns:

Result object containing the requested value when the results error is set to NO_ERROR(0)

Return type:

Result

setPullup(bEnable)[source]

Set bus pull-up state. This call only works with stems that have software controlled pull-ups. Check the datasheet for more information. This parameter is saved when system.save is called.

Parameters:

bEnable (const bool) –

  • true enables pull-ups false disables them.

Returns:

An error result from the list of defined error codes in brainstem.result

Return type:

unsigned byte

setSpeed(speed)[source]

Set I2C bus speed. This call sets the communication speed for I2C transactions through this API. Speed is an enumeration value which can take the following values. 1 - 100Khz 2 - 400Khz 3 - 1MHz

Parameters:

speed (const unsigned char) –

  • The speed setting value.

Returns:

An error result from the list of defined error codes in brainstem.result

Return type:

unsigned byte

write(address, buffer)[source]

Write to a device on this I2C bus.

Parameters:

address (const int) –

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

Returns:

An error result from the list of defined error codes in brainstem.result

Return type:

unsigned byte