4

I'm building an IR to wifi bridge using an esp8266. Basically I'm building an IR receiver connected to an esp8266 inside an IR remote control, to forward received IR Remote keypresses over wifi to a server. I'm using a Wemos D1 Mini.

I already have the IR decoding and network forwarding part working, but it is always on, which uses a lot of battery, especially considering that 99% of the time no buttons are being pressed.

I want it to go into deep sleep when a button hasn't been pressed for a certain time.

If I connect the IR receiver to the RST pin, that can wake the esp up from deep sleep, but the problem with that is that it will keep resetting the esp over and over as the IR keeps coming in, which will make the esp unable to actually decode the IR commands because it is continually being reset.

I need it to wake the esp up from deep sleep via RST, but then to ignore further RST activations until I programmatically send it into deep sleep again.

What I really need is a proper gpio interrupt so I can ignore further resets until I go to deep sleep, but AFAIK esp8266 doesn't support gpio interrupt wake from deep sleep.

I need some kind of resettable one-shot trigger to only issue one reset until you tell it that you're going to sleep again.

I'm not sure how I'd be able to implement this? Anyone have any ideas? I would rather not have to use another external microcontroller just to reset the esp8266, also space is tight inside the remote control so I'd rather not have to use a lot of external parts.

localhost
  • 1,253
  • 4
  • 18
  • 29

4 Answers4

10

This is a circuit that I use to allow for one shot interrupt to wake up from deep sleep on ESP8266. It operates by allowing interrupt to reset only after the deep sleep timer activated (D0 is pulled low). Put a short timeout on your deep sleep function to enable interrupt right away.

Wake up interrupt control circuit

After some testing, I find that the circuit above does not save as much power as I thought because it only prevents the chip from start up but internal part of ESP is active and draw around 15ma waiting for reset. This is a lot more than 60ua in deep sleep!

If you have a signal that stay on for a few seconds after activation (like a PIR motion sensor) then the circuit below may work. It uses a capacitor to allow only edge trigger then running code can check input signal on GPIO4. However, overall power usage is still not good because the ESP8266 max sleep time is about 1 hour. This means the ESP8266 still wakes up and uses 15ma for a few seconds before going back to sleep. At 5 minutes deep sleep cycle, a 1500mah would be good for around 5 days.

Deep Sleep edge trigger

Tomsim
  • 369
  • 3
  • 7
  • Thanks! I'll try it out sometime. – localhost Aug 20 '17 at 10:55
  • @user7151084 If the interrupt signal is received a second time, it will not reset the ESP since the ESP is already awake and processing code. The interrupt signal will reset the ESP only if it's in deep sleep. Is that right? – rams Oct 12 '17 at 17:06
  • @rams I never tried it. I tried for a long time to get an external microcontroller (digispark) working to do the job, but had a lot of trouble. Hard to debug with no debugging tools. Then I bought a new TV and now I don't have a need for the project at all anymore. I wish I knew this circuit before mucking around with the digispark which I never got to work. Please post a comment on whether it works if you do try it out... – localhost Oct 13 '17 at 03:57
  • https://electronics.stackexchange.com/questions/258666/missed-interrupt-problem-with-attiny85 – localhost Oct 13 '17 at 04:03
  • 1
    @rams while ESP is running, D0 (GPIO16) is high so interrupt signal can't turn on transistor so no reset is possible. When in deep sleep, D0 remains high until it's time to wake then it's pulled low. Now the circuit is armed and any high interrupt signal will turn on the transistor, connecting RST to D0. This will reset / wake-up the ESP. As soon as it start running, it will set D0 to high again which will prevent further interrupt. – Tomsim Oct 19 '17 at 01:52
  • @user7151084 can you share the transistor details? I tried using NTE24 but doesnt seem to work. – rams Oct 22 '17 at 22:58
  • 1
    @rams I use TIS97. I've also used C2206 with no problem. – Tomsim Nov 22 '17 at 05:39
  • @Tomsim Thanks for the info and updating the circuit. I am curious why you say that your first solution does not save current. Of the ESP goes into Deep Sleep doesn't it draw the 60microA as expected? The reason for one shot is to get it out of deep sleep via an interrupt but without endless interrupt triggers. What am I missing? – rams Nov 22 '17 at 19:09
  • 1
    @rams Normally, D0 is connected to reset pin directly and long deep sleep is used. At wake up, D0 goes low to reset and restart cpu. The 1st circuit depends on having a short deep sleep and uses transistor block D0 low signal, waiting for a trigger to enable this low level into reset pin. I'm currently testing the 2nd circuit in a project [link](https://github.com/Tommystus/PIR-Monitor). I'm also finding that my solution is a variation of this [link](http://www.esp8266.com/viewtopic.php?p=41638) – Tomsim Nov 23 '17 at 07:40
  • Can we skip a couple of interupts? – Sarath Jun 03 '21 at 10:52
2

Did you see Espressif doc about sleep ESP8266 modes? It is available here: http://www.espressif.com/sites/default/files/9b-esp8266-low_power_solutions_en_0.pdf

It says:

In Deep-sleep mode, the chip can be woken up and initialized by a low-level pulse generated on the EXT_RSTB pin via an external IO.

So, I'm not sure it is possible to avoid reset (although, maybe some hacky way exists?), but what about another sleep mode? Like light-sleep.

Falko
  • 17,076
  • 13
  • 60
  • 105
  • Thanks, I knew that already, it's just that if I connect the IR directly to that pin it will wake up but I believe it will continuously reset the ESP, so I will need something to stop that from happening. Light sleep still uses about 15mA which is far too much for a remote control run from two AAA batteries. I don't want to have to change batteries every couple of days. – localhost Sep 16 '16 at 00:14
  • Oops, just correcting myself: light sleep uses up to 1.8mA. Still more than I'd like to use continuously for my project but I'll probably end up switching between light sleep and deep sleep. – localhost Sep 19 '16 at 04:46
1

This post on electronics stack describes how to do a one-shot button with a couple extra parts. However space-wise they add up to be larger than using another micro, so the OP decided to go with an MCU. The micro will use the fewest additional parts and claim the lowest amount of space.

Community
  • 1
  • 1
leetibbett
  • 843
  • 4
  • 16
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/13671974) – Gynteniuxas Sep 14 '16 at 12:36
  • Thanks for reviewing. – leetibbett Sep 14 '16 at 12:41
  • I'm glad you answered. Could you improve your answer? – Gynteniuxas Sep 14 '16 at 12:43
  • I've also decided to go with another MCU (an Attiny85 - Digispark) because I had it lying around, it will take the same space and should be more flexible if I choose to add more features later. Now I just need to learn about interrupts and sleep mode on the Attiny85!! – localhost Sep 20 '16 at 00:56
0

I have a related follow up question: I tried to make this work using a Wemos D1 mini Board using the above circuit of @Tomsim . Unfortunately it seems my ESP does get into an undefined state rather than beeing reset successfully. I recorded the voltage at the RST pin and it all seems good. If I reset the ESP normally it comes back to life as expected.

Image single shot RST pin ESP8266

For those wondering why I think the ESP is in an undefinded state: continuously lit on board LED and garbled serial console output.

Image garbled serial console output

jsschmid
  • 1
  • 1
  • The ESP uses a weird baud rate on reset, then later switches to the "normal" speed you have chosen in your sketch. Check out this https://stackoverflow.com/a/41011637/1340782 but you should be able to find more info with a quick google. So I don't think it's actually an undefined state but the expected behavior on reset of an ESP8266. – localhost Mar 22 '23 at 05:54
  • I'll give this a try and set the monitor to 74880 baud or 115k, respectively. Yet I think it is not responsive in that state it is in. If so, it should switch back to the baud rate defined in the sketch, which it is not until I reset it manually. – jsschmid Mar 23 '23 at 16:26
  • Yes, I agree that it is probably a different problem if it isn't changing to the new baud rate automatically. – localhost Mar 29 '23 at 04:40
  • But still a handy tip to avoid those problems, thanks. From now on I'll set my sketches boud rates to 74880 by default. – jsschmid Mar 30 '23 at 16:23
  • I think there's debugging info in the output at the weird baud rate on reset, I've seen "decoders" for the esp8266 startup messages somewhere before. Maybe it could include some info that might help you work out why the sketch isn't launching properly. – localhost Mar 30 '23 at 22:24