ESP32-C6 Low Power hanging device?

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

Re: ESP32-C6 Low Power hanging device?

Postby WaveRider » Tue Apr 16, 2024 9:52 am

@iisfaq: I followed your guide and was now able to select the DFRobot Firebeetle C6 board and run your code example.

Unfortunately, regardless of what I try, the board never wakes up (just as you describe). Even worse, I cannot use deep sleep either.
I tried the suggestion from @boarchuz and moved the esp_sleep_timer_wakeup. I also tried adding the delay after digitalWrite(LED_BUILTIN, HIGH). Nothing seems to work. Behaviour is the same on the smaller Beetle C6.
The same code runs without problems on a DFRobot Firebeetle ESP32-E.

I wonder if anyone has a functioning example using sleep modes on the Firebeetle C6 or on any other ESP32-C6 board. I could not find anything in the web. Espressif examples are generic and (for me) too time consuming to test.

For now, I give up and continue with the Firebeetle ESP32-E. The C6 variants are nice and affordable but useless for me without low power functions.

@lbernstone: the Firebeetle C6 is not on Jason2866's list. I will check back from time to time.

Thanks to both of you for your promt replies!

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

Re: ESP32-C6 Low Power hanging device?

Postby lbernstone » Wed Apr 17, 2024 3:27 am

This is a snip from a deep sleep app on esp32-c6

Code: Select all

  log_v("to sleep");
  rtc_gpio_pullup_en(PIN_DN);
  rtc_gpio_pulldown_dis(PIN_DN);
  rtc_gpio_pullup_en(PIN_UP);
  rtc_gpio_pulldown_dis(PIN_UP);
  rtc_gpio_pullup_dis(PIN_IR);
  rtc_gpio_pulldown_dis(PIN_IR);
  uint64_t wakeup_pins = (1ULL<<PIN_IR) | (1ULL<<PIN_UP) | (1ULL<<PIN_DN);
  esp_sleep_enable_ext1_wakeup(wakeup_pins, ESP_EXT1_WAKEUP_ANY_LOW);
  uint64_t slp = TIME_SLEEP-micros();
  esp_sleep_enable_timer_wakeup(slp);
  Serial.printf("sleep: %llu\n", slp);
  Serial.flush();
  esp_sleep_enable_timer_wakeup(slp);
  esp_deep_sleep_start();

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

Re: ESP32-C6 Low Power hanging device?

Postby WaveRider » Thu Apr 25, 2024 10:34 pm

@lbernstone: that did the trick - thanks again for getting me on track. I can now use my DFRobot Beetle ESP32-C6 in low power mode.

[slightly off topic]
In case anyone is interested: here is my code for a motion detector sending alarms via ESP NOW.
I expect a runtime of several days with a 500mAh LiPo battery (power consumption Beetle + radar ~3.5 mA in deep sleep mode).
As the project is a children's toy to play detective, I guess this is sufficient ;)

Environment: Arduino IDE 1.8.19 with the hints from @iisfaq to include board definitions.

Code: Select all

//
// Detect motion using doppler radar module RWCL-0516 and send alarm via ESP NOW.
// Tested with DFRobot Beetle ESP32-C6. The radar module can be run on 3.3V (connecting Beetle 3.3V to RWCL-0516 3.3V).
// RWCL-0516 output is connected to GPIO 6.
//
// WiFi interferes with RWCL-0516. If ESP32 is mounted near the radar module, reliable readings are only possible when WiFi is off.
// This is considered here: WiFi is only active while the RWCL-0516 alarm is HIGH anyway.
//
// After each alarm, the first sleep phase waits for the alarm signal to end.
// In the second sleep phase, the system is "armed" and waits for the next alarm.
//

#include "WiFi.h"
#include <esp_now.h>

uint8_t receiverAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
esp_now_peer_info_t peerInfo;
bool blSendSuccessful;

unsigned long start = 0;
unsigned long diff = 0;

void GoToSleep(bool blAlarm) {
  uint64_t wakeup_pins = (1ULL << GPIO_NUM_6); // several pins possible, e.g. "(1ULL<<GPIO_NUM_6) | (1ULL<<GPIO_NUM_13)"
  if (blAlarm) { // Alarm on: sleep and wait for end of alarm pulse
    esp_sleep_enable_ext1_wakeup(wakeup_pins, ESP_EXT1_WAKEUP_ANY_LOW);
  }
  else { // Alarm off: sleep and wait for next alarm
    esp_sleep_enable_ext1_wakeup(wakeup_pins, ESP_EXT1_WAKEUP_ANY_HIGH);
  }
  esp_deep_sleep_start();
}

// Check send success (callback when ESP NOW data is sent)
void OnDataSent(const uint8_t *receiverAddress, esp_now_send_status_t status) {
  blSendSuccessful = !status; // somewhat dubious conversion enum ==> bool, but works as expected.
}

void setup() {

  // Alarm active?
  bool blAlarm;
  pinMode(GPIO_NUM_6, INPUT);
  blAlarm = digitalRead(GPIO_NUM_6);
  if (!blAlarm) {GoToSleep(blAlarm)}; // Alarm off: go to sleep and wait for new alarm

  // Alarm active: flash onboard LED
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH); delay(10); digitalWrite(LED_BUILTIN, LOW);

  // Prepare ESP NOW to send alarm
  WiFi.mode(WIFI_STA);
  esp_now_init();
  esp_now_register_send_cb(OnDataSent);
  memcpy(peerInfo.peer_addr, receiverAddress, 6);
  peerInfo.channel = 0;
  peerInfo.encrypt = false;
  esp_now_add_peer(&peerInfo);

  // Send alarm (as receiver sleeps up to 600ms, repeat for 600ms + extra 50ms, allowing for one missed packet)
  start = millis();
  diff = 0;
  while ((diff <= 650) && (!blSendSuccessful)) { // stop sending if message could be delivered
    char message[6];
    sprintf( message, "%6u", diff ); // for tests: send ms until successful send
    esp_now_send(receiverAddress, (uint8_t *) message, sizeof(message));
    delay(50); // receiver is online for 70 ms so alarm should not be missed if sent every 50 ms
    diff = millis() - start;
  }
  GoToSleep(blAlarm); // sleep and wait for end of alarm signal
}

void loop() {
}

fakhrullahs
Posts: 1
Joined: Wed Jun 05, 2024 10:19 am

Re: ESP32-C6 Low Power hanging device?

Postby fakhrullahs » Wed Jun 05, 2024 10:22 am

Hello. I have the same board and the deep sleep doesn't work, it would just disconnect the serial port but the current consumption remains as if it's active. How did u get it to work?

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

Re: ESP32-C6 Low Power hanging device?

Postby WaveRider » Tue Jun 11, 2024 2:03 pm

@fakhrullahs: could you post yor code and some information about your environment? Perhaps we can then find what's wrong.

Who is online

Users browsing this forum: No registered users and 104 guests