ESP32-C6 Low Power hanging device?

iisfaq
Posts: 4
Joined: Fri Mar 15, 2024 11:04 pm

ESP32-C6 Low Power hanging device?

Postby iisfaq » 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

boarchuz
Posts: 604
Joined: Tue Aug 21, 2018 5:28 am

Re: ESP32-C6 Low Power hanging device?

Postby boarchuz » Sat Mar 16, 2024 7:45 am

You only set esp_sleep_enable_timer_wakeup once. After the first sleep+wakeup, there is no wakeup source configured so it's expected that it remains in light sleep forever.

Try moving esp_sleep_enable_timer_wakeup to the line before esp_light_sleep_start.

iisfaq
Posts: 4
Joined: Fri Mar 15, 2024 11:04 pm

Re: ESP32-C6 Low Power hanging device?

Postby iisfaq » Sat Mar 16, 2024 8:04 am

I found that if I put a delay after digitalWrite(LED_BUILTIN, HIGH); like delay(1000) it is working. But the esp32-c6 has some sort of broken/limited usb support. When it goes to light sleep the usb chip is disabled but it does not get reenabled after coming out of light sleep. Hence usb serial never works after light sleep.

Chris

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32-C6 Low Power hanging device?

Postby lbernstone » Sat Mar 16, 2024 6:36 pm

The esp32-c series only has a hardware USB-CDC device. This would need to be reinitialized every time you come out of deep sleep (the host end is likely to decide the device is unresponsive and dead during light sleep). I personally find that the HWCDC is entirely inappropriate for development. You may note the the Espressif devkits all come a USB->UART adapter on board.

WaveRider
Posts: 5
Joined: Fri Apr 12, 2024 9:26 pm

Re: ESP32-C6 Low Power hanging device?

Postby WaveRider » Fri Apr 12, 2024 9:40 pm

May I ask how you added the library esp_wifi.h to Arduino IDE? The library documentation shows it belongs to esp-idf.

I am looking for a way to test sleep modes with DFRobot Beetle or Firebeetle. Platformio does not seem to support the boards yet (it only supports stable versions of esp-idf extension), and I could not find a way to control sleep functions via Arduino IDE.

Any help is appreciated.

iisfaq
Posts: 4
Joined: Fri Mar 15, 2024 11:04 pm

Re: ESP32-C6 Low Power hanging device?

Postby iisfaq » Sat Apr 13, 2024 1:57 am

This is my Preferences / Additional Boards

Image

http://download.dfrobot.top/FireBeetle/ ... index.json
https://espressif.github.io/arduino-esp ... index.json

I believe you need to have the 3.0.0.alpha3 or later library. By default I think when you click to install the board it defaults to the non alpha v2 version

Image

After that I think the wifi.h libraries worked for me.

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32-C6 Low Power hanging device?

Postby lbernstone » Sat Apr 13, 2024 6:00 pm

WaveRider wrote:
Fri Apr 12, 2024 9:40 pm
Platformio does not seem to support the boards yet (it only supports stable versions of esp-idf extension)
Jason2866 maintains a repo with frequent release packages for platformio.
https://github.com/tasmota/platform-espressif32/

WaveRider
Posts: 5
Joined: Fri Apr 12, 2024 9:26 pm

Re: ESP32-C6 Low Power hanging device?

Postby WaveRider » Sat Apr 13, 2024 9:25 pm

I should have mentioned that I want to test sleep modes on DFRobot C6 boards.
So my question is which toolchain does provide support (including sleep functions) for Beetle 2 ESP32 C6 or Firebeetle 2 ESP32 C6.

@iisfaq: in your initial post, esp_wifi is included in your code. You mention that you use Arduino IDE 2.3.2.
How can esp_wifi be installed/linked in Arduino IDE? I found no hint how to do that.

I would rather use PlatformIO but was not able to install esp-idf extension in a version that supports the DFRobot C6 boards.

Sorry if I am missing something very basic.

iisfaq
Posts: 4
Joined: Fri Mar 15, 2024 11:04 pm

Re: ESP32-C6 Low Power hanging device?

Postby iisfaq » Sun Apr 14, 2024 3:52 am

WaveRider wrote:
Sat Apr 13, 2024 9:25 pm
How can esp_wifi be installed/linked in Arduino IDE? I found no hint how to do that.
I would do this

Go to File - Preferences
In the settings tab at the bottom there should be a title called "Additional board manager Urls" enter the following

http://download.dfrobot.top/FireBeetle/ ... index.json
https://espressif.github.io/arduino-esp ... index.json

Click OK

Now go to tools and under boards select boards manager (CTRL+SHIFT-B)

In board manager you should find a board called "DFRobot ESP32 Boards" by DFROBOT

Install the latest version

Then scroll down to "esp32" by Espessif Systems

Select the latest version of 3.0.0-rc1 or 3.0.0-alpha and select install.

After that you should be able to see the ESP32-C6 board and others and the WIFI should work.

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32-C6 Low Power hanging device?

Postby lbernstone » Sun Apr 14, 2024 4:26 am

The development version is currently at 3.0.0-beta1, which has support for the C6 (and H2) boards.
If you prefer to use platformio, you can use Jason2866's packages that I linked above. The link shows what you add to platformio.ini.
arduino-esp32 is built on top of ESP-IDF. So, you can use almost all the code from the IDF in arduino. You just include the header you want. They are part of the install package. I think esp-wifi.h is pretty safe, but there may be some functionality that will interfere with the arduino core libraries.
You mentioned the esp-idf extension (for VSCode, I assume), which is a separate package from platformio. It is not necessary if you want to program with primarily Arduino code and don't need to modify the sdkconfig.

Who is online

Users browsing this forum: No registered users and 57 guests