MPU6050 - GY 521 with Arduino UNO R3 stuck at "Initializing I2C devices..."

HarzSR:
@zhomeslice - Found out the culprit. Sensor is dead. New sensor is working fine. I tried your code and found this result.

I2C Scanner
Scanning...
I2C device found at address 0x68 !
done

When i tried running the MPU6050 general program or from I2C and got the results for YRP. I have also tried your new Code and got the results too. Am so much happy now. I have screen shots of both the programs.

First screen shot (Values.jpg) for the program that i initially had
Second screen shot (New values.jpg) for the program that you gave latest - MPU6050_Latest_Code

Next what should i do Sir zhomeslice. Please guide me from here. I would like to learn from you.

My Favorite part Getting the bot to ballance :slight_smile:
For starters you will have a lot of testing and retesting to do. The bot you saw the YouTube Video I posted (How to Balance Robot PID totorial in under 2 minutes! ) that will get you a good start and possibly a bot that balances right away.
First lets calibrate our MPU6050
you will get 6 numbers
add them to the mpu6050 file

// supply your own gyro offsets here, scaled for min sensitivity use MPU6050_calibration.ino
// -4232	-706	1729	173	-94	37
//                       XA      YA      ZA      XG      YG      ZG
int MPUOffsets[6] = {  -4232,  -706,   1729,    173,    -94,     37};

Put then in the appropriate location in the BalancingBotBasic.ino file

You will need to modify the motor controls also
Modify These Function to work with your motor control

void FullBreaking () {
  HBridgeLockA(false);
  HBridgeLockB(false);
  SetPWMA(255);
  SetPWMB(255);
}

void SetPWMA(int Speed) {
  analogWrite(PWM_A, Speed);
}

void SetPWMB(int Speed) {
  analogWrite(PWM_B, Speed);
}

/* My HBridge configuration =
I have 2 1/2 H-Bridge chips per motor each chip has one High/Low side select input and an enable input.
The enable input of both 1/2 inputs are tied together and connected to pin 6 for Hbridge A and pin 3 for Hbridge B with PWM enabled
The following code focuses only on the High/Low side select
So by default when the enable input (PWM) is HIGH  The Low side of my HBridge is on.
Now I can enable the High side by connecting 5v to the Select pin (HBgA1HighEn pin 8,HBgA2HighEn pin 7 & HBgB1HighEn pin 4,HBgB2HighEn pin 5).
so for costing all I need to do is set PWM low.
and for full breaking I need to set all High/Low selects to the Low side and enable the H-Bridge (analogWrite(PWM_A, 255);)
Forward motion I put one side high and the other low reverse that and the motor turns in reverse.
Simple :)
*/

void HBridgeLockA(bool HighSide) {
  digitalWrite(HBgA1HighEn, HighSide);
  digitalWrite(HBgA2HighEn, HighSide);
}

void HBridgeLockB(bool HighSide) {
  digitalWrite(HBgB1HighEn, HighSide);
  digitalWrite(HBgB2HighEn, HighSide);
}

void HBridgeGoA(bool Reverse) {
  digitalWrite(HBgA1HighEn, Reverse);
  digitalWrite(HBgA2HighEn, !Reverse);

}

void HBridgeGoB(bool Reverse) {
  digitalWrite(HBgB1HighEn, Reverse);
  digitalWrite(HBgB2HighEn, !Reverse);
}

BalancingBotBasic.ino (16.1 KB)

MPU6050_calibration.ino (7.64 KB)

Hi zhomeslice,

First of all thanks for all these help. But, i am not sure whether am proceeding in the right way or not. So would like to get your advice before i proceed.

I have placed the Sensor as flat as possible. Img included where i have placed it horizontally.

Then i ran the MPU6050_calibration.ino program which you gave me and got this result.

Send any character to start sketch.

MPU6050 Calibration Sketch

Your MPU6050 should be placed in horizontal position, with package letters facing up.
Don't touch it until you see a finish message.

MPU6050 connection successful

Reading sensors for first time...

Calculating offsets...
...
...
...
...
...
...
...
...
...

FINISHED!

Sensor readings with offsets: 7 4 16379 -1 -1 0
Your offsets: 1540 653 1171 30 -28 38

Data is printed as: acelX acelY acelZ giroX giroY giroZ
Check that your sensor readings are close to 0 0 16384 0 0 0
If calibration was succesful write down your offsets so you can set them in your projects using something similar to mpu.setXAccelOffset(youroffset)

Now, where should i add this to the BalancingBotBasic.ino file. Because i dont want to change some value that should not been changed and again get burnt.

I am using a L293D for Motor Driver and 500 RPM normal DC Motor. For power am using 12 V 2 A Lead Acid batteries.

What are my connections from Arduino to L293D motor. Please help me with this.

Thanks you once again.

HarzSR:
Hi zhomeslice,
First of all thanks for all these help. But, i am not sure whether am proceeding in the right way or not. So would like to get your advice before i proceed.

I have placed the Sensor as flat as possible. Img included where i have placed it horizontally.

Then i ran the MPU6050_calibration.ino program which you gave me and got this result.

Send any character to start sketch.
MPU6050 Calibration Sketch
Your MPU6050 should be placed in horizontal position, with package letters facing up.
Don't touch it until you see a finish message.
MPU6050 connection successful
Reading sensors for first time...
Calculating offsets...
FINISHED!
Sensor readings with offsets: 7 4 16379 -1 -1 0
Your offsets: 1540 653 1171 30 -28 38

Data is printed as: acelX acelY acelZ giroX giroY giroZ
Check that your sensor readings are close to 0 0 16384 0 0 0
If calibration was succesful write down your offsets so you can set them in your projects using something similar to mpu.setXAccelOffset(youroffset)

Now, where should i add this to the BalancingBotBasic.ino file. Because i dont want to change some value that should not been changed and again get burnt.

I am using a L293D for Motor Driver and 500 RPM normal DC Motor. For power am using 12 V 2 A Lead Acid batteries.
What are my connections from Arduino to L293D motor. Please help me with this.

Thanks you once again.

Excellent :slight_smile:
Your offsets look great!

I am using a L293D for Motor Driver and 500 RPM normal DC Motor. For power am using 12 V 2 A Lead Acid batteries.
What are my connections from Arduino to L293D motor. Please help me with this.

This Image shows which Pins on your UNO should be hooked to the 1Amp Motor control chip
Untitled-1.jpg

Switch the motor leads to get each motor to run in the same direction and to turn in the correct direction when leaning so that the motors try to bring the bot back to level.

The attached code has your offsets added and the proper settings to drive this motor control.

My only concern is that you may not have enough power through this 1A H-Bridge controller to drive the motors enough to balance.
Lets try it out :slight_smile:
Z

BalancingBotBasicForHarzSR.ino (16.1 KB)

Hi zhomeslice,

Happy day. Great to be back here. First of all a very very great thank you for helping me in this project. Thanks for the code. When i tried to compile the code i got PID_v1.h missing. So i went to Arduino-PID-Library and downloaded PID_v1.h and placed it in C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino.

After this i am getting these following error -

undefined reference to PID::SetOutputLimits(double, double)' undefined reference to PID::SetSampleTime(int)'
.
.
.
undefined reference to `PID::PID(double*, double*, double*, double, double, double, int)'

Basically everything went undefined.

Is that the right library file and where should it be placed. Could you guide me on this

Complete Error Here

I think i found it out. I have only placed the header file and not the class file. After i placed the class file .cpp everything is working fine.

HarzSR:
I think i found it out. I have only placed the header file and not the class file. After i placed the class file .cpp everything is working fine.

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino.

This directory is one way to install libraries but be warned if you upgrade the Arduino IDE these may/will be deleted! I suggest placing them in a folder in the same directory all your sketches are found. Make a directory "libraries" and then ina sub directory PID_v1 and place your files there. Also this is a good spot foot the MPU6050 library files.
Does anyone have a good tutorial link on this?
Z

Well, will do that zhomeslice. And i can you help me with what is the KP fine tuning and all, that was done in the video. Let he say the bot is running with the program you gave me. And right now solving another problem. The bot is too heavy and the motors are failing to rotate when kept on ground. If air lifted and tilted they work perfectly fine. I have also gave the motor proper reference with the help of your video.

Now as far i can see, when i tilt forward the motor moves forward and increases speed upon more tilt up to a level and then shuts off. The same happens on to the backside also. It starts rotating slowly and increases speed on more tilt angle.

I have made Acrylic chassis with 5 MM and the design is below. The acrylic on its own is heavy for the motor it seems.
The Motor Controller i am using
The DC Motor used
Wheels
and BatteriesI am using 4 batteries. 3 connected for 12 V and i as spare battery.

The weight is more than expected. So i have planned to replace the batteries with lighter ones first, if that fails, then am shifting to reduce RPM to 100 and gain torque else if nothing checks out then i have reduce the chassis to 3 MM or less.

Is there any suggestion or feedback you would recommend me on this part

HarzSR:
Well, will do that zhomeslice. And i can you help me with what is the KP fine tuning and all, that was done in the video. Let he say the bot is running with the program you gave me. And right now solving another problem. The bot is too heavy and the motors are failing to rotate when kept on ground. If air lifted and tilted they work perfectly fine. I have also gave the motor proper reference with the help of your video.

Now as far i can see, when i tilt forward the motor moves forward and increases speed upon more tilt up to a level and then shuts off. The same happens on to the backside also. It starts rotating slowly and increases speed on more tilt angle.

I have made Acrylic chassis with 5 MM and the design is below. The acrylic on its own is heavy for the motor it seems.
The Motor Controller i am using
The DC Motor used
Wheels
and BatteriesI am using 4 batteries. 3 connected for 12 V and i as spare battery.

The weight is more than expected. So i have planned to replace the batteries with lighter ones first, if that fails, then am shifting to reduce RPM to 100 and gain torque else if nothing checks out then i have reduce the chassis to 3 MM or less.

Is there any suggestion or feedback you would recommend me on this part

This is a nice looking balancing bot.


I believe that the motor controller is the weak link. I've seen smaller motors provide enough power to make a bot that size balance. you have a few options
The chip you are using can handle about 1 amp MAX your motors could be required to pull 2~4 amps

The bot I demonstrate in the video will blow a 10 Amp fuse if I stall it (Crash it into a tree in my back yard lol).
The L298N based H-Bridge handles about 2 amps and might be good enough for your bot.

I prefer something that can handle closer to 10 amps Like the VNH2SP30 Duel H-Bridge which maxes out at 14 Amps continuous.

But my favorite for the price is the BTS7960B which can handle 40+ Amps with heatsink and around 20 Amps without you get 2 chips per H-Bridge so you will need one of these for each motor
times 2 (one of these for each motor)
This should get you closer to a good balancing bot :slight_smile:
Z

Note that I give the chip model number and not the breakout board model number there are many breakout boards that use these chips to choose from and most will be adequate to meet your needs.

Hi zhomeslice,

Let me say what i did today. The weight of the Chassis is 856 gms and Batteries 974 gms. The torque of the motor is 2 Kg and i doubt that it will move it. I have upgraded the Motor Driver to L298N Driver.

I tried removing the batteries and keeping the chassis and motor alone and powering from long length wire, the bot moved. but still it is not stable.

The fall rate is faster than movement rate. The bot is falling and the motor is working, but the bot is falling faster than the motor can counter act it. How to do the balancing of it. The motor is a 500 RPM motor

Could you also help me with, Kp, Ki, Kd - What are these and how to use them to calibrate it. As i can see in your video it makes the bot stable. So what should i do to make mine stable