diff --git a/src/gyro.cpp b/src/gyro.cpp index a8fa9eb..31ef43d 100644 --- a/src/gyro.cpp +++ b/src/gyro.cpp @@ -25,6 +25,7 @@ SOFTWARE. #include GyroSensor myGyro; +MPU6050 accelgyro; #define GYRO_USE_INTERRUPT // Use interrupt to detect when new sample is ready #define SENSOR_MOVING_THREASHOLD 500 @@ -45,8 +46,7 @@ bool GyroSensor::setup() { Wire.begin(D3, D4); Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having // compilation difficulties - accelgyro.initialize(); - + if (!accelgyro.testConnection()) { Log.error(F("GYRO: Failed to connect to MPU6050 (gyro)." CR)); sensorConnected = false; @@ -54,6 +54,7 @@ bool GyroSensor::setup() { #if !defined(GYRO_DISABLE_LOGGING) Log.notice(F("GYRO: Connected to MPU6050 (gyro)." CR)); #endif + accelgyro.initialize(); sensorConnected = true; // Configure the sensor diff --git a/src/gyro.hpp b/src/gyro.hpp index 5d01859..e04d1ee 100644 --- a/src/gyro.hpp +++ b/src/gyro.hpp @@ -50,7 +50,6 @@ struct RawGyroDataL { // Used for average multiple readings class GyroSensor { private: - MPU6050 accelgyro; bool sensorConnected = false; bool validValue = false; float angle = 0;