I2C

I2C(etp)

Methods:

Name Description
get_info

Query I²C pin information, bus counts and supported speeds.

init

Initialize I²C bus with speed.

read

Read data from I²C device.

read_reg

Read data from I²C device register.

scan

Scan I²C bus for devices.

write

Write data to I²C device.

write_reg

Write data to I²C device register.

get_info

get_info() -> dict

Query I²C pin information, bus counts and supported speeds.

Returns:
  • dict

    Dictionary containing I²C bus count, supported speeds and pin information.

init

init(bus: int, speed: int) -> int

Initialize I²C bus with speed.

Parameters:
  • bus (int) –

    I²C bus number.

  • speed (int) –

    I²C bus speed in kHz.

Returns:
  • int

    Initialization status.

read

read(bus, addr: int, num_bytes: int) -> list[int]

Read data from I²C device.

Parameters:
  • bus (int) –

    I²C bus number.

  • addr (int) –

    I²C device address.

  • num_bytes (int) –

    Number of bytes to read.

Returns:
  • list[int]

    list[int]: List of bytes read from the device.

read_reg

read_reg(
    bus: int, addr: int, reg: int, num_bytes: int
) -> list[int]

Read data from I²C device register.

Parameters:
  • bus (int) –

    I²C bus number.

  • addr (int) –

    I²C device address.

  • reg (int) –

    Register address.

  • num_bytes (int) –

    Number of bytes to read.

Returns:
  • list[int]

    List of bytes read from the register.

scan

scan(
    bus: int, start_addr: int = 0, end_addr: int = 127
) -> list

Scan I²C bus for devices.

Parameters:
  • bus (int) –

    I²C bus number.

  • start_addr (int, default: 0 ) –

    Start address to scan.

  • end_addr (int, default: 127 ) –

    End address to scan.

Returns:
  • list

    List of I²C device addresses.

write

write(bus, addr: int, data: list) -> int

Write data to I²C device.

Parameters:
  • bus (int) –

    I²C bus number.

  • addr (int) –

    I²C device address.

  • data (list) –

    List of bytes to write.

Returns:
  • int

    Write status.

write_reg

write_reg(
    bus: int, addr: int, reg: int, data: list[int]
) -> int

Write data to I²C device register.

Parameters:
  • bus (int) –

    I²C bus number.

  • addr (int) –

    I²C device address.

  • reg (int) –

    Register address.

  • data (list[int]) –

    List of bytes to write.

Returns:
  • int

    Write status.