adafruit_bus_device.i2c_device – I2C Device Manager
- class adafruit_bus_device.i2c_device.I2CDevice(i2c: busio.I2C, device_address: int, probe: bool = True)
Represents a single I2C device and manages locking the bus and the device address.
- Parameters:
Example:
import busio from board import * from adafruit_bus_device.i2c_device import I2CDevice with busio.I2C(SCL, SDA) as i2c: device = I2CDevice(i2c, 0x70) bytes_read = bytearray(4) with device: device.readinto(bytes_read) # A second transaction with device: device.write(bytes_read)
- readinto(buffer: circuitpython_typing.WriteableBuffer, *, start: int = 0, end: int = sys.maxsize) None
Read into
bufferfrom the device.If
startorendis provided, then the buffer will be sliced as ifbuffer[start:end]were passed. The number of bytes read will be the length ofbuffer[start:end].
- write(buffer: circuitpython_typing.ReadableBuffer, *, start: int = 0, end: int = sys.maxsize) None
Write the bytes from
bufferto the device, then transmit a stop bit.If
startorendis provided, then the buffer will be sliced as ifbuffer[start:end]were passed, but without copying the data. The number of bytes written will be the length ofbuffer[start:end].
- write_then_readinto(out_buffer: circuitpython_typing.ReadableBuffer, in_buffer: circuitpython_typing.WriteableBuffer, *, out_start: int = 0, out_end: int = sys.maxsize, in_start: int = 0, in_end: int = sys.maxsize) None
Write the bytes from
out_bufferto the device, then immediately reads intoin_bufferfrom the device.If
out_startorout_endis provided, then the buffer will be sliced as ifout_buffer[out_start:out_end]were passed, but without copying the data. The number of bytes written will be the length ofout_buffer[out_start:out_end].If
in_startorin_endis provided, then the input buffer will be sliced as ifin_buffer[in_start:in_end]were passed, The number of bytes read will be the length ofout_buffer[in_start:in_end].- Parameters:
out_buffer (ReadableBuffer) – write out bytes from this buffer
in_buffer (WriteableBuffer) – read bytes into this buffer
out_start (int) – beginning of
out_buffersliceout_end (int) – end of
out_bufferslice; if not specified, uselen(out_buffer)in_start (int) – beginning of
in_bufferslicein_end (int) – end of
in_buffer slice; if not specified, uselen(in_buffer)