MPU-6050 on Wemos D1 mini (I2C)

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
bubulle
Posts: 4
Joined: Sat Oct 22, 2016 2:21 pm

MPU-6050 on Wemos D1 mini (I2C)

Post by bubulle » Sun Oct 23, 2016 12:59 pm

Hello all

I have a Wemos D1 mini.
I'm trying to connect it to an accelerometer (MPU-6050 on a GY-521 breakout board) throught I2C. But nothing seems to work.
The GY-521 is powered with 5V, common ground, D1(GPIO5) is connected to SCL and D2(GPIO4) to SDA.

I read the MPU-6050 address can be 0x68 or 0x69 (choice is done with its AD0 pin), so I expect that I2C.scan() give me one of them. But the result is empty.

Here is how I call scan():

>>> from machine import Pin, I2C
>>> i2c = I2C(scl=Pin(5), sda=Pin(4))
>>> i2c.scan() # -> []

What I am doing wrong ?

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: MPU-6050 on Wemos D1 mini (I2C)

Post by torwag » Sun Oct 23, 2016 1:13 pm

Not sure what you doing wrong with the i2c stuff, but you are risking your wemos unit. The esp8266 operates at 3.3V. Connecting 5V logic might work, or blow up your esp, it is outside of the specs. There are controversial discussions but it is definitely not on the save side. You should
a) see or try if the peripheral module operates at 3.3V (datasheet, experiment)
b) use a voltage level converter between the 5V and 3.3V logic.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: MPU-6050 on Wemos D1 mini (I2C)

Post by deshipu » Sun Oct 23, 2016 1:53 pm

torwag wrote:Not sure what you doing wrong with the i2c stuff, but you are risking your wemos unit. The esp8266 operates at 3.3V. Connecting 5V logic might work, or blow up your esp, it is outside of the specs. There are controversial discussions but it is definitely not on the save side. You should
a) see or try if the peripheral module operates at 3.3V (datasheet, experiment)
b) use a voltage level converter between the 5V and 3.3V logic.
That's generally true, but not for I2C. You see, I2C was designed for communication between devices with different powers, and that's why the devices never send their logic high signal over the wire -- the wires are pulled up, and the devices just pull them down to send signals.

Perhaps you are missing the pullup resistors on the SCL and SDA lines?

You could also try using the GPIO0 and GPIO2 lines, as they already have pullups on the d1 mini.

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: MPU-6050 on Wemos D1 mini (I2C)

Post by marfis » Sun Oct 23, 2016 2:20 pm

It also depends to which voltage you have connected the pullup resistors. I2C allows a small deviation between supplies, but not too much.

1) If the resistors are connected to 5V, the 3V device may cause trouble because internal protetcion diodes start to conduct as soon as the voltage applied to the pin raises above say 3.6V. It might be ok because the pullup resistors will limit the amount of current, hence the voltage will level at 3.6V (but current flows through the diode..). So this is not clean.

2) If the the resistors are connected to 3V, the 5V device might not detect logical high (because the threshold voltage of the 5V device is higher than 3V). You'll have to check the datasheet of the MPU-6050 for these voltages. Maybe it just works, maybe not. Also not ideal.

The clean solution for this problem is often found and called a I2C level shifter, using 2 FETs. As described for example here:
http://playground.arduino.cc/Main/I2CBi ... velShifter

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: MPU-6050 on Wemos D1 mini (I2C)

Post by torwag » Sun Oct 23, 2016 4:22 pm

@deshipu:
In theory yes, but practically you are pinning those pull-ups to a certain voltage. Back in time when people used mainly external pull-ups, you might be able to connect it correctly, in that case to 3.3V . But now with internal pull-up you end up with pull-ups connect to VCC. The input voltage high threshold on the 5V side might trouble you in case you only pull up to 3.3V. It might work with one chip and not with another.
For exactly this reason their are many I2C-Level shifter circuits on the market.
Beside of that I never came across a PCB which used different voltage levels across some chips. I know of entire units which operate at 5V, 3.3V or 1.8V but then they used defined interface poiints with appropriate level shifting to talk to each other.
That said I believe you are right, just do not know how this performs in reality.
Hmmm... How does soft-i2c solutions deal with this?

Anyhow the OPs problem is still not solved ;)

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: MPU-6050 on Wemos D1 mini (I2C)

Post by deshipu » Sun Oct 23, 2016 5:01 pm

The internal pull-up resistors will of course be pulling to the board's internal volatge, which is 3.3V.

The same with the pull-up resistors on pins GPIO0 and GPIO2 -- they are connected to the 3.3V on the D1 mini.

The TTL high logic level is 2V for 5V, which is smaller than 3.3V, and thus it will work.

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: MPU-6050 on Wemos D1 mini (I2C)

Post by marfis » Sun Oct 23, 2016 6:41 pm

The TTL high logic level is 2V for 5V, which is smaller than 3.3V, and thus it will work.
Looking at the datasheet of the MPU-6050, it's actually 0.7*Vdd = 5*0.7 = 3.5V.

So your Logic High must be higher than 3.5V - I presume that this will be out of spec if you applied a 3.3V logic high (or well - it may just work because there are some safety margins in the spec).

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: MPU-6050 on Wemos D1 mini (I2C)

Post by deshipu » Sun Oct 23, 2016 8:42 pm

marfis wrote:
The TTL high logic level is 2V for 5V, which is smaller than 3.3V, and thus it will work.
Looking at the datasheet of the MPU-6050, it's actually 0.7*Vdd = 5*0.7 = 3.5V.

So your Logic High must be higher than 3.5V - I presume that this will be out of spec if you applied a 3.3V logic high (or well - it may just work because there are some safety margins in the spec).
Except that maximum VDD for the MPU-6050 is 3.46V, not 5V, as specified in the same datasheet.

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: MPU-6050 on Wemos D1 mini (I2C)

Post by marfis » Mon Oct 24, 2016 4:47 am

yeah you are right. I thought the OPs question was targeting on how to hookup a 5V I2C device to a 3V MCU. sorry about the confusion I may have created.

bubulle
Posts: 4
Joined: Sat Oct 22, 2016 2:21 pm

Re: MPU-6050 on Wemos D1 mini (I2C)

Post by bubulle » Mon Oct 24, 2016 8:29 am

Thanks for all the replies.

I must say i'm new to hardware considerations (i do better at coding).

From what you write, i see that i should be carefull with my pins and consider using (and learning about) pullup resistors.

Some questions:
- What should be the value of the pullup resistors ?
- How do I check that my D1 mini is not damaged ?
- Could my GY-521 have been damaged too ?
- I decided to plug the GY-521 Vin to 5V according to this page (http://playground.arduino.cc/Main/MPU-6050#boards). Can anyone confirm ?

I have another GY-521 and another D1 mini, so I will do more tests (including using Pins 0 and 2) when I get time.

Post Reply