0

The related hardware diagnostic could be found here: ESP8266 not working with MPU 6050 over wire library and I2C .But I'm not so sure it's a hard ware issue any more because I got the reading for GyroZ was somewhat reasonable but the absolute value of output angle for x and y could be over 360.

An ESP 8266 is connected to MPU6050 and extract the proper data of gyro speed and acceleration GyroX, GyroY, GyroZ and AccX,AccY,AccZ.

The algorithm to obtain the angle was below:

to obtain the elapsed time

  currentTime = micros();            // Current time actual time read
  elapsedTime = (currentTime - previousTime) / 1000000; // Divide by 1000000 to get seconds

to obtain the calculated angle

 Acc_angle_x = atan(AccY / sqrt(pow(AccX, 2) + pow(AccZ, 2)) ) * 180 / PI - Acc_angle_calibration_x;
  Acc_angle_y = -atan(AccX / sqrt(pow(AccY, 2) + pow(AccZ, 2)) ) * 180 / PI - Acc_angle_calibration_y;// a sign was required to correct the angle

and apply the complementary filter

  complementary_angle_x = (complementary_angle_x + GyroX * elapsedTime) * (1 - filter_strength) + Acc_angle_x * filter_strength;
  complementary_angle_y = (complementary_angle_y + GyroY * elapsedTime) * (1 - filter_strength) + Acc_angle_y * filter_strength;

with output

  output_angle_x =  complementary_angle_x;
  output_angle_y = complementary_angle_y;
  output_angle_z=GyroZ;// directly output the angular speed instead of angle

The output was

angle x= 45.98 angle y= -40.72 angle speed z= 0.20
Acc_angle_x = 45.99 Acc_angle_y = -40.72
Acc_angle_calibration_x = -1.05 Acc_angle_calibration_y = -4.19

Thus, apparently, there was something wrong with the calculation of Acc_angle_x and Acc_angle_y because the same code worked for Nano. The function atan was from Math library and all the value were float.

Supplement Information

Also, on nano, the calibration angle for for angle calculated from acceleration was

Acc_angle_calibration_x = -1.05 Acc_angle_calibration_y = -4.19

However, on ESP 8266 the calculated angle from acceleration was kept steady at angle_x and angle_y as shown above.

  • For what input does the Nano calculate which output value, which differs from the output value from the ESP8266 given the same input? – Maximilian Gerhardt Feb 20 at 17:48
  • Acceleration AccX/Y/Z, and angular speed GyroX/Y/Z because the complementary filter was need to calibrate for the drift. The output was output_angle_x/y/z but z direction was simply the angular speed. It's the exactly the same code for nano. But ESP 8266 doesn't work. I thought it was hard ware issue until I saw an angle of over 360. – ShoutOutAndCalculate Feb 20 at 17:52
  • But ESP 8266 doesn't work. I thought it was hard ware issue until I saw an angle of over 360 where is such an angle in the post? Can you give one concrete case with input and output values for which the same code but executed on the 2 different devices give different readings? If we can reproduce it consistently we can help you. – Maximilian Gerhardt Feb 20 at 17:56
  • @MaximilianGerhardt It's the output_angle_x/y, the diagnostic suggested that calculation by atan might be an issue. – ShoutOutAndCalculate Feb 20 at 17:59
  • Are you aware of atan2() that computes all angles correctly from x and y? – the busybee Feb 21 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.