GY-521 MPU-6050 module three-axis acceleration gyroscope 6DOF
เซนเซอร์ GY-521 หรือ MPU 6050 6-axis สามารถวัดได้ 6 แกน 1. Accelerometer วัดความเร่ง 3 แกน 2. Gyroscope วัดความเร็วเชิงมุม 3 แกนโดยต่อแบบ i2c
Introduction:
MPU-6000 is the worlds first 6-axis motion processing system. Compared to multi-component solutions the MPU-6000 eliminates the problem of axial distinction when gyroscopes and accelerators are combined thus reducing the amount of packaging space.
The MPU-6000 includes a 3-axis gyroscope 3-axis accelerator and includes a digital processor hardware acceleration (DMP) that can be connected to an accelerator magnetic sensor or other sensors via an I2C port. Second the engine from the I2C master port outputs a complete 9-core fusion algorithm to the application as a single data stream.
InvenSenses motion processing database manages complex data for motion detection reduces the load on the operating system for motion processing operations and provides architected APIs for application development.
MPU-6000s speed range of full sensing is 250 500 1000 and 2000 / sec (dps) which tracks fast and slow motion and programmable users can feel the fullness of the measurements. Is 2g 4g 8g and 16g transmission products can be transmitted via I2C up to 400kHz or SPI up to 20MHz.
The MPU-6000 can operate at different voltages with a supply voltage VDD 2.5V 5% 3.0V 5% or 3.3V 5% and the VVDIO logic interface supplies 1.8V 5% MPU-. The 6000 comes in a 4x4x0.9mm package (QFN) and is an industry revolutionary model. Other features include a built-in temperature sensor and an oscillator with only 1% variation in the operating environment.
Characteristics:
1.Chip: MPU-6050
2.Power supply: 3v-5V power
3. Gyroscope: + 250 500 1000 2000 / s
4. Acceleration: 2 4 8 16 g
5.Communication: standard IIC communication agreement.
6. Built-in 16 bit AD converter chip 16 bits of data output.
7.Pin spacing 2.54mm
#include Wire.h
#include math.h
const int MPU=0x68;
int16_t AcXAcYAcZTmpGyXGyYGyZ;
double pitchroll;
void setup(){
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop(){
Wire.beginTransmission(MPU);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU14true);
int AcXoffAcYoffAcZoffGyXoffGyYoffGyZoff;
int temptoff;
double ttxtf;
//Acceleration data correction
AcXoff = -950;
AcYoff = -300;
AcZoff = 0;
//Temperature correction
toff = -1600;
//Gyro correction
GyXoff = 480;
GyYoff = 170;
GyZoff = 210;
//read accel data
AcX=(Wire.read()8|Wire.read()) + AcXoff;
AcY=(Wire.read()8|Wire.read()) + AcYoff;
AcZ=(Wire.read()8|Wire.read()) + AcYoff;
//read temperature data
temp=(Wire.read()8|Wire.read()) + toff;
tx=temp;
t = tx/340 + 36.53;
tf = (t * 9/5) + 32;
//read gyro data
GyX=(Wire.read()8|Wire.read()) + GyXoff;
GyY=(Wire.read()8|Wire.read()) + GyYoff;
GyZ=(Wire.read()8|Wire.read()) + GyZoff;
//get pitch/roll
getAngle(AcXAcYAcZ);
//send the data out the serial port
Serial.print(Angle: );
Serial.print(Pitch = ); Serial.print(pitch);
Serial.print( | Roll = ); Serial.println(roll);
Serial.print(Temp: );
Serial.print(Temp(F) = ); Serial.print(tf);
Serial.print( | Temp(C) = ); Serial.println(t);
Serial.print(Accelerometer: );
Serial.print(X = ); Serial.print(AcX);
Serial.print( | Y = ); Serial.print(AcY);
Serial.print( | Z = ); Serial.println(AcZ);
Serial.print(Gyroscope: );
Serial.print(X = ); Serial.print(GyX);
Serial.print( | Y = ); Serial.print(GyY);
Serial.print( | Z = ); Serial.println(GyZ);
Serial.println( );
delay(333);
}
//convert the accel data to pitch/roll
void getAngle(int Vxint Vyint Vz) {
double x = Vx;
double y = Vy;
double z = Vz;
pitch = atan(x/sqrt((y*y) + (z*z)));
roll = atan(y/sqrt((x*x) + (z*z)));
//convert radians into degrees
pitch = pitch * (180.0/3.14);
roll = roll * (180.0/3.14) ;
}