ESP32 as an i2c slave: how to set the address?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
enzo
Posts: 40
Joined: Thu Jun 11, 2020 1:03 am

ESP32 as an i2c slave: how to set the address?

Post by enzo » Sat Apr 03, 2021 11:20 pm

Hi,
I searched everywhere but I couldn't find a way to set an I2C address to an ESP32 with standard MicroPython to make it callable (slave) from another master device.
I could only find this Boris Lovosevic

Code: Select all

https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/i2c
MicroPython which implements all the APIs to make full use of I2C but I don't know if it's a safe implementation for all other features.
Any hint about this? I only need to send short strings to an ESP32 which must in turn answer with other strings.
Thanks for any help!.

oyster
Posts: 26
Joined: Tue Feb 16, 2021 1:21 pm

Re: ESP32 as an i2c slave: how to set the address?

Post by oyster » Sun Apr 04, 2021 4:28 am

i2c.scan() ?

doublevee
Posts: 75
Joined: Mon Jul 02, 2018 11:09 pm

Re: ESP32 as an i2c slave: how to set the address?

Post by doublevee » Sun Apr 04, 2021 8:47 am

I am not entirely certain about the ESP32 support but assuming it uses the standard machine library, this post could be useful to you:

viewtopic.php?t=5320

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ESP32 as an i2c slave: how to set the address?

Post by pythoncoder » Sun Apr 04, 2021 12:16 pm

STM based boards (e.g. Pyboards) are the only targets supporting I2C slave mode.
Peter Hinch
Index to my micropython libraries.

enzo
Posts: 40
Joined: Thu Jun 11, 2020 1:03 am

Re: ESP32 as an i2c slave: how to set the address?

Post by enzo » Sun Apr 04, 2021 1:13 pm

oyster wrote:
Sun Apr 04, 2021 4:28 am
i2c.scan() ?
Thanks for your answer but scan() is a method for scanning the I2C bus and listing all active devices.

enzo
Posts: 40
Joined: Thu Jun 11, 2020 1:03 am

Re: ESP32 as an i2c slave: how to set the address?

Post by enzo » Sun Apr 04, 2021 1:15 pm

doublevee wrote:
Sun Apr 04, 2021 8:47 am
I am not entirely certain about the ESP32 support but assuming it uses the standard machine library, this post could be useful to you:

viewtopic.php?t=5320
Thanks, it's what i was looking for but it's related to a STM board while I've a nodeMCU ESP32.

enzo
Posts: 40
Joined: Thu Jun 11, 2020 1:03 am

Re: ESP32 as an i2c slave: how to set the address?

Post by enzo » Sun Apr 04, 2021 1:18 pm

pythoncoder wrote:
Sun Apr 04, 2021 12:16 pm
STM based boards (e.g. Pyboards) are the only targets supporting I2C slave mode.
Thanks, can't understand why but... ok!
Can't you tell me anything about the loboris uPython version which seems offering a full comprehensive I2C implementation? Is it fully compliant with "official" MicroPython?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ESP32 as an i2c slave: how to set the address?

Post by pythoncoder » Mon Apr 05, 2021 8:54 am

Using slave mode is quite difficult because of the way it is implemented. The slave has to be waiting on a transfer before the master will get a response. This doc describes the issue. What is needed is an asynchronous slave mode. It is possible that threading could be used to achieve this, but there is a question-mark over performance and I haven't tried it.

The Loboris port is abandonware. It is based on a long-superseded version of firmware and is effectively unsupported.
Peter Hinch
Index to my micropython libraries.

robert3
Posts: 1
Joined: Mon Apr 05, 2021 9:56 am
Contact:

Re: ESP32 as an i2c slave: how to set the address?

Post by robert3 » Mon Apr 05, 2021 10:00 am

There are two I2C bus interfaces in the ESP32, which can act as I2C master or slave. We will review the I2C communication protocol for ESP32 with Arduino IDE in this tutorial, namely, the selection of I2C pins, the connection between various I2C devices in one bus, the use of two interfaces for the I2C bus.
skribbl io

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ESP32 as an i2c slave: how to set the address?

Post by pythoncoder » Tue Apr 06, 2021 6:34 am

robert3 wrote:
Mon Apr 05, 2021 10:00 am
There are two I2C bus interfaces in the ESP32, which can act as I2C master or slave. We will review the I2C communication protocol for ESP32 with Arduino IDE in this tutorial, namely, the selection of I2C pins, the connection between various I2C devices in one bus, the use of two interfaces for the I2C bus.
skribbl io
That may be true at the hardware level, but as far as I can see slave mode cannot be accessed from MicroPython as the machine module doesn't support it. Or, if it does, support is undocumented: perhaps you can tell us how to access it.

Documented, tested support only exists in the STM-specific pyb module.
Peter Hinch
Index to my micropython libraries.

Post Reply