Nicla Vision - deep sleep after accessing camera sensor

Hi,

I am working with an Arduino Nicla Vision running on Firmware Version 4.3.0, powered via the 3.7V battery connector.

I am trying to write a script that takes an image and deep-sleeps, to minimize power consumption.

When only deep-sleeping, like so:

import pyb, time

time.sleep(2)

# Configure RTC to trigger wakeup ever 2 seconds
rtc = pyb.RTC()
rtc.wakeup(2000)

pyb.standby()

The Nicla draws ~4.3 mA during deep-sleep.

If I turn on the camera sensor:

import pyb, time, sensor

time.sleep(2)

# Configure RTC to trigger wakeup ever 2 seconds
rtc = pyb.RTC()
rtc.wakeup(2000)

# Initialize sensor
sensor.reset()

pyb.standby()

The Nicla now draws ~20 mA during deep-sleep.

However, when I try to turn off the sensor:

import pyb, time, sensor

time.sleep(2)

# Configure RTC to trigger wakeup ever 2 seconds
rtc = pyb.RTC()
rtc.wakeup(2000)

# Initialize and shutdown sensor
sensor.reset()
sensor.shutdown(True)

pyb.standby()

The Nicla still draws ~20 mA during deep-sleep.

It seems that the sensor.shutdown(True) does not do anything.

If I try to use sleep, instead of shutdown:

import sensor
sensor.sleep(True)

I get:

OSError: Sleep Failed

Is there a way to turn of the camera sensor during sleep, so the drawn current is similar to the ‘pure’ deep-sleep?

The image sensor power-down pin is not connected, for some reason, so shutdown() doesn’t actually do anything, and the sleep() function is not implemented either, because this sensor is poorly documented and the datasheet doesn’t mention any “softsleep” registers. That said, if you say that it draws less before reset, it means that some register is turning it on, and it may be possible to go back to that state. I don’t have a USB current meter right now to test with, you could try to set this (soft-reset register) bit 7:


For example:

sensor.__write_reg(0xFE, 0x80) # or 0xF0

You’ll have to reset() the sensor again after wakeup, or this one (bit 0 PLL_EN register) set it to 0:

Thank you for your response :slight_smile:

sensor.__write_reg(0xF7, 0x00)

decreased the current from ~20mA to ~17.5, so something happened!

I have found a temporary solution that will get me 5mA sleep, however.

If i execute my code in the following order

  1. Deep sleep
  2. Turn on Camera
  3. Do work
  4. Hard reset device

What about soft-reset ? Does it lower the current ?

sensor.__write_reg(0xFE, 0x80)
#or
sensor.__write_reg(0xFE, 0xF0)

Both result in ~20mA sleep

Running this code:

import pyb, time, sensor

time.sleep(2)

# Configure RTC to trigger wakeup ever 2 seconds
rtc = pyb.RTC()
rtc.wakeup(2000)

# Initialize sensor
sensor.reset()
time.sleep_ms(200)

sensor.__write_reg(0xFE, 0xF0)
# or
# sensor.__write_reg(0xFE, 0x80)

pyb.standby()

See image:
Light blue: 0x80
Dark blue: 0XF0

It might be worth trying this too:

sensor.__write_reg(0xF7, 0x00)
sensor.__write_reg(0xFE, 0x00)

Maybe later I can get a USB tester and find a set of registers that revert it to reset current.

Sadly those do not work either :frowning:

I have found a solution. This completely shuts down the sensor:

def shutdown_sensor():
    sensor.__write_reg(240, 33)
    sensor.__write_reg(241, 69)
    sensor.__write_reg(242, 0)
    sensor.__write_reg(243, 0)
    sensor.__write_reg(246, 0)
    sensor.__write_reg(247, 16)
    sensor.__write_reg(248, 0)
    sensor.__write_reg(249, 0)
    sensor.__write_reg(250, 0)
    sensor.__write_reg(251, 120)
    sensor.__write_reg(252, 1)
    sensor.__write_reg(253, 0)
    sensor.__write_reg(254, 0)

Some of the writes might be superfluous, however

Thanks! I’ll work on the sensor driver soon.

I went through them one by one, I removed the ones that I think have no effect (their value don’t change) or invalid (for example 240/241 are read-only chip ID registers), and I ended up with these 3 registers. Please let me know if you can test them and if you get the same current.

def shutdown_sensor():
    sensor.__write_reg(0xF2, 0x0)
    sensor.__write_reg(0xF7, 0x10)
    sensor.__write_reg(0xFC, 0x01)