Sleep Mode - Wakeup with external interrupt

Hello together,
thank you for the great work on OpenMV.

I’m using openMV camera M7 in a battery powered setup outdoors. To record only when something is happening my aim is to always have the openmv system to low-power mode, except sensor signals a HIGH on e.g. pin P0.

I read the documentation about low power states. I require to resume the openmv fast, ~0.3s . Therefore pyb.standby() is not helpful, as it triggers a full system reset on wakeup.
pyb.stop() seems the way to go. Resume execution directly.

I try to build an example:

import sensor, image, time, machine, pyb
from pyb import LED
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

clock = time.clock()
led = LED(1) # red led

def main(x):
    global extint, led
    led.toggle()
    extint.enable()
    while(True):
        clock.tick()
        img = sensor.snapshot()
        print(clock.fps())
        pyb.stop()

######## Configure external wakeup pin for sleep ######
extint = pyb.ExtInt("P0", pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, main)
#######################################################

main(0)

After script start we directly go into sleep state. openmv disconnects from IDE. A 3.3V HIGH on P0 does toggle the led for the first external interrupt. System seems to come up partially. IDE can not connect again, OpenMV COM port does not show up again.

Documentation of pyb.stop() and pyb.ExtInt are conflicting. pyb.stop() documentation tells that “Upon waking execution continues where it left off.” whereas triggering a pyb.ExtInt() event does execute a callback function. Even assuming that i would always call main with the callback for pyb.ExtInt, callstack would increase with every triggering of callback. Bad for long a long run…


  • What is the difference betwen pyb.stop() and machine.sleep()?
  • How to resume execution after an external interrupt at the code line of pyb.stop()?

I’m currently using fw build from commit a07fb2f600df48929dbbb4b9edd42a33fd14799b.

Thank you in advance.


Best wishes!

Hi, machine and pyb are basically the same thing. There’s just some re-factoring going on with MicroPython for those two modules.

Anyway, you shouldn’t put code… in your call back. Instead, just have a very simple method that immediately exits.

What will happen is that after standby the camera will wake up again and continue to execute code. Note that you need to completely re-init the camera after this happens.

import sensor, image, time, machine, pyb
from pyb import LED

def whatever(line):
    pass

led = LED(1) # red led

######## Configure external wakeup pin for sleep ######
extint = pyb.ExtInt("P0", pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, whatever)
#######################################################

while(True):
        sensor.reset()
        sensor.set_pixformat(sensor.RGB565)
        sensor.set_framesize(sensor.QVGA)
        sensor.skip_frames(time = 1000) # You may write down previous settings related to auto-gain and white balance and re-apply them to skip this on wakeup.
        img = sensor.snapshot()
        led.toggle()
        # Do stuff
        pyb.stop()

Just tested this and it works great. The camera goes down to 0mA current consumption and then back up to 150 mA briefly and then back down to 0mA.

Hi Kwabena,
thank you. This works.
I measured the current. After entering sleep state current drops to 24 mA @5.0V falling gradually with ~0.1 mA / sec to ~ 14.7 mA. Is this a known behaviour?

Best wishes!

Hi, you need to also shutdown the camera. Please execute the sleep method for the camera sensor.

That said, my USB current meter reports 0ma on the M7 when I do this.

I can confirm this.

Best wishes!