newbie issue with i2c

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
crowhill67
Posts: 6
Joined: Tue Sep 01, 2020 12:04 pm

newbie issue with i2c

Post by crowhill67 » Thu Oct 08, 2020 4:37 pm

Hi,

I want to connect an MPU6050 to a doit ESP32 devkit v1. I have hooket up theMPU as follows:

ESP32 MPU
GPIO22 ---> scl
GPIO21 ---> sda
3v3 ---> vcc
gnd ---> gnd

my code in the repl is very simple:

Code: Select all

from machine import I2C, Pin
i2c = I2C(scl=Pin(22), sda=Pin(21)
i2c.scan()
 
This results in all i2c addresses being displayed, not the expected 0x68.

does anyone have an idea what is going wrong?

Regards,
dave.

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

Re: newbie issue with i2c

Post by Roberthh » Thu Oct 08, 2020 4:41 pm

Looks like the pullup resistors are missing.

crowhill67
Posts: 6
Joined: Tue Sep 01, 2020 12:04 pm

Re: newbie issue with i2c

Post by crowhill67 » Thu Oct 08, 2020 4:47 pm

Thanks for your reply,

I was wondering if that was the case, and I added two resistors (10K) from both the scl and sda to 3v3, but I am having the same issue.

Dave.

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

Re: newbie issue with i2c

Post by Roberthh » Thu Oct 08, 2020 6:05 pm

Have you any means to check the state of the SDA and SCL line, either static (multimeter) or dynamic (logc analyzer). The efffect you see is typically caused by the SDA line constant low.

crowhill67
Posts: 6
Joined: Tue Sep 01, 2020 12:04 pm

Re: newbie issue with i2c

Post by crowhill67 » Thu Oct 08, 2020 7:15 pm

Hi Robert,

the sda line seems to be high (3.27v) according to my not so accurate mulitmeter. The thing is I have swapped out the MPU6050 for a HMC5883L, and the problem persists, so I don't think it is the MPU. I will try a different board.

thanks for the help sofar, if you think of anything else i would appreciate it!

regards,
dave.

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

Re: newbie issue with i2c

Post by Roberthh » Thu Oct 08, 2020 7:29 pm

For problems like this a simple logic analyzer works well, which are sold for about 12€ e.g. at Amazon, https://www.amazon.com/-/de/dp/B07K6HXD ... 237&sr=8-5
It gives you an insight of what happens instead of guessing. It works together with the Saleae "Logic" software or the public domain "pulseview".

OutoftheBOTS_
Posts: 799
Joined: Mon Nov 20, 2017 10:18 am

Re: newbie issue with i2c

Post by OutoftheBOTS_ » Fri Oct 09, 2020 1:52 am

I have set both pins to input pullup before setting up the I2C has fixed this problem in the past.

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

Re: newbie issue with i2c

Post by Roberthh » Fri Oct 09, 2020 6:06 am

@OutoftheBOTS_ That would help if there are no external pull-up resistors present. But if I understand the poster correct, there are some installed. So I think it's still a problem with the connection.
@crowhill67: Did you check/change the wires connecting the MPU? How long are these wires? I2C only works with short wires. You can also try a low freq setting, like freq=1000.

crowhill67
Posts: 6
Joined: Tue Sep 01, 2020 12:04 pm

Re: newbie issue with i2c

Post by crowhill67 » Fri Oct 09, 2020 9:20 am

the wires are bout 5cm (2 inches), I will try a lower frequequency.

Thanks

crowhill67
Posts: 6
Joined: Tue Sep 01, 2020 12:04 pm

Re: newbie issue with i2c

Post by crowhill67 » Fri Oct 09, 2020 3:50 pm

Roberthh wrote:
Thu Oct 08, 2020 7:29 pm
For problems like this a simple logic analyzer works well, which are sold for about 12€ e.g. at Amazon, https://www.amazon.com/-/de/dp/B07K6HXD ... 237&sr=8-5
It gives you an insight of what happens instead of guessing. It works together with the Saleae "Logic" software or the public domain "pulseview".
I have asked Santa for one :-)

Post Reply