6050 won't calibrate

Just got some 6050 sensors and I've been dealing with some interesting problems.

1st. No matter what calibration/example program I run, if it has the ability to tell you that the connection to 6050 failed, it will. Then it will give me data from it. FWIW, it will also show up on I2C scanner. Nobody else has reported this problem, so what's going on? Should I just ignore this, or does it suggest another issue?

2nd. 6050 won't calibrate. I tried the original Luis Rodenas program, told me I wasn't connected then gave me ellipses indefinitely (if I change the program to print out readings instead of ellipses, it does that, so it can read data). I tried the version from Jef Rowberg and no matter what offset I put for x-accel (the first reading it tries to calibrate), the reading never got closer to 0 (Tried a whole range from -2000 to 2000).

So, what's going on? Is problem 2 related to problem 1?

How did you connect the sensor to the Arduino ?
Which Arduino board do you use, and which MPU-6050 module ? (please a link to the module).
Do you use pullup resistors ? Do you use a level shifter ?

It is possible that the i2c_scanner works (barely) and that the I2C bus failes when more data is send.

Connect just one MPU-6050 sensor to the Arduino, and let the i2c_scanner run for a while. Is it stable ? It should never fail.

It's connected to an Arduino UNO thusly:

VCC -> 3.3V
GND -> GND
SDA -> A4
SDL -> A5
INT - > Pin 2 (INT 0)

No pull-ups used, unless they're set by the code. No Level shifter, just ran it off the 3.3v

The module is a Diymall®-Mpu-9250-Nine-axis-Attitude-Acceleration

I tried the link for a tutorial, but it's just 9250 specific libraries, which I installed, but every program that uses it (including the included example 9250_raw has a huge compiling error finding all sorts of things wrong with 9250.h. Not sure what's up with that.

IC2 Scanner never has a problem finding it on 0x68. No matter how long I leave it running.

That module has a voltage regulator for 3.3V, but not a level shifter.
It is better to use the Arduino 5V to the module VCC.
The 10k pullup resistors on the module are too low, because the Uno is a 5V board and the SDA and SCL voltage might get too high. The typical pullup resistors to 3.3V should be 4k7. You can keep it this way, or add an extra 10k pullup resistors for SDA and SCL to 3.3V.

You real problem seems to be the libraries.
Which libraries did you try ? How did you install them ?
Perhaps there is a mix of libraries with similar names.
Do you know the user ‘libraries’ folder, next to your projects ? Perhaps in C:\ \ Documents \ Arduino
What is in the ‘libraries’ folder.

If you have accidently copied user libraries to the Arduino system files, you might have to reinstall, and/or delete the Arduino folder in the Program Files.

Well, tried hooking it up to 5V and got the same results. Then I put 10K resistors between each pin and the sensor and got odd results. The 6050 short example gave me readings of -1 for everything except temp and they didn’t change even when I moved the sensor. Then I ran the 6050 example from InvenSense (copied from the same page as the short example) and the error changed from 0 to 2. Also, the values will switch back and forth between high and low values. For example:

MPU-6050
Read accel, temp and gyro, error = 2
accel x,y,z: 2137, 241, 2
temperature: 123.100 degrees Celsius
gyro x,y,z : 2048, 758, 228,

MPU-6050
Read accel, temp and gyro, error = 2
accel x,y,z: 22792, -3840, 512
temperature: 38.350 degrees Celsius
gyro x,y,z : 8, -2558, -7168,

MPU-6050
Read accel, temp and gyro, error = 2
accel x,y,z: 2137, 241, 2
temperature: 123.100 degrees Celsius
gyro x,y,z : 2048, 758, 228,

The Who am I and PWR_MGMT_1 error are also 2, instead of 0 like they used to be.

Removing the resistors made it go back to they way it was before, which was:

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -984, -112, 15436
temperature: 39.471 degrees Celsius
gyro x,y,z : 39, -55, 73,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -944, -172, 15516
temperature: 39.659 degrees Celsius
gyro x,y,z : 29, -61, 88,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -944, -172, 15432
temperature: 39.518 degrees Celsius
gyro x,y,z : 36, -54, 44,

This readout is pretty much the same if I used 3.3 or 5 v.

As for the libraries. The 9250 ones are relatively new and the problem predates them, so they’re not the issue. I’m using wire.h, 6050.h, and I2Cdev.h, just like everybody else. I downloaded 6050 and 12Cdev.h from the links on the Arduino website. I don’t know if I have to reinstall everything, but could you provide me with links to libraries you know work? I could just replace those 3 and see what happens.

Edit: I installed them the same way I installed everything else (that works). I either used the .zip file installer or just copied the files to /libraries in their folder. There are some Arduino system files in the /library (a folder named Arduino15), but except for the .zip files in the staging/libraries subfolder, there’s nothing there that looks like a library file.

Some progress, I think

I tried running Jeff Rowberg's calibration sketch and found out if I move the sensor around, I can get converging offsets for the accelerometers. Then, the gyros will converge by themselves. I tried it 3 times and got somewhat consistent results:

  1. x: -16, y: -48, z: -121

  2. x: -11, y: 85, z: -91

  3. x: -12, y: -41, z: -70.

I still get the "connection failed" notice and the other (Luis Rodenas) one fails as before.

Not sure what this means, but I thought I'd post this new info.

Please, you have to tell what you are doing. You almost have to spell it out.

The numbers when the error = 0 are okay. The sensor is that noisy. A filter in software makes useable data.
For the MPU-6050 these are the most common used code:
In the Playground section : http://playground.arduino.cc/Main/MPU-6050
The i2cdevlib : http://www.i2cdevlib.com/
The Kalman Guide : http://forum.arduino.cc/index.php?topic=58048.0

However, if the I2C hardware bus has troubles, and the connection is lost, you need to fix that first.

With an extra 10k pullup, I ment a 10k resistor from SDA to 3.3V, and another 10k resistor from SCL to 3.3V.
They way you describe it, you could have done something else.
Without that 10k resistor the MPU-6050 gets a little overvoltage on the pins, but connecting a 5V Arduino Uno to a MPU-6050 is a little outside the specifications anyway.

If you use a link or a library, you have to tell which one.
This is the official i2cdevlib for Arduino on Github : i2cdevlib/Arduino at master · jrowberg/i2cdevlib · GitHub

How long are the wires to the MPU-6050 ?

For testing: Use the 5V to the VCC of the module. Don't connect anything else to the Arduino Uno. Use short wires of 10cm or less.
If you want to make it work within the specifications, you can use a 3.3V Arduino board, or a level shifter for the SDA, SCL, and INT.

Most common mistakes are mismatching voltage levels of the I2C bus, or motors that introduce an enormous amount of electrical noise, or long cables for the I2C bus, or flat ribbon cables with SDA next to SCL.

Sorry for the lack of documentation, but I can’t really tell you where I’ve gotten all my libraries because I don’t rightly remember. I’m pretty sure I got my I2C files from the link you provided, but I don’t remember exactly how I did it. I tried to download it again, but the link takes you to the code itself and not a downloadable file. I’m under the impression that both those files need to be in a directory named I2Cdev in the libraries folder. Is there a link to a .zip file so I can just do the “add .ZIP library” thing? If not, how to I get that code into a proper named file in the proper named folder. I tried cutting and pasting into an Arduino sketch, then renaming to remove the .ino, but that went badly.

My wires are standard prototyping wires for breadboards and are ~20 cm long. I have some solid-core wire that I could cut up, so I’ll try replacing with short pieces of that.

What I did with the resistors is plug the Arduino into the breadboard, link to the other side of the breadboard with the resistors and then put the sensor into the breadboard. So, there was a separate resistor between every Arduino pin and the sensor. This did not work. I’ll give what you described a shot. If I understand correctly, I hook the 3.3 V to the power strip part of the breadboard, then run a couple of 10K resistors from the power strip and connect them to where the SDA/SDL are attached. This will give me 2 wires leading from SDA/SDL. One to A4/A5 and the other to 3.3v. Is that right? Do I still hook up 5 v to VCC, or do I use the 3.3 v?

Keep the 5V to the module VCC. Because when you use 3.3V, the voltage regulator on the module makes about 3.2V, and the sensor chips runs at 3.2V, using output voltages that are maximum 3.2V.
When you use 5V, the voltage regulator on the modules makes a nice 3.3V for the sensor chip.

The i2cdevlib on Github has a zip file (go one level up), but that is not a Arduino library zip file.
Do you know the 'libraries' folder of the user custom libraries I wrote about in my Reply #3 ?
I downloaded the complete i2cdevlib zip file from Github, and I opened the zip file.
I selected the 'Arduino' folder in the zip file, and dragged the things that I needed into the 'libraries' folder. They are I2Cdev, MPU6050 and MPU9150. After that I started the Arduino IDE, and in the menu are the examples that came with those libraries and they compiled.

Downloaded the zip file and put IC2Dev, MPU6050, and MPU9150 in the libraries folder. Given that the programs that require these libraries are now running without error, I can assume they are working. I hooked the sensor to the Arduino using 7cm pieces of solid core wire. Wired the SDA/SDL to the 3.3v via individual 10K resistors. I still have the same problems. Sketches tell me they can’t connect, then give me data from it. Calibration software does not return offsets, except for the Rowberg one, but it’s harder to shake the sensor when it’s connected by short wire. Didn’t get far enough to see if it can still get gyro offsets. Basically, it the same it was before I tried to fix it. The 10K pullups do seem to work well. Right now, the sensor won’t work without it.

It’s not the libraries, it’s not the wires, it’s not the voltage levels. So, what is it?

If it helps I have two of these sensors and have the same problems with both, so it’s definitely not the sensor.

It should work.

You have two sensors, but do you have two Arduino boards ? and what about another breadboard ? or other wires.
Breadboards can have bad contacts, that happens a lot.

Perhaps you have a cheap Arduino Uno clone, that has not enough decoupling, or bad quality components.
Perhaps the ground wire is not connected well.
I would add a few capacitors, at the Arduino (5V and GND, 3.3V and GND) and at the sensor (VCC and GND) and if there is a 3.3V pin also 3.3V and GND.
This is interesting : EEVblog #859 - Bypass Capacitor Tutorial - YouTube
In the end he needs four capacitors for good decoupling.

To get the signals right, you have to use a 3.3V Arduino board or add a level shifter for the SDA, SCL, and INT.

Level shifters can be found everywhere.

At AliExpress, they start at 25 cents, search for : i2c level

I think the cause is that you have bad luck. Maybe the voltage from the USB cable is a little too high or too low, maybe it is a cheap Uno board, maybe the breadboard is not very good. Everything together makes that the I2C bus is not okay. Another possibility is that you have something that you have not told yet. Perhaps two sensors are connected or a motor. A level shifter should fix most of those causes.

Nope, just one sensor, one Arduino. No motors or anything else just yet. I've got a project I'm going to mount this in, but I've got to figure out how to use it first. Then I can worry about motors.

Tried it with genuine Arduino and got the same problem. Tried the capacitors and they made no difference except when I found out linking GND and 5V with a 100pF capacitor will make it not work at all. Changed the Breadboard too. Didn't help. I put in an order for a Adafruit logic 757 level shifter. I'll try hooking up through that.

Thanks for your help. I'm sure i'll figure it out eventually.

So, if I understand you correctly. I should hook up the 5V to VCC (relying on the regulator), GND to GND, and SDA/SDL/Int through the shifter (not relying on the regulator). Do I still use Pullups?

The 5V to VCC is better to get a good 3.3V to the sensor.

You don't need extra pullup resistors, because this one has already pullup resistors on both sides

A level shifter has two sides, a high voltage side and a low voltage side. Apply 5V to the high voltage and 3.3V to the low voltage. Then the signals will be shifted. You can take the 3.3V from the Arduino since the sensor is running with a good 3.3V as well.

Could you check your sensor module (with a magnifier). Are you sure that all the resistors are "103", and they did not accidently put in something else.

There is a whole page about the I2C levels: http://playground.arduino.cc/Main/I2CBi-directionalLevelShifter

A 100pF capacitor at 5V will make it not work ? How is that possible ? I assume it is a mistake ? The component is broken or you connected it to something else ? Can you repeat that with an other capacitor of 100pF ?

If you still have that magnifier nearby, check every soldering on the Arduino and the sensor module.

If nothing works after all, the go to another building, with another computer, buy an other Arduino board and a other sensor module from a different seller with an other breadboard and other wires. I can not guarantee that will work, perhaps you do something that I don't know. For example a very old Arduino IDE, or an Arduino on a conductive rubber layer. Anything is possible.

Well, some good news. I tested out a couple of 6050s I bought and they work fine. Just put some pull-ups on SDA/SDL and you're good to go. Connects successfully and it calibrates. I really didn't think it was going to work, but it did. Thanks for all the help. I've still got that level shifter coming, so maybe there's still hope for the 9250s, but it's nice to know I don't have to get them working.