Created
January 16, 2023 11:23
-
-
Save manchoz/81799d048c9baf5a436b46d544e44bcd to your computer and use it in GitHub Desktop.
Nicla Vision MicroPython Deep Sleep Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Deep Sleep Mode Example | |
# This example demonstrates the low-power deep sleep mode plus sensor shutdown. | |
# Note the camera will reset after wake-up from deep sleep. To find out if the cause of reset | |
# is deep sleep, call the machine.reset_cause() function and test for machine.DEEPSLEEP_RESET | |
import pyb, machine, sensor, time, random | |
# Create and init RTC object. | |
rtc = pyb.RTC() | |
# (year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]]) | |
rtc.datetime((2023, 1, 11, 12, 13, 0, 0, 0)) | |
# Print RTC info. | |
print(rtc.datetime()) | |
sensor.reset() | |
RED_LED_PIN = 1 | |
BLUE_LED_PIN = 3 | |
sensor.reset() # Initialize the camera sensor. | |
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE | |
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others) | |
sensor.skip_frames(time = 2000) # Let new settings take affect. | |
pyb.LED(RED_LED_PIN).on() | |
sensor.skip_frames(time = 2000) # Give the user time to get ready. | |
pyb.LED(RED_LED_PIN).off() | |
pyb.LED(BLUE_LED_PIN).on() | |
print("You're on camera!") | |
img = sensor.snapshot() | |
# You may want to save an image on the internal QSPIF. YMMV. | |
# name = f"example-{time.time()}-{random.randrange(1024)}.jpg" | |
# img.save(name) | |
pyb.LED(BLUE_LED_PIN).off() | |
print("Done! Reset the camera to see the saved image.") | |
# Shutdown the sensor (pulls PWDN high). | |
sensor.shutdown(True) | |
# Enable RTC interrupts every 10 seconds. | |
# Note the camera will RESET after wakeup from Deepsleep Mode. | |
rtc.wakeup(10000) | |
# Enter Deepsleep Mode. | |
machine.deepsleep() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment