MPU-6050 on Wemos D1 mini (I2C)
MPU-6050 on Wemos D1 mini (I2C)
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 ?
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 ?
Re: MPU-6050 on Wemos D1 mini (I2C)
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.
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.
Re: MPU-6050 on Wemos D1 mini (I2C)
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.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.
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.
Re: MPU-6050 on Wemos D1 mini (I2C)
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
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
Re: MPU-6050 on Wemos D1 mini (I2C)
@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
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
Re: MPU-6050 on Wemos D1 mini (I2C)
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.
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.
Re: MPU-6050 on Wemos D1 mini (I2C)
Looking at the datasheet of the MPU-6050, it's actually 0.7*Vdd = 5*0.7 = 3.5V.The TTL high logic level is 2V for 5V, which is smaller than 3.3V, and thus it will work.
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).
Re: MPU-6050 on Wemos D1 mini (I2C)
Except that maximum VDD for the MPU-6050 is 3.46V, not 5V, as specified in the same datasheet.marfis wrote:Looking at the datasheet of the MPU-6050, it's actually 0.7*Vdd = 5*0.7 = 3.5V.The TTL high logic level is 2V for 5V, which is smaller than 3.3V, and thus it will work.
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).
Re: MPU-6050 on Wemos D1 mini (I2C)
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.
Re: MPU-6050 on Wemos D1 mini (I2C)
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.
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.