logo elektroda
logo elektroda
X
logo elektroda

ESP32, battery back-up and digital potentiometer amplifier control

czarny8322 4965 33
Best answers

Can an ESP32-based radio use a CR2032 battery backup in deep sleep and control a 5 V X9C103 digital potentiometer directly from 3.3 V GPIOs?

An ESP32 can only be battery-backed by a CR2032 if it is already in deep sleep/hibernation with RTC/ULP running; it cannot stay alive in normal Wi‑Fi mode, and the coin cell plus SS34 drop leaves only about 2.5 V at the chip, which is marginal and can reset it [#18249943][#18250398][#18257620] If you need to preserve settings, save them to RTC memory or Flash before sleep, because the main SRAM is lost on deep sleep and only RTC-related data survives [#18250601][#18257930] The thread concluded that the X9C103 can be controlled from 3.3 V ESP32 GPIOs even when powered from 5 V because its inputs are TTL-compatible, so a level shifter is generally not required [#18248618] Be careful with ESP32 boot pins: GPIO12 must not be high at boot, and GPIO14/15 can emit short boot-time PWM pulses that may interfere [#18248919] On the audio path, add a coupling capacitor to remove the DAC DC offset before the divider/pot, otherwise you can get crackling while adjusting volume [#18249781]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18248183
    czarny8322
    Level 11  
    Good morning:) .

    I would be very grateful for constructive answers:) I am building a radio on an ESP32 with battery backup. The amplifier is a PAM8403 module, for which I would like to adjust the signal power from the DAC by software with a digital potentiometer: X9C103 (one channel). Therefore, I have some questions for the following schematic:

    1. does such a battery backup scheme have the right to work?
    2. I have a separate +5V line (missing on the schematic) - since the ESP32 runs on 3.3V, can I connect the VCC for the X9C103 to +5 and its logic will be controlled from the ESP32 pins without some logic state conversion?

    3. does anyone see any errors in the schematic?

    For all answers thank you in advance.



    ESP32, battery back-up and digital potentiometer amplifier control
    .
  • ADVERTISEMENT
  • #2 18248208
    Anonymous
    Level 1  
  • #5 18248618
    jarek_lnx
    Level 43  
    khoam wrote:
    It may work, but if it's going to work like this for longer, get a spare ESP32.
    The standby ESP can always come in handy :) but I don't understand what you are trying to scare the author of the topic with, damage to the ESP from a device that only has inputs? As long as it doesn't burn up the X9C103 then nothing will happen to the ESP either.
    The logic levels of the X9C103 are TTL, so compatible with the 3.3V CMOS outputs.
  • #6 18248919
    Anonymous
    Level 1  
  • #7 18249781
    jarek_lnx
    Level 43  
    khoam wrote:
    I'm not trying to scare you, just trying to develop good habits
    If you're not scare-mongering, why the comment about a back-up ESP? What did you want to show in the manufacturer's documentation? I don't like vague hints, how is an amateur supposed to guess what problem you are writing about when I don't see any problem. Maybe you thought there was an output from the 5V circuit, but you wrote so vaguely that you could always change your mind and no one would know?

    khoam wrote:
    The internet is full of so-called fritzing with ESP, which is a simple (or rather primitive) circuit conversion from AVR.
    Probably this is the case, but what effect does it have on the circuit we are discussing?
    Good habits means checking the facts, and the facts are that the input of a circuit supplied with 5V will not supply voltage to the output of a circuit supplied with 3.3V, i.e. there is no risk of damage to the ESP. The second fact is that the output levels of a 3.3V CMOS chip (ESP) are within acceptable limits for a 5V TTL-compatible input.

    And coming back to the topic, the divider by 11 before the potentiometer is strange, what should be the maximum signal level at the output?
    Another thing is that the DAC has to work with an offset in order to process audio signals correctly, and if you apply a DC voltage from the DAC to the potentiometer, you will hear crackling during the adjustment, before the potentiometer or before the divider there should be a capacitor to cut off the DC component.
  • #8 18249943
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #9 18250398
    jarek_lnx
    Level 43  
    A CR2032 battery might be able to withstand a momentary load of 30mA, but 300mA is not even possible on a short circuit, so such a backup can only work in the case of Hibernation mode and Deep Sleep, when the ESP will have the radio part and the core switched off all the time, leaving RTC and ULP.
    https://lastminuteengineers.com/esp32-sleep-modes-power-consumption/
    https://data.energizer.com/PDFs/lithiumcoin_appman.pdf
  • #10 18250601
    Anonymous
    Level 1  
  • #11 18253596
    Anonymous
    Level 1  
  • #12 18253609
    Anonymous
    Level 1  
  • #13 18257538
    czarny8322
    Level 11  
    Thank you for your replies, and confirmation that it does not need logic state conversion.

    1. battery backup - I only care about remembering the current time (RTC&ULP). From what I've read, assuming the ESP32 will detect a change in voltage, then go into "Deep sleep" mode then the CR2032 should pass the test. There are also LIR2450 rechargeable batteries available at 3.6V - if the regular CR2032 doesn't pass then I'd replace it. Larger 18650 type solutions are unfortunately out of the question as there is no room for them for this project.

    2 Voltage divider: I downloaded the schematic and library from the following project:
    https://www.xtronical.com/basics/audio/dacs-on-esp32/
    https://www.youtube.com/watch?v=xotWNWUh7i4
    a1e103bb8 .
    Regarding power - the PAM amplifier that is in the project is 2x3W - but I only need 1x1W - I don't have room for large speakers. So perhaps you know of some other circuit/module that I could use?
  • #14 18257620
    TvWidget
    Level 38  
    czarny8322 wrote:
    Battery backup - I only care about remembering the current time (RTC&ULP). From what I've read, assuming the ESP32 will detect a change in voltage, then go into "Deep sleep" mode then the CR2032 should pass the test.
    .
    You are making a logical error. An ESP32 powered by a CR2032 battery will not detect anything. It will stop working.
  • #15 18257644
    czarny8322
    Level 11  
    Are you sure? As far as I know, in the "Deep Sleep" mode I can use the ULP that supports this ADC, with which I could study the change in voltage with which the ESP32 is supplied,

    The other possibility is an external wake up, using some transistor that would simulate a button after a voltage change.
  • ADVERTISEMENT
  • #16 18257657
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #17 18257738
    TvWidget
    Level 38  
    czarny8322 wrote:
    it will detect a change in voltage and then switch to "Deep sleep"
    .
    So which mode should the voltage change detection take place in ?
  • #18 18257755
    Anonymous
    Level 1  
  • #19 18257770
    czarny8322
    Level 11  
    TvWidget --> voltage variation according to my data it can examine round the clock in normal operation as well as in "deep sleep"
  • #20 18257844
    TvWidget
    Level 38  
    If I have understood this correctly, the aim is nicely to detect mains power failure and enter "Deep sleep" mode. Am I wrong ?

    The ESP32 has a VDD3P3_RTC leg used to support the RTC power supply. The voltage on this can be 2.3..3.6V.
  • #21 18257902
    czarny8322
    Level 11  
    The aim is to have a battery backup using CR2032 so that the current time information is stored. Thanks for your suggestions on the VDD_RTC. Just as a quick note, I found some tests and:

    "
    Did a few tests about this. The issue seems to be that internal CPU regulator can also take power from VDD_RTC pin, meaning that if all the power rails except VDD_RTC are powered off, CPU can still keep running; this may cause issues if the CPU tries to read instructions or data from Flash, which will be powered down. This will soon cause the CPU to crash and enter boot loop.

    Monitoring the VDD and going into deep sleep when it disappears is possible, but we are looking for an automatic solution to the problem."

    Except that I don't need the main CPU to be running during backup.

    To summarise the whole idea of deep sleep battery backup, it is rather possible. I have just found the following material which describes this.

    https://www.youtube.com/watch?v=-QIcUTBB7Ww

    Thanks to you, a lot of input problems have been solved:) Now I just have to wire everything up and test:)
  • #22 18257907
    Anonymous
    Level 1  
  • #23 18257929
    TvWidget
    Level 38  
    I still don't know what the sequence of events is supposed to be. If the mains power fails when the ESP32 is not in "Deep sleep" mode then the circuit will stop working.
  • #24 18257930
    Anonymous
    Level 1  
  • #25 18257979
    czarny8322
    Level 11  
    TvWidget --> I would like it to work in such a way that when the normal power supply is disconnected from the ESP32, the chip will go from normal mode, into deep sleep mode. The mode change itself will be done already on the battery. It remains for me to test the stability of switching into this mode on the battery itself. Whether it will work I know, because I have tested it. The question is how, whether stable and for how long:) .
  • #26 18258332
    TvWidget
    Level 38  
    czarny8322 wrote:
    The mode change itself will already take place on battery
    .
    When the mains supply is disconnected, the circuit will not go into Deep sleep but will perform a reset. The internal resistance of the CR2032 battery is too high. It will not sustain ESP32 operation in normal mode.
  • #27 18258369
    jarek_lnx
    Level 43  
    czarny8322 wrote:
    What about power - the PAM amplifier that is in the project is 2x3W - but I only need 1x1W - I don't have room for large speakers. So maybe you know some other circuit/module that I could use?
    Power depends on the supply voltage, if you supply from 5V it will be up to 3W as from 3.3V it will be 1.3W. You can reduce the power by limiting the input level of the amplifier.

    And as for the power monitoring transition, do you need to measure with ADC? not a simple GPIO connected to an external 3.3V or other power line via a suitable divider will suffice? I used to trigger an interrupt at power loss, and as I detected a voltage drop before the inverter feeding the uC, I had a moment to react before the voltage feeding the uC dropped, but I didn't do this with the ESP.
  • #28 18258498
    Anonymous
    Level 1  
  • #29 18482563
    czarny8322
    Level 11  
    Thanks for all the tips. In the end I opted for simplicity and an external RTC - DS3231MZ+. However, this is not the end of the problems:) .

    The ordered PCBs arrived, I soldered the components and after the first flashing on the uart I was getting a message:

    ets Jun 8 2016 00:22:57
    rst:0x1 (POWERON_RESET),boot:0x3 (DOWNLOAD_BOOT(UART0/UART1/SDIO_REI_REO_V2))

    It turned out that pin 25th - IO0 - should have a high state during normal operation so the pull-up resistor in the schematic from page 1 is missing. After soldering the resistor - the test program started.

    Problem 2 -> I2c - I switched from Eagle to EasyEd. My project uses the model for ESP32-WROOM-32D in which the pins are labelled like this:

    pin 20 - marked as SCL
    pin 21 - marked as SDA

    In the documentation it is as follows:

    pin 20 - CLK
    pin 21 - SD0

    https://www.espressif.com/sites/default/files...32-wroom-32d_esp32-wroom-32u_datasheet_en.pdf

    On a development board e.g. ESP32 devkit and similar:
    pin 21 - SDA
    pin 22 - SCL

    https://rntlab.com/question/what-pins-are-the-i2c-pins-on-the-esp32/

    I have a bare ESP32-WROOM-32D chip.
    Can someone direct me under which pins I should connect my peripherals: DS3231MZ+, mcp23017 ?
  • Helpful post
    #30 18482607
    Anonymous
    Level 1  

Topic summary

✨ The discussion revolves around building a radio using an ESP32 microcontroller with battery backup and controlling a PAM8403 amplifier via a digital potentiometer (X9C103). Key concerns include the feasibility of the battery backup circuit, voltage compatibility between the ESP32 (3.3V) and the X9C103 (5V), and potential errors in the schematic. Participants highlight the need for logic level conversion, the limitations of using a CR2032 battery for powering the ESP32, and the importance of deep sleep mode for power management. Suggestions include using an external RTC (DS3231MZ+) for timekeeping and exploring alternative power solutions like 18650 batteries. The conversation also touches on issues with I2C connections and resistor specifications in the circuit design.
Generated by the language model.

FAQ

TL;DR: ESP32 peaks at 300 mA during Wi-Fi [Espressif, 2019]; "3.3 V CMOS drives 5 V TTL fine" [Elektroda, jarek_lnx, post #18248618] Use deep-sleep + CR2032 only for RTC, route GPIO21/22 for I²C, and add 10 kΩ pull-ups and 470 kΩ cathode resistors.

Why it matters: following these limits avoids resets, burnt resistors and dead modules.

Quick Facts

• ESP32 supply range: 2.3–3.6 V; Wi-Fi burst current ≈300 mA [Espressif, 2019] • X9C103 logic-HIGH ≥2.0 V (TTL); VCC 5 V allowed [Intersil, 2004] • CR2032 internal resistance 15–30 Ω; safe pulse ≤30 mA [Energizer, 2017] • PAM8403 output: 3 W/chan @5 V, ~1.3 W @3.3 V [PAM, 2018] • GPIO12 must be LOW at boot or ESP32 stalls [Espressif, 2019]

Will a CR2032 keep my ESP32 running during power loss?

No. The cell’s 15–30 Ω resistance drops the voltage below 2.5 V at ≈100 mA, forcing a reset; it can only power RTC/ULP in deep-sleep where current is <10 µA [Energizer, 2017][Elektroda, jarek_lnx, post #18250398]

Can I drive a 5 V X9C103 digital potentiometer directly from 3.3 V ESP32 pins?

Yes. The X9C103’s TTL inputs treat ≥2 V as HIGH, so 3.3 V GPIO meets the spec. The pot never sources current back into the ESP32, so no damage occurs [Intersil, 2004][Elektroda, jarek_lnx, post #18248618]

Do I need logic-level converters between ESP32 and X9C103?

Not for control lines; 3.3 V is sufficient. Add a 10 kΩ pull-up on IO0 so the ESP32 boots, and keep X9C103’s INC/U/D lines below 100 kHz to avoid EMI [Espressif, 2019][Elektroda, czarny8322, post #18482563]

Which pins handle I²C on a bare ESP32-WROOM-32D?

Default: GPIO21 (leg 33) = SDA and GPIO22 (leg 36) = SCL. Any free GPIO can be remapped in software, but these pins have internal pull-ups on many modules [Elektroda, khoam, post #18482607]

How can I detect mains loss and enter deep-sleep?

  1. Feed the 3.3 V rail (before the regulator) to an ADC-capable GPIO via 100 kΩ/47 kΩ divider.
  2. In normal code read Vbat; if <3.0 V, call esp_deep_sleep().
  3. Optionally let the ULP coprocessor read the same pin every 100 ms and wake the core when power returns. [Espressif docs, 2023].

What happens if GPIO12 is HIGH during reset?

Bootloader sees the wrong strapping level, enters invalid flash mode, and the ESP32 hangs until power-cycled [Espressif, 2019][Elektroda, khoam, post #18248919]

Are there boot-time glitches on other pins?

GPIO14 and GPIO15 emit short PWM pulses during boot; keep them away from relays or audio paths or add RC filters to avoid clicks [Elektroda, khoam, post #18248919]

How do I cut PAM8403 output to ~1 W for a small speaker?

Power the amp from the 3.3 V rail and cap input signal at 0.5 Vpp using the X9C103 plus a 10 µF coupling capacitor; output power falls to ≈1.3 W @10 % THD [PAM, 2018][Elektroda, jarek_lnx, post #18258369]

Does deep-sleep preserve my variables?

Only the 8 kB RTC fast memory survives; main SRAM clears. Save settings to RTC RAM or Flash (SPIFFS) before sleeping [Elektroda, khoam, post #18257930][Espressif, 2023].

Edge case: what if the X9C103 wiper shorts to VCC?

ESP32 GPIOs are 5 V-intolerant; a short could force 5 V into the pin and destroy it. Add a 1 kΩ series resistor on each control line for fail-safe isolation [Espressif, 2019].

Quick 3-step: use ULP ADC to wake when power returns

  1. In ESP-IDF, configure ULP to sample ADC1 channel 6 (GPIO34).
  2. Program a compare threshold of 2.8 V.
  3. On threshold exceed, issue ulp_set_wakeup_period() and ulp_run(); the core restarts automatically [Espressif docs, 2023].

Is LM386 a viable 1 W alternative to PAM8403?

Yes. With 5 V supply and 8 Ω load, LM386 gives ≈0.7 W; bridge-mode boards reach 1 W, though with higher THD than class-D PAM8403 [Texas Instruments, 2022][Elektroda, khoam, post #18257755]

How much margin does a 470 kΩ resistor need at 170 V?

Dissipation is (V²/R)=0.06 W. Use 0.25 W metal-film parts for 4× headroom and 350 VDC rating to avoid surface arcing [Vishay, 2021].
Generated by the language model.
ADVERTISEMENT