Problem with i2c on a esp8266

Hi,

I want to use a MPU6050 sensor for my project with the adafruit-MPU6050 library.
I started to prototype it on a Uno for ease of connection, and everything works fine, but when I switch to my esp8266, the sensor is not found.
I runned an I2C scanner on my esp8266 , and non device is found, while if I run the scanner on my Uno, it is found on the expected 0x68 I2C address.

In order to check my I2C connection on the esp8266, I tested with another sensor I used previously (a GY-271 magnetometer) and it worked properly for both project file and I2C scanner.

The sensor breakout board has pullups resistors, I am powering everything from an external 5V battery.

I have no idea what to try next as I can't really find out what is at fault... So any suggestion would be very welcomed.

Thanks!

How is the MPU6050 powered and at what voltage ?

Connect the mpu6050 back to the Uno and check it still works.

If it does, the next step will be for you to read the forum guide so that the forum can help you figure out the problem.

No need to post your project code yet. First step, as you already know, is to get i2c scanner to detect it, and we already have that code.

But forum needs to know exactly what esp board you have and exactly what mpu board you have. Post links to the detailed specs of those and post a schematic showing how everything is wired, including power supplies.

It is powered by a 5V power bank ( "helped" by my computer USB port while I'm trying to receive serial for debug).
It's the exact same conditions which works with my other sensor over I2C

Where exactly does it get its power from ?
Is it directly from the power bank or from a pin on the ESP8266 board ? Where is its GND pin connected to ?

Thanks @PaulRB
I connected back to the Uno and it's still working fine.

My esp8266 is from here

My MPU6050 from this reference

Here is the schematic of the connection:

thanks @UKHeliBob
It is powered directly from the power bank (through a prototyping board).
Ground of the power, sensor and the board are connected together on the prototyping board. I just uploaded a schematic on my answer just above.

Also there's a led on the breakout board of the sensor, which is indicating that it is powered properly.

I can see from it's schematic that the mpu board (GY-521) has an onboard 3.3V regulator and it's SDA & SCL pins are pulled up to 3.3V with 2K2 resistors. 2K2 is a little bit low...

The ESP board looks very similar to the common NodeMCU board design. No schematic is provided (the schematic link on that page goes to a pinout diagram; the pinout link goes to another pinout diagram.) The schematic for other NodeMCU shows no pull-ups on the D1 & D2 pins which are the default i2c pins, if I remember.

The GY-271 has 4K7 pull-ups:

thank you so much @PaulRB , it looks like a really good track to explore to solve the problem !

I dunno. I can't see any clear reason why it would not work.

I just tested mpu6050 with a Wemos D1 mini pro, which uses the same chip as your board, I'm pretty sure.

Worked no problem:

12:42:59.640 -> Scanning...
12:42:59.673 -> I2C device found at address 0x68  !
12:42:59.673 -> done

Also tested supplying 3.3V to the mpu6050. This also worked.

The Adafruit MPU6050 library example sketch also worked:

13:11:56.947 -> Acceleration X: -0.24, Y: -0.08, Z: 9.47 m/s^2
13:11:56.947 -> Rotation X: 0.00, Y: 0.05, Z: 0.00 rad/s
13:11:56.947 -> Temperature: 27.93 degC

thanks for the extensive testing!
I don't have it with me now but I will conduct some more tests tomorrow and post my results.

Thanks again for your help

Hi,

So I think I've found the problem. I failed to mention earlier that I have a fairly long cable between my esp8266 and my sensor (3 meters) and when I just switched to shorter jumper cables it works just fine.
I still don't understand why it causes no problem with the uno though.

I've just read I2C is not recommended over long cable distances, but is there something I can do to increase the length it accepts? Should I try to increase the value of the pull up resistors?

The ESP8266 does not have an I2C peripheral and uses a crude, bit-banged function to replace it. This may explain the difference in performance with the Uno.

Apart from stronger pull-up resistors, you could also try lowering the I2C clock rate. Again, on a Uno, this would be straight forward: setClock() - Arduino Reference . For the ESP8266 you could look at this: Run i2c on < 100 kHz · Issue #2524 · esp8266/Arduino · GitHub (which I have not studied in detail).

Thanks a lot @6v6gt ! I'm going to look into this

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.