logo elektroda
logo elektroda
X
logo elektroda

ESP32, battery back-up and digital potentiometer amplifier control

czarny8322 5196 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
  • #31 18486354
    czarny8322
    Level 11  
    Posts: 81
    Rate: 14
    Thank you khoam;) .
    You have helped me a lot:) Another problem eliminated:

    ESP32 is flashing and I can see the peripherals over I2C.

    Another problem appeared on the horizon. In addition to the radio, the ESP is supposed to control the NIXIE tubes.
    After connecting the power supply, the 470K resistors - R2, R6, R9, R12 that control the cathodes - were literally fried. Currently a voltage of 170V is deposited on them.

    This is a well known and duplicated schematic on mmbta42/92 transistors. Can you perhaps see the cause of the burned resistors?
    ESP32, battery back-up and digital potentiometer amplifier control
    .
  • ADVERTISEMENT
  • Helpful post
    #32 18486585
    TvWidget
    Level 38  
    Posts: 4391
    Help: 471
    Rate: 691
    czarny8322 wrote:
    After connecting the power supply, the 470K resistors - R2, R6, R9, R12 controlling the cathodes - were literally fried. Currently a voltage of 170V is deposited on them.
    .
    170²/470000=61mW
    My bet is that these are not 470k resistors.
  • ADVERTISEMENT
  • #33 18486775
    Anonymous
    Level 1  
  • #34 18490388
    czarny8322
    Level 11  
    Posts: 81
    Rate: 14
    You were right - it couldn't be 470K - I must have soldered 470 Ohms in a hurry....
    Yes, that 170V value was already after the resistors were evaporated.

    I've eliminated most of the problems for now, unfortunately the PCB is up for rework, but at least it's going in the right direction.

    Many thanks for all the advice.
  • 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