read()) / 16384.0 // Z-axis value // Calculating Roll and Pitch from the accelerometer dataĪccAngleX = ( atan(AccY / sqrt( pow(AccX, 2) + pow(AccZ, 2))) * 180 / PI) - 0.58 // AccErrorX ~(0.58) See the calculate_IMU_error()custom function for more detailsĪccAngleY = ( atan( -1 * AccX / sqrt( pow(AccY, 2) + pow(AccZ, 2))) * 180 / PI) + 1.58 // AccErrorY ~(-1.58) // = Read gyroscope data = // requestFrom(MPU, 6, true) // Read 6 registers total, each axis value is stored in 2 registers //For a range of +-2g, we need to divide the raw values by 16384, according to the datasheetĪccX = ( Wire. write( 0x3B) // Start with register 0x3B (ACCEL_XOUT_H) Wire. */ // Call this function if you need to get the IMU error values for your module Wire.write(0x10) // Set the register bits as 00010000 (1000deg/s full scale) Wire.write(0x1B) // Talk to the GYRO_CONFIG register (1B hex) Configure Gyro Sensitivity - Full Scale Range (default +/- 250deg/s) Wire.write(0x10) //Set the register bits as 00010000 (+/- 8g full scale range) Wire.write(0x1C) //Talk to the ACCEL_CONFIG register (1C hex) Configure Accelerometer Sensitivity - Full Scale Range (default +/- 2g) endTransmission( true) //end the transmission /* write( 0x00) // Make reset - place a 0 into the 6B register Wire. write( 0圆B) // Talk to the register 6B Wire. beginTransmission(MPU) // Start communication with MPU6050 // MPU=0圆8 Wire. */ # include const int MPU = 0圆8 // MPU6050 I2C address float AccX, AccY, AccZ įloat accAngleX, accAngleY, gyroAngleX, gyroAngleY, gyroAngleZ įloat AccErrorX, AccErrorY, GyroErrorX, GyroErrorY, GyroErrorZ įloat elapsedTime, currentTime, previousTime *Īrduino and MPU6050 Accelerometer and Gyroscope Sensor Tutorial Below the code you can find a detail description of it. Here’s the Arduino code for reading the data from the MPU6050 sensor. As an Amazon Associate I earn from qualifying purchases. Breadboard and Jump Wires ………… Amazon / Banggood / AliExpressĭisclosure: These are affiliate links.You can get the components needed for this Arduino Tutorial from the links below:
0 Comments
Leave a Reply. |