How do you properly handle external interrupts?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How do you properly handle external interrupts?

Post by pythoncoder » Fri Mar 03, 2017 7:25 am

kfricke wrote:...The first two are not that applicable for a battery powered scenario...
I'd agree about the first, but the second is debatable: the Light Sleep (0.9 mA) mode may be applicable depending on the application. Take a system running off alkaline AA cells: capacity is 2600mAH. So the run time in this mode is about 2600/(0.9*24*31) = 3.9 months. Of course this will be reduced as the device will presumably wake up and do some work from time to time ;) Another option might be to run off a 2AH rechargeable LiPoly cell.
Peter Hinch
Index to my micropython libraries.

Rf3w8
Posts: 14
Joined: Tue Feb 21, 2017 4:51 pm

Re: How do you properly handle external interrupts?

Post by Rf3w8 » Fri Mar 03, 2017 7:48 pm

This discussion is very interesting, but I think it's a bit off topic. Should we move to another thread?
I'd love to hear more about powering options..

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: How do you properly handle external interrupts?

Post by kfricke » Fri Mar 03, 2017 9:17 pm

Rf3w8 wrote:...

Code: Select all

def call_this(change):
    print(change)

p2 = Pin(2, Pin.IN)

p2.irq(trigger=Pin.IRQ_FALLING, handler=call_this)
To be honest I have not noticed that Pin.irq(...) method before. Did you see that it seems to return a callback object? Where did you read about the argument for the handler method?
Did you also pull the Pin up (towards VCC via a resistor) to define the idle (non-pressed) state?
...

Code: Select all

while 1:
    pass
...
This is a busy loop which does not return idle time to the RTOS running on the ESP. Not giving idle time back to the RTOS will sooner or later trigger the WDT and reset the ESP.

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: How do you properly handle external interrupts?

Post by kfricke » Fri Mar 03, 2017 9:23 pm

Rf3w8 wrote:This discussion is very interesting, but I think it's a bit off topic. Should we move to another thread?
I'd love to hear more about powering options..
My story about the dash button was meant for your scenario, tbh. You do have GPIOs available, so why not use those to implement an external circuitry like that?

Rf3w8
Posts: 14
Joined: Tue Feb 21, 2017 4:51 pm

Re: How do you properly handle external interrupts?

Post by Rf3w8 » Fri Mar 03, 2017 9:34 pm

kfricke wrote:
Rf3w8 wrote:This discussion is very interesting, but I think it's a bit off topic. Should we move to another thread?
I'd love to hear more about powering options..
My story about the dash button was meant for your scenario, tbh. You do have GPIOs available, so why not use those to implement an external circuitry like that?
Yes but either way it's too slow? I guess?
By they way, the approach you were referring to is probably the same used by this guy here: https://www.youtube.com/watch?v=nbMfb0dIvYc
Last edited by Rf3w8 on Sun Mar 05, 2017 12:59 am, edited 1 time in total.

Rf3w8
Posts: 14
Joined: Tue Feb 21, 2017 4:51 pm

Re: How do you properly handle external interrupts?

Post by Rf3w8 » Sun Mar 05, 2017 12:57 am

I did some testing to see how much it takes to connect to a wifi network, comparing normal boot vs. reset from deep sleep:
  • Normal boot - DHCP Enabled: 5 seconds
  • Deepsleep - DHCP Enabled: 3 seconds
  • Normal boot - Static IP addressing: 2 seconds
  • Deepsleep - Static IP addressing: 0 seconds
Times were taken with utime.time() function. I didn't have time to experiment too much with utime module and find a way to time to the millisecond, but I have the feeling that normal boot + static ip addressing is > 2.5 seconds (or either way pretty close to 2.5).
Deep sleep with static ip addressing is instantaneous.

This, together with the approach shown in the video I put above, would allow making a pretty great remote for controlling lights.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How do you properly handle external interrupts?

Post by pythoncoder » Sun Mar 05, 2017 1:41 pm

How did you determine connectivity in these tests? It would be informative to do this by retrieving some actual content from the network. It may be that with static IP the ESP reports connectivity instantly, but the access point may need time to respond.
Peter Hinch
Index to my micropython libraries.

Rf3w8
Posts: 14
Joined: Tue Feb 21, 2017 4:51 pm

Re: How do you properly handle external interrupts?

Post by Rf3w8 » Sun Mar 05, 2017 5:02 pm

pythoncoder wrote:How did you determine connectivity in these tests? It would be informative to do this by retrieving some actual content from the network. It may be that with static IP the ESP reports connectivity instantly, but the access point may need time to respond.
This is true, I didn't test for internet connectivity, because it is not needed for what I need. You could do:

Code: Select all

import socket
info = socket.getaddrinfo("google.com", 80)
And check what it contains. You should be able to determine if you are on the internet or not.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How do you properly handle external interrupts?

Post by pythoncoder » Sun Mar 05, 2017 5:36 pm

Then you'd be timing your ISP and the local internet in addition to the wakeup time. I'd go for accessing a local resource such as the router or a server. This should return a time as near as possible to that between waking and actually having connectivity. The results would be interesting.
Peter Hinch
Index to my micropython libraries.

Post Reply