my project is a location tracker which is supposed to be in deepsleep most of the time and wake up when moved. To do so I connected my Arduino Nano ESP32 to an MPU6050. The sketch is based on the magic push button (basically a wake-on-motion interrupt with a certain threshold) in this article:
https://wolles-elektronikkiste.de/en/mp ... ope#anker5
and modified with ChatGPT to include a deepsleep / wake-up routine:
Code: Select all
#include "Wire.h"
#define MPU6050_ADDR 0x68
#define MPU6050_PWR_MGT_1 0x6B
#define MPU6050_INT_ENABLE 0x38
#define MPU6050_WOM_EN 0x06
#define MPU6050_WOM_THR 0x1F
byte interruptPin = 2;
void setup() {
Serial.begin(9600);
Wire.begin();
writeRegister(MPU6050_PWR_MGT_1, 0);
setInterrupt(1); // Set Wake-on-Motion Interrupt Threshold
pinMode(interruptPin, INPUT);
attachInterrupt(digitalPinToInterrupt(interruptPin), motionInterrupt, RISING);
// Set timer to go back into deep sleep after 10 seconds
esp_sleep_enable_timer_wakeup(10 * 1000000); // 10 seconds converted to microseconds
esp_deep_sleep_start();
}
void loop() {
// This code won't be executed after waking up
}
void setInterrupt(byte threshold){
writeRegister(MPU6050_WOM_THR, threshold); // Set Wake-on-Motion Threshold
writeRegister(MPU6050_INT_ENABLE, 1 << MPU6050_WOM_EN); // Enable the interrupt
}
void writeRegister(uint16_t reg, byte value){
Wire.beginTransmission(MPU6050_ADDR);
Wire.write(reg);
Wire.write(value);
Wire.endTransmission();
}
void motionInterrupt() {
Serial.println("ESP32 has been woken up!");
delay(100); // Short delay to ensure the serial print completes
}
I uploaded the code and the Nano seems to turn on every 10 sec, which is what I expected (sensi = 1).
Problem now is that my Windows PC doesnt recognize the Arduino anymore and I cant upload new code to it.
I tried all the available ports put always get the error message:
No DFU capable USB device available.
exit status 74
When connecting a different Nano ESP32 everything works and Port COM9 is automativally chosen. With the "broken" one, Port COM9 is not even an option in the list.
Is there a way to solve this?
Thanks in advance! Let me know if you need any more info.