Need Help With MPU 6050 stabilization system

Discussion in 'Embedded Systems and Microcontrollers' started by Umindu, Sep 3, 2015.

  1. Umindu

    Thread Starter New Member

    Sep 1, 2015
    25
    0
    I need help with mpu 6050 with arduino. i finally managed to connect arduino nano with gyro and two servos.but when i tilt the servo left the gyro turns left and when i tilt the servo right the servo arm turns right.I need to make it opposite so the stabilization can be done
    this is the code i use

    #include <Wire.h>
    #include <Servo.h>

    constintMPU=0x68;// I2C address of the MPU-6050

    int16_t GyX,GyY;//Variabile int a 16bit

    Servo ServoMot_X;
    Servo ServoMot_Y;

    voidsetup(){
    Wire.begin();
    Wire.beginTransmission(MPU);
    Wire.write(0x6B);// PWR_MGMT_1 register
    Wire.write(0); // set to zero (wakes up the MPU-6050)
    Wire.endTransmission(true);
    ServoMot_X.attach(8);
    ServoMot_Y.attach(9);
    Serial.begin(9600);
    }
    voidloop(){
    Wire.beginTransmission(MPU);
    Wire.write(0x3B);// starting with register 0x3B (ACCEL_XOUT_H)
    Wire.endTransmission(false);
    Wire.requestFrom(MPU,14,true);// request a total of 14 registers
    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)

    intPosServo_X=map(GyX,-16000,16000,0,179);
    intPosServo_Y=map(GyY,-16000,16000,0,179);
    ServoMot_X.write(PosServo_X);
    ServoMot_Y.write(PosServo_Y);

    Serial.println("Giroscopio");
    Serial.print("Asse X : ");Serial.println(PosServo_X);
    Serial.print("Asse Y : ");Serial.println(PosServo_Y);
    Serial.println(" ");
    delay(100);
    }
    please help
     
Loading...