Low Power with External Trigger

Hi,

I am trying to work on sleep mode and take&save snapshot only upon external trigger.
I have read several conversations about this issue on this forum but I can’t figure out what i am doing wrong…

During sleep mode I can reach ~40mA consumption.
Can you please let me know what i am missing here ?

This is my code :

import sensor,pyb, image, time, utime, machine
from pyb import UART,Pin, ExtInt, LED


red_led   = LED(1)

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_quality(80)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.set_auto_gain(1)
sensor.set_auto_whitebal(1)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.

Cam_Gain=sensor.get_gain_db()

clock = time.clock()                # Create a clock object to track the FPS.

def wakeup(line):
    pass

######### Configure external wakeup pin for sleep ######
pin = Pin("P7", Pin.IN, Pin.PULL_UP)
ext = ExtInt(pin,ExtInt.IRQ_FALLING,Pin.PULL_UP, wakeup)
########################################################

while(True):
    sensor.sleep(1)
    red_led.off()
    machine.lightsleep()
    sensor.sleep(0)
    #Do After Wakeup
    sensor.set_auto_gain(0,Cam_Gain)
    sensor.set_auto_whitebal(0)
    Cam_Gain=sensor.get_gain_db()
    # Take Snapshot
    sensor.snapshot().save("example.jpg")
    

---------------------------------------------------------------------------------

Hi, can you use pyb.stop()?

https://docs.openmv.io/library/pyb.html#power-related-functions

Actually I have tested first with pyb.stop() and then I have changed it to machine.lightsleep().
checked it now again just to be sure with same results (~40mA).
I must find the reason for this…

BTW,
I am working with OpenMV Cam H7 Plus model.

It could be the SDRAM.

@ibrahim?

I get ~10mA with the deepsleep example (machine.deepsleep()) with the latest firmware.

I didn’t want to work with machine.deepsleep() because i have read in the documentation that it will act like a restart (start again from main) so all initialization will be performed again and there will be a long delay until the snapshot will be taken (is it correct ?).

On other threads of this forum I have read that you have reached few microamps with machine.lightsleep() or pyb.stop() ,

  • Do you know why it doesn’t happen with the current firmware version ?

I appreciate your support and prompt answers,
I have read a lot of discussions and learned a lot from your answers

The lowest possible current is only achievable with the deepsleep example.

Actually I realized QSPI wasn’t disabled in low-power modes, after some fixes the board draws less than 10mA in deepsleep… As for lightsleep, it still draws at least 30mA… However, I noticed if sensor.reset() is not called at all it gets down to 10mA… so there must be some register that gets written into OV5640 that causes it to draw more power in standby mode @Kwabena.

Thanks Ibrahim,
I hope it is a firmware issue which can be solved.

In the below thread I noticed that you managed to get very low current consumption while using pyb.stop().
Maybe it is best to work with the firmware version which was used there ?

That’s not my post and it’s for the older camera not the H7+, actually the H7+ should be able to get to lower power or the same at least, since we fixed a missing pull up on the sensor power down.

So Currently it is not possible to get lower than 10mA on Sleep mode with the H7 plus ?
Do you plan to fix this issue soon ?
it is very limiting factor right now…

Yeah, you’d go to deep sleep… Keep in mind in sleep mode the SDRAM is still on. Asking the system to keep all RAM retention cost power.

If you want the camera to boot faster from deep sleep this is easily doable. The auto functions on the camera can be forced to go to the right value immediately on startup. You don’t have to wait for them to stabilize. Our firmware right now has delays and other things in it to accommodate generally booting the camera.

To be clear, the OV5640 is not designed for low power. The best way to get it to be a low power sensor it to turn it off. That said, from boot to image capture this can be done in less than a second. Is there a reason you need a faster trigger time?

I’ll see what I can do with the OV5640. There are a bunch of clock and reset controls in it. So, I think I can make it sip less power. Please create a GitHub issue: Issues · openmv/openmv · GitHub

The best we can do right now is 30mA for STOP mode and less than 10mA in STANDBY mode. I’m working on a fix to the stop mode could possibly get down to 10mA.

I want to use the device as battery operated security system which will be activated by external sensor.
so power consumption and trigger time is important.

I hope you can work on it so it will be as older firmware, it will be great.

To summarize your answers, please correct me if I am wrong :

  • In stop mode : current consumption is 30mA and we can get fast trigger time

  • In Standby mode which is actually machine.deepsleep() , current consumption is 10mA and we need to reset the sensor so trigger time will be ~1sec.

    \

  1. Is it correct ?

  2. What do I need to modify in my code to reach 10mA ? I didn’t managed to reach this consumption

I just a made a small fix to shutdown and the final numbers that I see are 10mA in sleep()/lightsleep() (STOP mode), and less than 10mA in deepsleep() (STANDBY mode) I’m not sure what the exact numbers are if you have a meter hooked up let us know.

If you can build the code, this is the fix: Sensor shutdown fixes. by iabdalkader · Pull Request #1141 · openmv/openmv · GitHub
It will be merged shortly.

I am able to run this example fine with that fix, it goes down to 10mA and on extint it goes up to ~130mA, takes a snapshot and back to 10mA (note I changed the pin).

import sensor,pyb, image, time, utime, machine
from pyb import UART,Pin, ExtInt, LED


red_led   = LED(1)

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_quality(80)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.set_auto_gain(True)
sensor.set_auto_whitebal(True)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.

Cam_Gain=sensor.get_gain_db()

clock = time.clock()                # Create a clock object to track the FPS.

def wakeup(line):
    pass

######### Configure external wakeup pin for sleep ######
pin = Pin("P5", Pin.IN, Pin.PULL_UP)
ext = ExtInt(pin,ExtInt.IRQ_FALLING,Pin.PULL_UP, wakeup)
########################################################
i = 0
while(True):
    sensor.shutdown(True)
    red_led.off()
    machine.sleep()
    sensor.shutdown(False)
    red_led.on()
    #Do After Wakeup
    sensor.set_auto_gain(False, Cam_Gain)
    sensor.set_auto_whitebal(False)
    Cam_Gain=sensor.get_gain_db()
    # Take Snapshot
    sensor.snapshot().save("example%.3d.jpg"%(i))
    i+=1

BTW I also tested the firmware used in the linked post, it’s fw 3.0.0, and I get the same 10mA with the OPENMV3/F7 in stop mode.

OK, Thanks
I don’t know how to embed this fix in firmware.
I think I will wait till it will be merged.

Than I will check the current consumption and update you.

Do you think you can reach the results of ~1mA ?
As in this post where you have wrote you reached 500uA / 1.6mA ?

The fix has been merged, and it will be available in the next release…

Again, that’s a post about an older camera without SDRAM and it’s using deepsleep not lightsleep.

I’m new to OpenMV and working to figure out how to use an H7 Plus to measure distances when initiated by an external controller (Linux machine). Sorry for the long story. I’ve tried a bunch of things to get this to work, and may have broken my camera.

At a high level, I’m having difficulty figuring out if my H7 camera is responding properly to what I thought would a simple thing - 1) boot up, 2) initiate low power mode (e.g., deep_sleep, sensor_sleep, stop_mode…), 3) wake up from low power mode from an external trigger (extint_wakeup), 4) do something (for now, take a picture - longer term it will execute a script that leverages find_lines example code, samples, averages… and transmit serial data), 5) go back to low power, and 6) wait for a signal to run again.

Details:
First step, confirm the IDE and camera were at the latest releases and run helloworld to make sure everything is works as expected.

Run stop_mode example code from the IDE. The camera takes a snapshot, turns on the camera LED red, disconnects from the IDE a few seconds later and about 10 seconds after that there’s an OS error that the disk was not ejected properly.

When I apply a signal (3.3 V) to the GPIO pin, the camera’s LED (red) turns off. When no signal (0 V) is on the pin, the LED comes back on red. It seems the external interrupt is doing something.

When I attempt to reconnect the camera to the IDE, I get an error “No OpenMV cameras found!” Either way, with or without a 3.3V signal to the pin, the camera will not reconnect to the IDE until it is reset.

I tried iabdalkader’s code from Jan '21 found above in this post (set pin to the GPIO number I’m using). With the exception of the red LED (it does not come on at all), the camera takes one picture then disconnects. When I try to reconnect, I get an IDE error “No OpenMV Cams found!” and then asks if I have one connected that was bricked. I also get the same OS error about ejecting the disk. When I reset the camera (ground RST pin), everything is back to normal.

It may be that my confusion is simply because the OpenMV IDE disconnects, the USB drive get ejected, and/or attempting to reconnect the IDE it reports the camera is busy or times out.

To bypass my IDE dilemma, I saved the code above as main.py on the camera with potentially damaging results. It was caught in an endless loop of taking a picture, disconnecting, ejecting the disk and triggering the OS error.

I inadvertently left 3.3V on the GPIO pin when erasing and reprogramming the flash memory. Helloworld now shows a completely green screen, even after erasing and reprogramming without the 3.3 V signal AND rebooting the IDE… Is the camera trash now?

According to the IDE serial monitor I’ve got, “MicroPython: v1.18-omv-r6 OpenMV: v4.3.1 HAL: v1.9.0 BOARD: OPENMV4P-STM32H743” in use. Anything else you need to know about my setup?

Any recommendations on what I’m doing wrong or is there something else going on?

Thanks for the help,
Luis