-
Notifications
You must be signed in to change notification settings - Fork 345
i2c
This class includes full support for using ESP32 I2C peripheral
Both master and slave modes are supported.
Argument | Description |
---|---|
id |
The hardware I2C peripheral ID; 0 or 1 can be usedDefault: 0
|
mode |
I2C interface mode; master or slave Use the constants machine.I2C.MASTER or machine.I2C.SLAVE Default: master |
speed freq
|
I2C clock frequency in Hz Default: 100000 |
sda |
I2C sda pin; can be given as integer gpio number or Pin object |
scl |
I2C scl pin; can be given as integer gpio number or Pin object |
slave_address |
I2C slave address to be assigned to this i2c interface. Only used if SLAVE mode is selected 7-bit address, do not use reserved adresses 0x00-0x07 & 0x78-0x7F
|
Default: 32 (0x20) |
|
slave_bufflen |
Size of slave buffer used for master<->slave comunication in bytes; Range: 256 - 4096 Default: 256 Only used if SLAVE mode is selected |
Only sda
and scl
are required, all the others are optional and will be set to the default values if not given.
i2c = machine.I2C(0, sda=21, scl=22)
si2c = machine.I2C(1, mode=machine.I2C.SLAVE, sda=25, scl=26, slave_bufflen=512)
Deinitialize the I2C object, free all used resources.
Scan for i2c devices on I2C bus.
Returns the list of detected addresses.
Can only be used in master mode.
Read nbytes
bytes from i2c device with address addr
.
Bytearray of read bytes is returned.
Can only be used in master mode.
Read from i2c device with address addr
into buffer object buf
.
Size of buf
bytes are read.
Can only be used in master mode.
Write the content of the buffer object buf
to the i2c device with address adr
If optional stop
argument is set to False
, the stop signal is not issued.
Can only be used in master mode.
Argument | Description |
---|---|
addr |
i2c device address |
memaddr |
memory address to be wtitten before read |
n |
number of bytes to read |
adrlen |
optional; number of addres bytes to write, 1 - 4 If not given, number of bytes to send is determined from the memaddr value |
stop |
optional; Default: True If True , stop signal is issued after address writeIf False , repeated start signal is issued after address write |
Write the address to the i2c device with address addr
, then read n
bytes from it.
Bytearray of read bytes is returned.
Can only be used in master mode.
Argument | Description |
---|---|
addr |
i2c device address |
memaddr |
memory address to be wtitten before read |
buf |
Buffer object to read into |
adrlen |
optional; number of addres bytes to write, 1 - 4 If not given, number of bytes to send is determined from the memaddr value |
stop |
optional; Default: True If True , stop signal is issued after address writeIf False , repeated start signal is issued after address write |
Write the address to the i2c device with address addr
, then read from itinto buffer object buf
.
Size of buf
bytes are read.
Can only be used in master mode.
Argument | Description |
---|---|
addr |
i2c device address |
memaddr |
memory address to be wtitten before read |
buf |
Buffer object to write from |
adrlen |
optional; number of addres bytes to write, 1 - 4 If not given, number of bytes to send is determined from the memaddr value |
Write the address to the i2c device with address addr
, then write the content of the buffer object buf
to the device
Can only be used in master mode.