pyb.standby() and ExtInt Line identification

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
CarlClement
Posts: 1
Joined: Mon Sep 28, 2015 1:00 pm

pyb.standby() and ExtInt Line identification

Post by CarlClement » Mon Sep 28, 2015 1:18 pm

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

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: pyb.standby() and ExtInt Line identification

Post by dhylands » Tue Sep 29, 2015 3:39 am

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).

JimTal001
Posts: 176
Joined: Thu Jul 30, 2015 4:59 pm

Re: pyb.standby() and ExtInt Line identification

Post by JimTal001 » Tue Sep 29, 2015 5:55 pm

I don't believe interrupts work in standby() mode.

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

Re: pyb.standby() and ExtInt Line identification

Post by pythoncoder » Wed Sep 30, 2015 12:11 pm

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.
Peter Hinch
Index to my micropython libraries.

JimTal001
Posts: 176
Joined: Thu Jul 30, 2015 4:59 pm

Re: pyb.standby() and ExtInt Line identification

Post by JimTal001 » Fri Oct 02, 2015 9:48 pm

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?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: pyb.standby() and ExtInt Line identification

Post by dhylands » Fri Oct 02, 2015 10:12 pm

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.

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

Re: pyb.standby() and ExtInt Line identification

Post by pythoncoder » Sat Oct 03, 2015 7:46 am

@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.
Peter Hinch
Index to my micropython libraries.

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

Re: pyb.standby() and ExtInt Line identification

Post by pythoncoder » Tue Oct 06, 2015 12:11 pm

@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.
Peter Hinch
Index to my micropython libraries.

JimTal001
Posts: 176
Joined: Thu Jul 30, 2015 4:59 pm

Re: pyb.standby() and ExtInt Line identification

Post by JimTal001 » Tue Oct 06, 2015 2:03 pm

This is good news regarding pin X18. Is there a way to determine whether the interrupt is from X18 or RTC?

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

Re: pyb.standby() and ExtInt Line identification

Post by pythoncoder » Wed Oct 07, 2015 4:30 am

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.
Peter Hinch
Index to my micropython libraries.

Post Reply