微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从 DeepSleep 模式返回后 Mpu6050 未连接到 Esp32

如何解决从 DeepSleep 模式返回后 Mpu6050 未连接到 Esp32

我是硬件编程的完全菜鸟。我正在做一个项目,我必须从 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 举报,一经查实,本站将立刻删除。