Skip to content
Boris Lovosevic edited this page Mar 3, 2018 · 16 revisions

Editing in progress...

machine Module

Class I2C


This class includes full support for using ESP32 I2C peripheral
Both master and slave modes are supported.



Create the I2C instance object

i2c = machine.I2C(id, mode, speed, sda, scl, slave_addr, slave_bufflen)

Argument Description
id The hardware I2C peripheral ID; 0 or 1 can be used
Default: 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
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.

m = machine.I2C(0, sda=21, scl=22)
s = machine.I2C(1, mode=machine.I2C.SLAVE, sda=25, scl=26, slave_bufflen=512)
Clone this wiki locally