Skip to main content
Read, write, and scan I2C (Inter-Integrated Circuit) devices connected to a Lager Box.

Import

Methods

Method Reference

Net.get(name, type=NetType.I2C)

Get an I2C net by name.
Parameters: Returns: I2C Net instance

config(frequency_hz, pull_ups)

Configure I2C bus parameters. Only explicitly-provided parameters are changed; omitted parameters retain their stored values.

scan(start_addr, end_addr)

Scan the I2C bus for connected devices.
Returns: list[int] - List of 7-bit addresses that responded with ACK

read(address, num_bytes, output_format, overrides)

Read bytes from an I2C device.
Returns: list[int] - Received bytes as integers (when output_format="list")

write(address, data, overrides)

Write bytes to an I2C device.

write_read(address, data, num_bytes, output_format, overrides)

Write then read in a single I2C transaction using a repeated start condition. This is the standard pattern for reading device registers.
Returns: list[int] - Received bytes as integers (when output_format="list")

get_config()

Get the raw net configuration dictionary.
Returns: dict - Full net configuration including name, role, instrument, and params

Output Formats

The output_format parameter on read() and write_read() controls how data is returned:

Examples

Basic Device Read

Register Read/Write

Bus Configuration

Multi-Device Setup

Per-Call Configuration Override

Supported Hardware

Notes

  • Net must be configured as NetType.I2C
  • Addresses are 7-bit format (0x00-0x7F), not left-shifted
  • pull_ups only works on the Aardvark adapter; ignored on LabJack T7
  • write_read() uses a repeated start condition for atomic register reads
  • Default scan range (0x08-0x77) skips reserved addresses
  • Configuration changes persist to saved_nets.json for subsequent commands
  • LabJack T7 runs at approximately 450 kHz regardless of requested frequency due to hardware limitations