Self Balancing Device

Hi everyone.
Recently I am doing a little project on a self balancing device, which contains of 3 servo motors, arduino uno and MPU6050.
However, it seems that my MPU6050 is different from most of the online resources.


It gets 8 pins but without the usual int pin.
May I know how I can connect it to the arduino board and how the code will be to get the gyro raw data (x,y,z) in serial monitor. I think after the raw data can be obtained, I can set up suitable servo motor to compensate the movement.
Thanks everyone.

Hi tobbykan

Please post a link to the MPU6050 module you are using.

Regards

Ray

Hi Ray
Sorry for my late reply.
http://www.ewallpk.com/index.php?id_product=120&controller=product&id_lang=1
This is the link I am referring to. I just found it quite different with the most MPU6050 I found online.
Thanks!
Tobby

Hi Tobby

Looks like that particular board has a microcontroller built into it to carry out Kalman filtering and provide a serial interface. The diagrams show serial connections to the external microcontroller (e.g. Arduino) rather than the usual I2C.

You will need to find a datasheet for the breakout board to work out how to control it.

Regards

Ray

Hi Ray,
Thank you so much!!! You inspired me and gave me a clear guide to find out the datasheet. Inside the datasheet folder and I found this example, which I can get raw data. Thanks!

/*
This code is used for connecting arduino to serial mpu6050 module, and test in arduino uno R3 board.
connect map:
arduino mpu6050 module
VCC 5v/3.3v
TX RX<-0
TX TX->1
GND GND
note:
because arduino download and mpu6050 are using the same serial port, you need to un-connect 6050 module when you want to download program to arduino.
Created 14 Nov 2013
by Zhaowen

serial mpu6050 module can be found in the link below:
http://item.taobao.com/item.htm?id=19785706431
*/

unsigned char Re_buf[11],counter=0;
unsigned char sign=0;
float a[3],w[3],angle[3],T;
void setup() {
// initialize serial:
Serial.begin(115200);
}

void loop() {
if(sign)
{
sign=0;
if(Re_buf[0]==0x55)
{
switch(Re_buf [1])
{
case 0x51:
a[0] = (short(Re_buf [3]<<8| Re_buf [2]))/32768.016;
a[1] = (short(Re_buf [5]<<8| Re_buf [4]))/32768.0
16;
a[2] = (short(Re_buf [7]<<8| Re_buf [6]))/32768.016;
T = (short(Re_buf [9]<<8| Re_buf [8]))/340.0+36.25;
break;
case 0x52:
w[0] = (short(Re_buf [3]<<8| Re_buf [2]))/32768.0
2000;
w[1] = (short(Re_buf [5]<<8| Re_buf [4]))/32768.02000;
w[2] = (short(Re_buf [7]<<8| Re_buf [6]))/32768.0
2000;
T = (short(Re_buf [9]<<8| Re_buf [8]))/340.0+36.25;
break;
case 0x53:
angle[0] = (short(Re_buf [3]<<8| Re_buf [2]))/32768.0180;
angle[1] = (short(Re_buf [5]<<8| Re_buf [4]))/32768.0
180;
angle[2] = (short(Re_buf [7]<<8| Re_buf [6]))/32768.0*180;
T = (short(Re_buf [9]<<8| Re_buf [8]))/340.0+36.25;
Serial.print(“a:”);
Serial.print(a[0]);Serial.print(" “);
Serial.print(a[1]);Serial.print(” “);
Serial.print(a[2]);Serial.print(” “);
Serial.print(“w:”);
Serial.print(w[0]);Serial.print(” “);
Serial.print(w[1]);Serial.print(” “);
Serial.print(a[2]);Serial.print(” “);
Serial.print(“angle:”);
Serial.print(angle[0]);Serial.print(” “);
Serial.print(angle[1]);Serial.print(” “);
Serial.print(angle[2]);Serial.print(” ");
Serial.print(“T:”);
Serial.println(T);
break;
}
}
}
}

void serialEvent() {
while (Serial.available()) {

//char inChar = (char)Serial.read(); Serial.print(inChar); //Output Original Data, use this code

Re_buf[counter]=(unsigned char)Serial.read();
if(counter==0&&Re_buf[0]!=0x55) return;
counter++;
if(counter==11)
{
counter=0;
sign=1;
}

}
}

That's good to hear, Tobby.

Could you please edit your last post and put [nobbc][code] [/code][/nobbc] tags around the listing. It makes it much easier for people to read :slight_smile: