I am using a MPU6050 gyro on an arduino mega adk and I connect two wires to SDA and SCL, as I should. It worked pretty good, till today.
The connection seems to be broken in some way, and whenever I run my program I get strange values, even if the gyro is not connected!!! Do you have any idea? Was I clear enough? Thanks in advance!
Also, do you how I can change from "wire" to "wire1"? I tried to reply all the "wire" in the code with "wire1", but it doesn't recognize "wire1".
pylon:
You are at least missing the GND and 3V3 connection as well as the I2C bus pull-up resistors. Did you desolder the onboard pull-ups of the Mega?
The Mega has only one I2C interface. Wire1 is usable only on the Due, which has two I2C interfaces.
I am not missing the GND and the 3V3 neither, also because the gyro worked pretty good till today. And also i didn't desdol anything on my board...
Peter_n:
The Mega board has a 5V I2C bus, you need a level shifter for the MPU-6050. You might already have broken it.
Without the MPU-6050 connected, you should not receive any data. Can you run the i2c_scanner ?
I read it, but I see an other SDA and SCL on my board, and I don't know why they are there if I cannot use them.
The point is: why everything was working (without the level shifter) till today? What happened to my board? Also I just connect the gyro to an Arduino Leonardo, and now I got the same problem there too. I'm trying to run the i2c_scanner, but it seems not working as it should.
Things are getting really weird...
Do you have any others ideas?
I think that things are not really weird, but really damaged
Sometimes a chip is rated for 3.3V, and it will blow at 3.6V. But it could run for weeks at 5V.
The Leonardo doesn't have the 10k pullup resistors on the board as the Mega does. So you can test the MPU-6050 with the Leonardo (without level shifter).
For now, you need to buy a level shifter and a new MPU-6050
You don't need the level shifter, but you must ensure that no 5V goes to the MPU data pins (that's why you should have removed the onboard pull-ups on the Mega). If you use an UNO or Leonardo and disable the internal pull-ups, include external pull-ups to 3V3 (2k2 will do) and you have a working I2C without any additional hardware (except the pull-ups).
pylon:
You don't need the level shifter, but you must ensure that no 5V goes to the MPU data pins (that's why you should have removed the onboard pull-ups on the Mega).
Are you saying that the digital output of the mega is compatible with 3.3v devices if the onboard pullups are taken off the board?
Are you saying that the digital output of the mega is compatible with 3.3v devices if the onboard pullups are taken off the board?
No, but the I2C bus is designed to allow 5V and 3V3 devices to use the same bus without level shifters. Every device does explicitly not provide the high value, that is ensured by the pull-ups. If needed the devices pull the bus lines low (to GND). If they don't pull to GND the pull-ups pull the lines high. If high level is 3V3, it's high for 5V and 3V3 devices.
pylon, that is more or less true or not true. When a 3.3V I2C devices is connected to the Arduino Uno, it will work, but the high levels are below the official specifications for ATmega328P. Many devices like the ATmega328P don't have real open-collector outputs for the I2C bus, but have for example internal protection diodes. Also the MPU-6050 does not allow 5V at its SDA and SCL pins. So either the MPU-6050 gets damaged with a voltage that is too high, or the ATmega328P gets a voltage below the specifications.
Peter_n, according to the datasheet everything above 2V7 is a logical high for the ATmega328p, so why exactly is this below the official specification?
According to the datasheet the I2C lines are either pulled low or switched as an input but never pulled high so they fulfill the I2C specification (every device which does not react this way is not I2C compliant).
pylon, this is an endless discussion on the forum. But I think it was like this: The ATmega328P needs 0.6 * VCC for a high, but with I2C it needs a 0.7 * VCC.
The internal protection/clamping diodes are always there, so a 3.3V ATmega328P can not have 5V at its I2C pins. I read the datasheet of the MPU-6050 once for this, and they also specify a maximum voltage for the I2C signals.
I'm on a tablet now, so I can't tell which page of the datasheet it is.
For a short answer.. Get another MPU6050 and a level shifter. I've attached an App note from Phillips (NXP) that describes a simple method to do bi-lateral level shifting.
I've used this circuit with 2N7000's and it worked fine for the three devices I built.
There is something hidden from you in the data sheets for the LP2985 and for that matter most if not all linear regulators.. The output cannot sink current... IE If you add a pull-up from 5V to 3.3V (lets use 4K7 ohms as a typical value as this allows for 2 10K pull-ups)...
The pull-up(s) Will bring the 3.3V regulator output to ~ 3.9V - 4.1V which is out of specification for the MPU6050..
See page 14 of the attached data sheet for the MPU6050... @ 2.7 to 3.46 V.
The usual behavior is undefined...
It might work, it might not...
But it will certainly cause the device to fail...
Sooner or later.
I think your MPU6050 died..
This is a link to a MPU6050..Link to the MPU6050
Been there done that.. Once.