How to manually awake from deep sleep

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
kwiley
Posts: 67
Joined: Wed May 16, 2018 5:53 pm
Contact:

How to manually awake from deep sleep

Post by kwiley » Fri Jun 14, 2019 5:53 am

Say I want to run a sensor very rarely, once a day perhaps, using an ESP-01S. Upon waking from deep sleep, the sensor takes its reading, transmits the data to a web server, and quickly goes back to deep sleep. However, if I walk past the device, I want to be able to push a button that manually triggers it (wakes it up and takes a reading). In particular, I want to do this because in addition to transmitting sensor data to the server, the device also gives an immediate indication of its state with the LED, so by pressing a button you get an immediate visual sensor indication regardless of the data being sent to the server.

How would you build something like this? What would the button *do*? The battery will already be connected to VCC and GND, so it wouldn't be a matter of a conventional switch the closes and otherwise open power circuit. I'm not sure how to do this. Would the switch manually raise the IRQ alarm or something to that effect?

Thanks.

User avatar
Roberthh
Posts: 1569
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: How to manually awake from deep sleep

Post by Roberthh » Fri Jun 14, 2019 6:09 am

How about just forcing reset with a button? If that happens only rarely, the few seconds required to boot seem acceptable.

kwiley
Posts: 67
Joined: Wed May 16, 2018 5:53 pm
Contact:

Re: How to manually awake from deep sleep

Post by kwiley » Fri Jun 14, 2019 7:02 am

I did a little digging and it looks like most circuits wire the RST pin to VCC with a resistor and then provide a switch to ground. So, the idea is that the reset pin spends most of its time high, but if you explicitly pull it low with a switch the board suddenly reboots?

User avatar
Roberthh
Posts: 1569
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: How to manually awake from deep sleep

Post by Roberthh » Fri Jun 14, 2019 7:54 am

Yes. The pin also has an internal pull-up, and adding a capacitor between the reset input and GND parallel to the switch reduces bouncing. Value about 100 nF

kwiley
Posts: 67
Joined: Wed May 16, 2018 5:53 pm
Contact:

Re: How to manually awake from deep sleep

Post by kwiley » Sat Jun 15, 2019 2:20 am

So I put a simple momentary switch between RST and GND. It resets the board just fine, but curiously, it still resets with a DEEPSLEEP_RESET as the cause anyway. If I run the following code, which creates the main.py necessary for a proper boot-up and then puts the board to sleep, and if I then press the button before the sleep period ends, I still get the "woke from deep sleep" message.

Code: Select all

a = '''
import machine, time

s2 = machine.Signal(machine.Pin(2, machine.Pin.OUT), invert=True)

# check if the device woke from a deep sleep
if machine.reset_cause() == machine.DEEPSLEEP_RESET:
	for i in range(5):
		s2.on()
		time.sleep(.05)
		s2.off()
		time.sleep(.05)
	print('woke from a deep sleep')
else:
	print('ordinary reset')
'''
with open('main.py', 'w') as f:
	f.write(a)
f.close()

# configure RTC.ALARM0 to be able to wake the device
rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)

# set RTC.ALARM0 to fire after 10 seconds (waking the device)
rtc.alarm(rtc.ALARM0, 10000)

# put the device to sleep
machine.deepsleep()

Post Reply