Page 1 of 2

pyb.standby() and ExtInt Line identification

Posted: Mon Sep 28, 2015 1:18 pm
by CarlClement
Hi,

New to the forum and new to micropython but I have been playing and getting the LoNet GSM/GPS module working with my pyBoard.

As part of this I have hooked up a PIR sensor to get the board to send a REST call to a server via the LoNet board. All works okay but I want to try reducing the power consumption. All seems good with using external interrupts and getting the board to do as expected, so all is going well.

I now want to add a second sensor on a second external interrupt, and that is where my skills are failing me. How do I get the value of the external interrupt line that was triggered and woke up the board after a py.standby() or py.stop()?

Ideally, I would like to use pyb.standby() but will settle for pyb.stop() if that gives me the information that will let me identify the external interrupt that was triggered. I can see the line value in the callback from pyb.stop() but can't work out how to make it available else where in my program (it's probably a lack of understanding on the use of global on python variables, so sorry for my very basic question).

Many thanks

Carl

Re: pyb.standby() and ExtInt Line identification

Posted: Tue Sep 29, 2015 3:39 am
by dhylands
When you register an interrupt callback with the ExtInt module, it gets passed a line. That is what you use to tell you which line caused the interrupt.

The lines correspond to the pin number. So CPU pin B3 will use line 3 (modulo me being off by 1 because I'm saying this off the top of my head without actually testing it first).

Re: pyb.standby() and ExtInt Line identification

Posted: Tue Sep 29, 2015 5:55 pm
by JimTal001
I don't believe interrupts work in standby() mode.

Re: pyb.standby() and ExtInt Line identification

Posted: Wed Sep 30, 2015 12:11 pm
by pythoncoder
I don't believe interrupts work in standby() mode.
From the docs for pyb.standby() http://docs.micropython.org/en/latest/library/pyb.html:
To wake from this sleep state requires an external interrupt or a real-time-clock event. Upon waking the system undergoes a hard reset.

Re: pyb.standby() and ExtInt Line identification

Posted: Fri Oct 02, 2015 9:48 pm
by JimTal001
When suspend() mode is woke by an external interrupt resulting in a hard reset, how can one identify the source of the interrupt?

Perhaps in the boot.py?

Re: pyb.standby() and ExtInt Line identification

Posted: Fri Oct 02, 2015 10:12 pm
by dhylands
The reference manual (RM0090) Table 23 (Section 5.3 - Low Power Modes on page 126) seems to indicate that EXTI can only wake the processor up when its in stop mode, and not when its in standby mode.

Re: pyb.standby() and ExtInt Line identification

Posted: Sat Oct 03, 2015 7:46 am
by pythoncoder
@dhylands That seems unambiguous. In which case the Pyboard docs are wrong: http://docs.micropython.org/en/latest/l ... -functions states
pyb.standby()

Put the pyboard into a “deep sleep” state.

This reduces power consumption to less than 50 uA. To wake from this sleep state requires an external interrupt or a real-time-clock event. Upon waking the system undergoes a hard reset.

Re: pyb.standby() and ExtInt Line identification

Posted: Tue Oct 06, 2015 12:11 pm
by pythoncoder
@JimTal001 Further study indicates that it's possible to wake the Pyboard from standby() with an external event by using the Tamper input. This is on pin X18. I'm hacking some code together to enable access to this. It works but needs tidying up and documenting: I expect to update my micropower repo on Github in the next few days.

It's perhaps stating the obvious, but response to an external event isn't exactly quick. The Pyboard goes through its boot sequence on recovery from standby. I haven't yet measured it, but on the basis of previous measurements and visual impressions it's on the order of 0.5S.

Re: pyb.standby() and ExtInt Line identification

Posted: Tue Oct 06, 2015 2:03 pm
by JimTal001
This is good news regarding pin X18. Is there a way to determine whether the interrupt is from X18 or RTC?

Re: pyb.standby() and ExtInt Line identification

Posted: Wed Oct 07, 2015 4:30 am
by pythoncoder
Yes. I have a test program which distinguishes between the three reasons for wakeup, namely boot, RTC timeout and tamper. I'll post here when it's ready.