I2C not working

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
lormayna
Posts: 3
Joined: Sun Feb 07, 2021 8:44 pm

I2C not working

Post by lormayna » Mon May 31, 2021 9:21 pm

I am trying to work with a BMP280 on a ESP32-DEVKIT-V1, but I am getting this error:

Code: Select all

>>> from machine import I2C, Pin
>>> bus = I2C(scl=Pin(21), sda=Pin(22))
>>> bus.scan()
[8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5]
Sometimes bus.scan() return only an empty array.

Those are my device's details:

Code: Select all

>>> import os
>>> os.uname()
(sysname='esp32', nodename='esp32', release='1.13.0', version='v1.13 on 2020-09-02', machine='ESP32 module with ESP32')
What I am doing wrong?

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: I2C not working

Post by marcidy » Tue Jun 01, 2021 3:53 am

I don't know if it's necessary, but I pass pull=Pin.PULL_UP when I declare the pins.

Code: Select all

	i2c_bus = I2C(freq=400000, scl=Pin(15, pull=Pin.PULL_UP), sda=Pin(4, pull=Pin.PULL_UP)) 
Check the electrical connections and power to make sure there's sufficient power to the device.

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

Re: I2C not working

Post by Roberthh » Tue Jun 01, 2021 7:11 am

It looks like a wiring problem. So either the pull-up resistors are missing, or the wires are swapped, or you forgot to connect GND, or the BMP280 is not powered, or the BMP280 is set to SPI mode. Most BMP280 breakout boards have pull-up resistors implemented. If not, add some. 4.7 kOhm is a good compromise. Using the built-in pullup of the ESP32 may work with low baud rates, like 10000.

srbpavel
Posts: 10
Joined: Tue Jan 19, 2021 5:09 pm

Re: I2C not working

Post by srbpavel » Sat Jun 12, 2021 10:38 am

hallo lormayna, as robertHH is mentioning: check for short circuit

i had the same experiences with lot's of i2c addresses when some of my machines were outside under the roof in dry place, but during the spring humidity was going up.

- after moving the machine in lab to dry conditions, all works well. so, short circuit.

pavel

Post Reply