1
\$\begingroup\$

I'm trying to use a DS3231 RTC to wake my ESP8266 at a specific hour, minute and second. My circuit is a very low power design.

I believe I need to reset my microcontroller (by momentarily pulling the RST pin low) when the RTC alarm signal goes from high to low (the SQW pin on the DS3231). However, when the DS3231 alarm is triggered, the signal stays low, so connecting the RTC SQW pin directly to the MCU RST pin won't work (because holding the RST pin low prevents the MCU from booting).

enter image description here

Desmos graph

Unfortunately, deep sleep doesn't support values greater than about 3.5 hours. I tried sleeping for an hour at a time until the desired time is reached, but found that it's not very accurate (often dozens seconds of drift on each wake, adding up to many minutes of drift after several hours).

\$\endgroup\$
9
  • \$\begingroup\$ Could control the MCU power rather than using deep sleep... Though the RTC SQW pin goes high as soon as it's initialized, after which the MCU sets the alarm. When the alarm triggers, the RTC SQW pin goes low. So, I'm not quite sure how to power off the MCU and keep it off while the RTC SQW is high (then power on when it goes low). \$\endgroup\$ Commented Dec 1, 2022 at 19:35
  • \$\begingroup\$ Can you use deepsleep wakeup triggered by the sqw pin going low (pullup attached) and when the esp wakes up reset / reinitiate the alarm? \$\endgroup\$
    – RemyHx
    Commented Dec 1, 2022 at 19:50
  • \$\begingroup\$ NB: maybe not possible on the 8266, with the esp32 it is possible \$\endgroup\$
    – RemyHx
    Commented Dec 1, 2022 at 19:52
  • 1
    \$\begingroup\$ Read here: randomnerdtutorials.com/esp32-external-wake-up-deep-sleep and especially look at External Wake Up (ext0) (also another type available). I doubt if this option is available on the 8266, but maybe you can use the esp32 \$\endgroup\$
    – RemyHx
    Commented Dec 2, 2022 at 9:33
  • 1
    \$\begingroup\$ So to make it more clear: you connect the sqw pin to a gpio pin on the esp32, not the rst or enable pin. The rtc chip wakes up the mpu by activating / switching the gpio. \$\endgroup\$
    – RemyHx
    Commented Dec 2, 2022 at 9:34

2 Answers 2

1
\$\begingroup\$

You can probably get-away with a cobbled-together monostable like this: -

schematic

simulate this circuit – Schematic created using CircuitLab

When the input drops low, the buffer output goes low but, then C1 is recharged via R1 (this sets the length of the pulse) and, after a short period of time, the buffer output goes high again. If the input returns high some time later, the capacitor is discharged fairly quickly by diode D1. All ready for the next event on the input.

R2 prevents excessive current flow into the buffer input when the input signal goes high.

Simulation: -

enter image description here

The top red waveform is the digital representation of the buffer output hence it is small in amplitude compared to the blue input that is regarded by micro-cap as an analogue input (because it connects to the capacitor).

\$\endgroup\$
4
  • \$\begingroup\$ It worked! Thank you. I added an answer with the eventual solution (bigger cap, and PNP for buffer): electronics.stackexchange.com/a/644782/288848 \$\endgroup\$ Commented Dec 2, 2022 at 16:33
  • \$\begingroup\$ OK that's good but who's answer are you going to accept; yours or mine? @NickBolton \$\endgroup\$
    – Andy aka
    Commented Dec 2, 2022 at 16:38
  • 1
    \$\begingroup\$ Yours; without it, I wouldn't have reached my solution :) \$\endgroup\$ Commented Dec 2, 2022 at 16:47
  • 1
    \$\begingroup\$ I forgot to say, I thought your circuit was very elegant. Thanks again. \$\endgroup\$ Commented Dec 3, 2022 at 0:27
1
\$\begingroup\$

There's two approaches; deep sleep wake and light sleep wake.

Deep sleep wake ESP8266 with DS3231 (monostable required)

Huge thanks Andy aka's monostable answer. This led to the eventual solution.

My solution is almost the same as Andy aka's monostable, except that I:

  • Used a PNP transistor for the output buffer (the ESP8266 module has an internal pull-up on RST).
  • Replaced the 10nF cap with a polarized 10uF cap, as the smaller cap discharged too quickly and so didn't pull the MCU RST pin low enough for long enough.

I also posted the MCU C++ code on Arduino SE.

schematic

simulate this circuit – Schematic created using CircuitLab

Simulation:

Simulation

Reality:

Scope photo

  • CH1: RTC_SQW
  • CH2: MCU_RST

Edit: 1uF cap also seems to do the job.

Scope photo

  • CH1: RTC_SQW
  • CH2: MCU_RST

Light sleep wake ESP8266 with DS3231 (lower part count)

As an alternative, for a lower part-count design: if very low power is not a requirement and light sleep is acceptable, you can wake the ESP8266 from light sleep using a GPIO pin where the input signal (unlike the RST pin), doesn't need to pulse.

esp_sleep_enable_gpio_wakeup()
esp_sleep_start()

Note: These functions don't appear to be available in the ESP class for Arduino.

There is a SO answer that describes using gpio_pin_wakeup_enable as an alternative (but that didn't actually seem to work for me).

This is similar to the esp_sleep_enable_ext0_wakeup function for ESP32, which unfortunately is not available for ESP8266. There doesn't seem to be a way to wake the ESP8266 from deep sleep with GPIO, and according to the docs: only a pulse on the RST pin can wake the ESP8266 from deep sleep.

\$\endgroup\$
11
  • 1
    \$\begingroup\$ Why didn't you use an NPN transistor? The PNP would work as you have shown but it's more conventional to use the emitter connected to the RST pin. \$\endgroup\$
    – Andy aka
    Commented Dec 2, 2022 at 16:40
  • 1
    \$\begingroup\$ OK, yes, the NPN wouldn't work unless the pulse was inverted!! \$\endgroup\$
    – Andy aka
    Commented Dec 2, 2022 at 16:44
  • 1
    \$\begingroup\$ Very odd. It seems to me that it should work. \$\endgroup\$
    – Andy aka
    Commented Dec 2, 2022 at 16:48
  • 1
    \$\begingroup\$ Sounds like a daft artefact of the simulation. If you put 10 pF across RST to positive I bet it goes away. \$\endgroup\$
    – Andy aka
    Commented Dec 2, 2022 at 19:54
  • 1
    \$\begingroup\$ Nice. You were right. Must be a SPICE bug/quirk. I thought I'd see what the lowest cap value is to eliminate the 20 kV spike... It turns out a 0.00000000000001pF cap. Fun. If you add a couple extra zeros in, you start to see the spike grow. \$\endgroup\$ Commented Dec 3, 2022 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.