ESP32 C6 deep sleep drains battery

I'm trying to get an ESP32 C6 (Seeed) to go into deep sleep, and only have it wake up on button press. However, after a few hours of doing nothing, the battery is dead. So I think I either wired the thing wrong, or my code is flawed. Can anyone help me here? I tried to follow the steps here: ESP32 External Wake Up from Deep Sleep | Random Nerd Tutorials

Here's a photo of the setup:

It should be similar to this sketch (just other board and pin 0):

Not even sure if I need the resistor, but I couldn't get it to work without it.

Here's the code. I actually want to use ESP NOW to send a signal, but the battery drain already occurs with just the onboard led blinking, so here's the stripped code:

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

#define BUTTON_PIN_BITMASK (1ULL << GPIO_NUM_0)


void setup(){
  pinMode(LED_BUILTIN, OUTPUT);
  
  digitalWrite(LED_BUILTIN, LOW);

  esp_sleep_wakeup_cause_t wakeup_reason;

  wakeup_reason = esp_sleep_get_wakeup_cause();

  if (wakeup_reason == ESP_SLEEP_WAKEUP_EXT1) {
    
  
    delay(300);
    digitalWrite(LED_BUILTIN, HIGH);
    
    delay(50);
  } else {
    //
  }

  esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH);

  //Go to sleep now
  esp_deep_sleep_start();
}

void loop(){
  //This is not going to be called
}

What happens when you use the Deep Sleep examples that SEEED provide for the ESP32C6 ?

https://wiki.seeedstudio.com/xiao_esp32c6_getting_started/

Well I combined that code with the one from the example. If you check Seeed's code, it's basically the same as mine: Getting Started with Seeed Studio XIAO ESP32C6 | Seeed Studio Wiki

And just to be sure, I implemented this correctly?

Hardware Connections
======================
Push Button to GPIO 0 pulled down with a 10K Ohm
resistor

If I did the maths right, the resistor should not be a problem. Using INPUT_PULLUP mode and reacting to the switch inout going LOW would eliminate any question.

I respect the random nerd, and you've prolly sick of research, but I cannot help but point out

as a source.

How are you measuring the current? I had to get a new meter when my low power projects starting really succeeding.

A meter on its low current setting in parallel with a closed slide switch is handy. Place that combo in series with you load, let the sleep begin, then opens the switch to measure 12 uA or 1.2 uA or whatever.

Some boards don't sleep very well; I have no experience with either you are using from this perspective.

HTH

a7

Over in the support forum that SEEED have for their boards there is post\test report showing the C6 reported as having a deep sleep current of 15uA.

Does it go to sleep then wake up when you push the button?

According to Serial prints, yes. The code works exactly as expected.

@srnet But 15uA shouldn't drain the battery like that right?

Your code has no serial prints.
Are you now using different code from what you show in post #1

I stripped the serial prints. The setup() method I used to test de deep sleep has these at the bottom:

  //Go to sleep now
  Serial.println("Going to sleep now");
  esp_deep_sleep_start();
  Serial.println("This will never be printed");

Your solder job is a possible problem.

You have a battery that will supply 500mA for 1 hour.

So if the deep sleep current is 15uA then the battery should last, if fully charged;

500/.015 = 33,333 hours.

Is there anything on the board, front or back that will drain current and add to the 15uA. Those super low numbers are generally for a bare chip, not a dev board.

Quoting myself. Still wondering.

What he said. How do you know it's even going to sleep?

a7

Oh sorry missed that. Not measuring, I don't have a meter. Will get one this week to check, thanks.

And how I know it's sleeping - I don't for sure. But when I run esp_deep_sleep_start(); the Serial message that follows isn't printed and it's disconnected from my Arduino IDE. On battery I indeed do not know for sure it sleeps, but I kind of assume that would be similar to when it's connected to my laptop.

Are you 100% sure the battery was fully charged?
Did you inspect your soldering?
You could code a single LED blink when waking up and continuous blinking in loop to have feedback from Esp.

Hey @hypercubz
Could you try to setup an led in your circuit? It would help you to see when your MCU is up or sleeping.

Also, could you try to enable and disable pullup/pulldown resistors with rtc_gpio_pulldown_en/rtc_gpio_pullup_dis functions? Check Seeed and espessif documentation (your board is xiao, not arduino).
I had weird misbehavior when my mcu worked fine with deep sleep when was connected to usb, however was totaly randomly woken up when was connected to battery (like in your case).

Another piece of advice (don't take me wrong), try to prototype with a breadboard before soldering. It could help you to easily switch components. I only solder jst-ph2 battery connector to xiao board, and headers, the rest is connected with wires.

And the last one - if you have extra $100, buy Nordic PPK2 power profiler. It blown away my self-delusion that I made efficient low power circuit.

Good luck man

simply measure the current with your digital multimeter.
Another reason for not soldering everything right away.

I bet the current will 8 mA to 15 mA in deep-sleepmode.
Explanation down below.

If you have no digital multimeter this is the right time to buy one.
a DMM is a must if you tinker with microcontrollers

microampere is 15 / 1 million
This is 0.000015 A
0.5 Ah / 0.000015 = 33333.33 hours
or your calculation

500 mAh / 0.015 mA = 33333.33 hours

The real reason that the current is much higher than 15 µA is the TTL-to-USB-chip
and eventually onboard LEDs that are switched on
The board must be totally optimised for super-low-current.

ezSBC has such an ESP32 board with the deep-sleep current as low as 15 µA

I have them and measured the current.
Supplied with 5V 12.9 µA

It appeared my solder job was indeed the cause of leaking current. I used the wrong flux.. Cleaned the whole thing and now it measures 14-16 µA in deep sleep (I also bought a multimeter now). Thanks for the suggestions guys!