Cannot find I2C devices on ESP32

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
l00p1n6
Posts: 5
Joined: Fri Feb 07, 2020 11:33 pm

Cannot find I2C devices on ESP32

Post by l00p1n6 » Sun Jul 05, 2020 9:59 pm

Hello,

I am trying to make a display (128x32 I2C Pi OLED) to work with esp32 (ESP - WROOM-32)
OLED device is working properly as I have tested it with Arduino using Adafruit's libraries.
Esp32 device is working properly as it runs other code without problem.

I followed a video [https://www.youtube.com/watch?v=qqxgKZCTdUk] and was unsucessful in running the example code on MicroPython git site (https://github.com/micropython/micropyt ... ssd1306.py).
"i2c.writeto()" just kept timming out. It looked like I2C device was not found at all since scanning I2C returned empty list:

Code: Select all

import machine
i2c = machine.I2C(-1, sda=machine.Pin(21), scl=machine.Pin(22))
print(i2c.scan())
I have tried flashing latest stable firmware (esp32-idf3-20191220-v1.12.bin) but that did not help with I2C problem.

Does anyone have a clue on what I am doing wrong?

User avatar
Roberthh
Posts: 2054
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Cannot find I2C devices on ESP32

Post by Roberthh » Mon Jul 06, 2020 5:30 am

The code looks OK. So you should check the wiring (4 wires: Vcc, GND, scl, sda), whether the wires are not broken and the assignment to sda and scl.

ESpy
Posts: 7
Joined: Sun Jun 28, 2020 6:58 am

Re: Cannot find I2C devices on ESP32

Post by ESpy » Mon Jul 06, 2020 3:12 pm

And make sure you really do rotate out the wires and don't just think you have (like I did...).

l00p1n6
Posts: 5
Joined: Fri Feb 07, 2020 11:33 pm

Re: Cannot find I2C devices on ESP32

Post by l00p1n6 » Mon Jul 06, 2020 5:33 pm

Please find wiring attached:
Image
https://ibb.co/L877QKT

Image
https://ibb.co/QF0h1SN

One can see that the green wire is SDA.

NB: I did try to switch the wires on esp32 and got the same result

User avatar
Roberthh
Posts: 2054
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Cannot find I2C devices on ESP32

Post by Roberthh » Mon Jul 06, 2020 6:17 pm

Did you also try to move the ESP32 on the breadboard or use other ESP32 pins for the test. You can use every output capable pin for SDA and SCL. Maybe either the breadboard is defective or the connection between the ESP32 chip and the pin connector.

ESpy
Posts: 7
Joined: Sun Jun 28, 2020 6:58 am

Re: Cannot find I2C devices on ESP32

Post by ESpy » Mon Jul 06, 2020 7:00 pm

ESP32 has hw I2C, doesn't it, as opposed to the 8266? Haven't tried one as yet to see what the configuration differences might be.

That Vcc on the Arduino's definitely 3V3 isn't it?

User avatar
Roberthh
Posts: 2054
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Cannot find I2C devices on ESP32

Post by Roberthh » Mon Jul 06, 2020 7:16 pm

The ESP32 has a hardware I2C, but when the I2C constructor with device ID -1 is called, the software I2C is used. That is done here. But I ran a SSD1306 both with software and hardware I2C. At least the scan function should return the address.

User avatar
Roberthh
Posts: 2054
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Cannot find I2C devices on ESP32

Post by Roberthh » Mon Jul 06, 2020 8:03 pm

SO I looked at the schematics of the Arduino Mega and the Oled Pi device.
The Arduino has 10k pull-up resistors on SCL and SDA. The Oled Pi device has NO pull-up resistors.
So you have to add pull-up resistors to SCL and SDA. 4.7 kOhm is a good value. The ESP32 built-in weak pull-ups are not sufficient. It may work with a very low baud rate, like 10000 or 1000. At least for a scan that could give a result.

l00p1n6
Posts: 5
Joined: Fri Feb 07, 2020 11:33 pm

Re: Cannot find I2C devices on ESP32

Post by l00p1n6 » Mon Jul 06, 2020 9:41 pm

Thank you Roberthh!
Your pullup idea did the trick:

Image
https://ibb.co/4jNZDvw

NB: I didn't have 4.7k so I had to use 10k and 9.1k in parallel which gave me 4764 Ohm.

rpr
Posts: 82
Joined: Sat Oct 27, 2018 5:17 pm

Re: Cannot find I2C devices on ESP32

Post by rpr » Mon Jul 06, 2020 9:47 pm

l00p1n6 wrote:
Mon Jul 06, 2020 9:41 pm
Thank you Roberthh!
Your pullup idea did the trick:

Image
https://ibb.co/4jNZDvw

NB: I didn't have 4.7k so I had to use 10k and 9.1k in parallel which gave me 4764 Ohm.
Nicely done. :D

Post Reply