ESP32-C6 Low Power hanging device?
Posted: Fri Mar 15, 2024 11:15 pm
I bought a DFROBOT FireBeetle ESP32-c6 device and I did some testing with light power saving. So far it just hangs the device.
My code is quite simple
[Codebox]
#include <esp_wifi.h>
#include "driver/uart.h"
#define TIMER_WAKEUP_TIME_US (2 * 1000 * 1000)
void GoToLightSleep() {
if (IsSafeToUseSleep()) {
Serial.println("Going tolight sleep now!");
// To make sure the complete line is printed before entering sleep mode, need to wait until UART TX FIFO is empty
uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
Serial.println("SLEEP!");
Serial.flush();
esp_wifi_stop();
esp_light_sleep_start();
esp_wifi_start();
Serial.println("Wakeup from light sleep now!");
} else {
Serial.println("Light sleep mode was supposed to be enabled - but A2 (PIN3) is not held high!");
delay(1000);
}
}
void setup() {
//set the analog resolution to 12 bits (0-4096)66
// analogReadResolution(12);
uint64_t err = esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US);
if (err != ESP_OK) {
Serial.println("Configure timer as wakeup source failed");
}
pinMode(LED_BUILTIN, OUTPUT);
// Start the serial
Serial.begin(9600);
delay(500);
}
// This code checks if it is safe to use sleep mode. Sleep mode will only be enabled if 3.3v is applied to pin 3 (A2) basically via a jumper from the 3.3v rail. This
// will allow us to disconnect the wire incase of bricking the device due to it sleeping to quickly.
bool IsSafeToUseSleep() {
int A2 = analogRead(3);
return A2 > 3000;
}
void loop() {
Serial.println("Loop");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
GoToLightSleep();
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.println("Loop after sleep");
delay(1000);
}
[/Codebox]
I have a wire connecting from 3V3 to Pin3 (A2) so that I can disable the sleeping if it sort of locks up on restart. This is not needed but since the USB drops I wanted a way to not just kill the ability to reset the device without it going back to sleep.
What I have found is that the device hangs and does not return from light sleep mode. I have no problem using deep sleep.
But I would like to use light sleep for 1-5 seconds. What happens is that the LED should turn on when it goes to sleep and turn off when it comes out of sleep. It however does not, the device hangs or appears to. The USB connection also fails but I believe this is a side effect of light sleep and the USB hardware on the C6.
Any thoughts?
This is a bare bones device being tested so light sleep should work and the code seems to be what I am supposed to use based on examples online.
How would I debug this?
I am using Arduino IDE 2.3.2 and DF Robot Firebeetle C6 board using 3.0.0-a ESP by Espressif
Chris
Chris
My code is quite simple
[Codebox]
#include <esp_wifi.h>
#include "driver/uart.h"
#define TIMER_WAKEUP_TIME_US (2 * 1000 * 1000)
void GoToLightSleep() {
if (IsSafeToUseSleep()) {
Serial.println("Going tolight sleep now!");
// To make sure the complete line is printed before entering sleep mode, need to wait until UART TX FIFO is empty
uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
Serial.println("SLEEP!");
Serial.flush();
esp_wifi_stop();
esp_light_sleep_start();
esp_wifi_start();
Serial.println("Wakeup from light sleep now!");
} else {
Serial.println("Light sleep mode was supposed to be enabled - but A2 (PIN3) is not held high!");
delay(1000);
}
}
void setup() {
//set the analog resolution to 12 bits (0-4096)66
// analogReadResolution(12);
uint64_t err = esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US);
if (err != ESP_OK) {
Serial.println("Configure timer as wakeup source failed");
}
pinMode(LED_BUILTIN, OUTPUT);
// Start the serial
Serial.begin(9600);
delay(500);
}
// This code checks if it is safe to use sleep mode. Sleep mode will only be enabled if 3.3v is applied to pin 3 (A2) basically via a jumper from the 3.3v rail. This
// will allow us to disconnect the wire incase of bricking the device due to it sleeping to quickly.
bool IsSafeToUseSleep() {
int A2 = analogRead(3);
return A2 > 3000;
}
void loop() {
Serial.println("Loop");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
GoToLightSleep();
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.println("Loop after sleep");
delay(1000);
}
[/Codebox]
I have a wire connecting from 3V3 to Pin3 (A2) so that I can disable the sleeping if it sort of locks up on restart. This is not needed but since the USB drops I wanted a way to not just kill the ability to reset the device without it going back to sleep.
What I have found is that the device hangs and does not return from light sleep mode. I have no problem using deep sleep.
But I would like to use light sleep for 1-5 seconds. What happens is that the LED should turn on when it goes to sleep and turn off when it comes out of sleep. It however does not, the device hangs or appears to. The USB connection also fails but I believe this is a side effect of light sleep and the USB hardware on the C6.
Any thoughts?
This is a bare bones device being tested so light sleep should work and the code seems to be what I am supposed to use based on examples online.
How would I debug this?
I am using Arduino IDE 2.3.2 and DF Robot Firebeetle C6 board using 3.0.0-a ESP by Espressif
Chris
Chris