Section 4: Flight-Control-Functions.

........... Configure MPU6050 Source Code ............

=== File-Name: 6_Configure_MPU6050_Accel_and_Gyro.ino ==



//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++ Begin Config_MPU6050_Accel_and_Gyro function ++++++++
//             Last Update: 28-11-2021   
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

void Config_MPU6050_Accel_and_Gyro()
 {
    writeTo(MPU_addr,0x19, 0x07);  // Reg.25: Sample Rate divider, set sample rate to 8000/1+7 = 1000Hz

    writeTo(MPU_addr,0x1A, 0x05);       // Reg.26: CONFIG register, disable FSync. 
//    I2C.write(0x1A);                  //Write to the CONFIG register (1A hex)
//    I2C.write(0x05);                  //Set Low Pass Filter to 10Hz.Register bits are 00 000 101=0x05

    writeTo(MPU_addr,0x6B, 0x00);     // Reg.107: Setup the MPU-6050`s PWR_MGMT_1 register,
                                      // set to zero (wakes up the MPU-6050)
//    I2C.write(0x6B);                //Write to the PWR_MGMT_1 register (6B hex)
//    I2C.write(0x00);                //Set register bits as 00000000 to activate gyro


//GYRO==GYRO==GYRO==GYRO==GYRO==GYRO====GYRO==GYRO==GYRO==GYRO== 
//    I2C.write(0x1B);                  Write to the GYRO_CONFIG register (1B hex)
 
//    scale +/-500 deg/s => 65.5 bitspdegpsec. Bij 16bit is 2**16 => 65536/(2*500)=65.5 bits/deg/s
//    I2C.write(0x08);                  Set the register bits as 000 01 000 => 0x08 (set to 500dps full scale)

//    scale +/-250 deg/s => 131 bitspdegpsec. Bij 16bit is 2**16 => 65536/(2*250)=131 bits/deg/s
//    I2C.write(0x00);                  Set the register bits as 000 00 000 => 0x00 (set to 250dps full scale)
    
     writeTo(MPU_addr,0x1B, 0x00);      //Reg.27: Setup the MPU-6050`s GYRO_CONFIG register, disable gyro self tests,
//     DigitPerdps = 131;                 //Gyro-Rate: 250 deg/s => 131, 500 deg/s => 65.5


//ACCEL==ACCEL==ACCEL==ACCEL==ACCEL==ACCEL==ACCEL==ACCEL==ACCEL=
      writeTo(MPU_addr, 0x1C, 0x10);    // Reg.28: ACCEL_CONFIG register,     
//    I2C.write(0x1C);                  Write to the ACCEL_CONFIG register (1C hex)
//    I2C.write(0x10);                  disable accel self tests, scale of +-8g=>000 10 000=0x10, no DHPF
//      Sensitivity = 4096; //LSB/g bij +/-8g Full Scale Range

  Serial.println("Sensor MPU6050 has been configured");  
  
  } 

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++ End Config_MPU6050_Accel_and_Gyro function ++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Free-Drones Company 2022