ESp032 C6 - Light SleepMode hangs the device?

userHead iisfaq 2024-03-15 14:52:29 539 Views1 Replies

I amusing the Arduino IDE and I am seeing issue swith typing to use the FireBeetle 2 ESP32-C6 with USB + Light Sleep

 

ESP connected to computer via USB cable.

 

#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);

}


When I connect a wire from GND to Pin3/A2 the led flashes and USB output continues - no light sleep is enabled when in this configuration.

 

If I connect 3.3v to Pin3/A2 the led has a single very faint flash and the USB crashes/no longer works. No flashing of the LED after the first inital slight flash. Looks like it is hung.

 

I do not know what is wrong.  Deep sleep works fine with timer to wake up.

 

ps: When I try to upload an .ino file 2KB here I get alert MAX 10MB!


Chris

2024-03-16 18:18:26

OK I have found out some more and I think there is no problem after all.

 

void loop() {

  Serial.println("Loop");

   digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)

delay(1000);

  GoToLightSleep();

    digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW

  Serial.println("Loop after sleep");

  delay(1000);

}

 

Basically the LED needs a delay before the sleep to actually light up otherwise it is just a very small flicker. The 1000 is just to show this off.

 

The serial is broken but I believe that is expected as the ESP32-C6 only has a minimal USB setup or something like that. The chip gets disabled during light sleep but it does not reinitialize after light sleep so USB serial is broken after it wakes up and so you never see any more messages.

 

 

userHeadPic iisfaq