问题描述
我是硬件编程的完全菜鸟。我正在做一个项目,我必须从 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
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)