Help with using Nicla Vision and low power mode

Hi there,

I’m having some issues with my Nicla Vision and the OpenMV firmware. For context, I have made a transfer learning model on edge impulse following a tutorial for detecting the pointer on a gauge and classifying as a low, normal or high reading. All of that works well, but I have been trying for the past couple of days to set up a low power mode, ideally able to go low power for up to (and possibly over) an hour so it only takes a reading once an hour. For now, I’m just trying to test that it works, so I’m taking a reading once every ten seconds instead.

I read in documentation and other forums that pyb.stop(), machine.lightsleep() and sensor.sleep() are all made for this purpose, but they have all not worked for me and I can’t quite wrap my head around why. Specifically, the first two appear to malfunction and disconnect the Nicla when called, and sensor.sleep() throws “OSError: Sleep Failed”.

My guess is that either I’m doing something wrong either in set up or code, or it’s having issues because Edge-Impulse isn’t exporting on the latest OpenMV firmware version (exports as 4.3.1, encouraged to update to 4.3.2 by IDE but that somehow removes the EI model).

Code attached below, any help with this issue would be much appreciated, thanks

# Edge Impulse - OpenMV Image Classification Example

import sensor, image, time, os, tf, uos, gc, pyb

sensor.reset()                         # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565)    # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)      # Set frame size to QVGA (320x240)
sensor.set_windowing((96,96))       # Set 240x240 window.
sensor.skip_frames(time=2000)          # Let the camera adjust.

net = None
labels = None
rtc=pyb.RTC()

def callback():
    clock.tick()

    img = sensor.snapshot()

    # default settings just do one detection... change them to search the image...
    for obj in net.classify(img, min_scale=1.0, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5):
        print("**********\nPredictions at [x=%d,y=%d,w=%d,h=%d]" % obj.rect())
        img.draw_rectangle(obj.rect())
        # This combines the labels and confidence values into a list of tuples
        predictions_list = list(zip(labels, obj.output()))

        for i in range(len(predictions_list)):
            print("%s = %f" % (predictions_list[i][0], predictions_list[i][1]))

    print(clock.fps(), "fps")

rtc.wakeup(10*1000,callback)

try:
    # Load built in model
    labels, net = tf.load_builtin_model('trained')
except Exception as e:
    raise Exception(e)


clock = time.clock()
while(True):
    sensor.sleep(True)

Hi, you need to set the RTC first, set the RTC wakeup time, then finally call the low-power entry function machine.deepsleep() or machine.sleep(). Please see the low-power examples in the IDE and try them separately first to see how it works. Note the deepsleep() function (i.e standby mode) doesn’t work quite right on the dual core H7 right now, but we’re working on fixing it. When it works it resets the whole board on wakeup. The sleep (i.e stop mode) should be working, this doesn’t reset the MCU it just wakes up again after the RTC timeout. Note both modes will disconnect the USB.
sensor.sleep() may not be implemented for that sensor and you probably don’t need it.

Had a look through the Nicla Vision examples in the IDE, I think I’m starting to get it now. So rtc.datetime() function basically sets the initial time, and without it the timer won’t work properly?

Is there a way that I can still preview what the camera sees in the frame buffer/have it output readings to terminal after it stops and wakes up?

Thanks again

No, the IDE will not auto reconnect.

Okay, and is there a way to force it to reconnect or otherwise output a number to the terminal?

That feature is not built in. There’s no way for the IDE to know you just didn’t remove the board from your PC. When your device powers off it is the same as if it was disconnected.

Now, if you want to put a GitHub feature tracker for the IDE on adding an auto reconnect I can do that in the future.

1 Like

Fair enough, I’ll see if I can do that. Thanks for your help