Library i2c

To use this library in your code:

import i2c
I2C is a serial communication bus able to address multiple devices along the same 2-wire bus.
To set up an I2C bus:

import i2c

SDA ::= 21
SCL ::= 22

main:
  bus := i2c.Bus
    --sda=SDA
    --scl=SCL
An I2C bus can be associated with a number of devices. Each device must have a unique I2C address. The address can be found in the datasheet for the selected peripheral - it's a 7-bit integer.
In case of the Bosch [BME280 sensor](https://cdn.sparkfun.com/assets/e/7/3/b/1/BME280_Datasheet.pdf), the address is 0x76:

  device := bus.device 0x76
ESP32 target support
All supported ESP32 variants can use Target. The target features differ:
  • ESP32 supports 7-bit and 10-bit addresses. It does not support general-call
  • broadcast or clock stretching while waiting for a target response, so it
  • requires dynamic read responses to be queued before the controller starts
  • reading. The configured default response is always available.
  • ESP32-S2 supports only 7-bit addresses and does not support general-call
  • broadcast. It supports response-time clock stretching.
  • ESP32-C3, ESP32-C6, ESP32-P4, and ESP32-S3 support 7-bit and 10-bit
  • addresses, general-call broadcast, and response-time clock stretching.
General-call broadcast cannot be combined with a 10-bit target address.

Classes

Bus for communicating using I2C.

Device connected using the I2C bus.

Registers for an I2C device.

An I2C target backed by a native register array.

An addressable I2C target.

Globals

The default frequency for I2C communication. 400kHz.

Default native buffer size for an I2C target.

Default maximum time for producing a stretched target response.

Maximum size of an I2C target default response.