Page 1 of 2

newbie issue with i2c

Posted: Thu Oct 08, 2020 4:37 pm
by crowhill67
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.

Re: newbie issue with i2c

Posted: Thu Oct 08, 2020 4:41 pm
by Roberthh
Looks like the pullup resistors are missing.

Re: newbie issue with i2c

Posted: Thu Oct 08, 2020 4:47 pm
by crowhill67
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.

Re: newbie issue with i2c

Posted: Thu Oct 08, 2020 6:05 pm
by Roberthh
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.

Re: newbie issue with i2c

Posted: Thu Oct 08, 2020 7:15 pm
by crowhill67
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.

Re: newbie issue with i2c

Posted: Thu Oct 08, 2020 7:29 pm
by Roberthh
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".

Re: newbie issue with i2c

Posted: Fri Oct 09, 2020 1:52 am
by OutoftheBOTS_
I have set both pins to input pullup before setting up the I2C has fixed this problem in the past.

Re: newbie issue with i2c

Posted: Fri Oct 09, 2020 6:06 am
by Roberthh
@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.

Re: newbie issue with i2c

Posted: Fri Oct 09, 2020 9:20 am
by crowhill67
the wires are bout 5cm (2 inches), I will try a lower frequequency.

Thanks

Re: newbie issue with i2c

Posted: Fri Oct 09, 2020 3:50 pm
by crowhill67
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 :-)