我是硬件编程方面的完全菜鸟。我正在做一个项目,我必须从 mpu6050 计算滚动和俯仰值,同时在 esp32 中实现深度睡眠模式以降低功耗。
我遵循在线教程并设法让 esp32 进入深度睡眠模式,但是在我从深度睡眠模式回来后,我无法重新连接到 mpu6050(mpu6050 状态为 1)。
这是我的代码,
#include "Wire.h"
#include <MPU6050_light.h>
#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 10 /* Time ESP32 will go to sleep (in seconds) */
RTC_DATA_ATTR int bootCount = 0;
RTC_DATA_ATTR bool setupOnce = false;
RTC_DATA_ATTR MPU6050 mpu(Wire);
void setup(){
Serial.begin(115200);
delay(1000); //Take some time to open up the Serial Monitor
//Setup the MPU6050 Once
if (setupOnce == false){
setupOnce = true;
Wire.begin();
byte status = mpu.begin();
Serial.print(F("MPU6050 status: "));
Serial.println(status);
while(status!=0){ } // stop everything if could not connect to MPU6050
Serial.println(F("Calculating offsets, do not move MPU6050"));
delay(1000);
mpu.calcOffsets(true,true); // gyro and accelero
Serial.println("Done!\n");
Serial.println();
}
else{
byte status = mpu.begin();
Serial.print(F("MPU6050 status: "));
Serial.println(status);
while(status!=0){ } // stop everything if could not connect to MPU6050
}
//Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));
//Calculate Values
calcValues();
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
esp_deep_sleep_start();
}
void calcValues(){
mpu.update();
Serial.print(F("TEMPERATURE: "));
Serial.println(mpu.getTemp());
Serial.print(F("(Roll:Pitch:Yaw) - ("));
Serial.print(mpu.getAngleX());
Serial.print(":");
Serial.print(mpu.getAngleY());
Serial.print(":");
Serial.print(mpu.getAngleZ());
Serial.println(")");
Serial.println(F("=====================================================\n"));
}
void loop(){
//This is not going to be called
}