User Tools

Site Tools


arduino:mpu-6050

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
arduino:mpu-6050 [2017/08/03 23:05] – created aistisarduino:mpu-6050 [2017/09/03 20:46] (current) – aistis
Line 1: Line 1:
 +MPU6050  MPU-6050 gyroscope accelerometer
 +
 +bord: GY-521   ITG/MPU
 +
 {{:arduino:pasted:20170803-230553.jpeg}} {{:arduino:pasted:20170803-230553.jpeg}}
  
 https://playground.arduino.cc/Main/MPU-6050#short https://playground.arduino.cc/Main/MPU-6050#short
  
 +<code c>
 +    // MPU-6050 Short Example Sketch
 +    // By Arduino User JohnChi
 +    // August 17, 2014
 +    // Public Domain
 +    #include<Wire.h>
 +    const int MPU_addr=0x68;  // I2C address of the MPU-6050
 +    int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
 +    void setup(){
 +      Wire.begin();
 +      Wire.beginTransmission(MPU_addr);
 +      Wire.write(0x6B);  // PWR_MGMT_1 register
 +      Wire.write(0);     // set to zero (wakes up the MPU-6050)
 +      Wire.endTransmission(true);
 +      Serial.begin(250000);
 +    }
 +    void loop(){
 +      Wire.beginTransmission(MPU_addr);
 +      Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
 +      Wire.endTransmission(false);
 +      Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
 +      AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)    
 +      AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
 +      AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
 +      Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
 +      GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
 +      GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
 +      GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
 +      Serial.print(""); Serial.print(AcX);
 +      Serial.print(","); Serial.print(AcY);
 +      Serial.print(","); Serial.print(AcZ);
 +      Serial.print(","); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
 +      Serial.print(","); Serial.print(GyX);
 +      Serial.print(","); Serial.print(GyY);
 +      Serial.print(","); Serial.println(GyZ);
 +      //delay(333);
 +    }
 +</code>
 +
 +{{:arduino:pasted:20170803-230713.png}}
 +
 +{{:arduino:mpu-6050-judinamas.gif}}
 +
 +calibrate
 +
 +https://github.com/kkpoon/CalibrateMPU6050
 +
 +<code c>
 +#include "I2Cdev.h"
 +#include "MPU6050.h"
 +#include "Wire.h"
  
 +#define MPU6050_ACCEL_OFFSET_X -773
 +#define MPU6050_ACCEL_OFFSET_Y 3278
 +#define MPU6050_ACCEL_OFFSET_Z 1660
 +#define MPU6050_GYRO_OFFSET_X  -24
 +#define MPU6050_GYRO_OFFSET_Y  -62
 +#define MPU6050_GYRO_OFFSET_Z  -6
 +  
 +MPU6050 mpu;
 +  
 +void setup() {
 +    Wire.begin();
 +    mpu.initialize();
 +    mpu.setXAccelOffset(MPU6050_ACCEL_OFFSET_X);
 +    mpu.setYAccelOffset(MPU6050_ACCEL_OFFSET_Y);
 +    mpu.setZAccelOffset(MPU6050_ACCEL_OFFSET_Z);
 +    mpu.setXGyroOffset(MPU6050_GYRO_OFFSET_X);
 +    mpu.setYGyroOffset(MPU6050_GYRO_OFFSET_Y);
 +    mpu.setZGyroOffset(MPU6050_GYRO_OFFSET_Z);
 +}
 +  
 +void loop() {
 +}
 +</code>
arduino/mpu-6050.1501790755.txt.gz · Last modified: by aistis