Skip to content

Instantly share code, notes, and snippets.

@KineticPrecision
Last active October 18, 2023 15:17
Show Gist options
  • Save KineticPrecision/5ba9bbf7cc076f70ba2776146510acc8 to your computer and use it in GitHub Desktop.
Save KineticPrecision/5ba9bbf7cc076f70ba2776146510acc8 to your computer and use it in GitHub Desktop.
Real Deep Sleep via Circuit Python on the ESP32-S3
########################################
# Author: spencer_webb_nh
# Date: 18-OCT-2023
#
# DeeperSleeper is the function that gets the ESP32-S3 processor into deep sleep
# whence the current consumption is at an absolute minimum. After a
# the specified delay, in seconds, the system reboots.
#
# This knowledge was hard-earned.
#
# Measured results indicate about 18 uA deep sleep current on an
# Adafruit ESP32-S3 Rev TFT Feather board.
#
# Dependencies:
#
# import time
# import board
# import alarm
# import digitalio
# from digitalio import DigitalInOut, Direction, Pull
#
# The function is called simply:
#
# DeeperSleeper(DeeperSleeper_interval)
#
# No code is executed after the above line.
# The system reboots after DeeperSleeper_interval seconds.
#
# Also, in the interest of minimum battery current usage when the Rev TFT is present,
# but not used in the periodic execution,
# the following line should be place right after the imports:
#
# board.DISPLAY.brightness = 0
#
def DeeperSleeper(SleepTime):
print("DeeperSleeper activated. TFT, I2C, NEO powering down normally.")
# Turn off power to the TFT, I2C bus.
TFTpwr = digitalio.DigitalInOut(board.TFT_I2C_POWER)
TFTpwr.direction = digitalio.Direction.OUTPUT
TFTpwr.value = 0
# Turn off power to the NeoPixel.
NEOpwr = digitalio.DigitalInOut(board.NEOPIXEL_POWER)
NEOpwr.direction = digitalio.Direction.OUTPUT
NEOpwr.value = 0
print("")
# Create a an alarm that will trigger SleepTime seconds from now.
time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + SleepTime)
# Exit the program, and then deep sleep until the alarm wakes us.
alarm.exit_and_deep_sleep_until_alarms(time_alarm)
# Does not return, so we never get here.
#
# Test code for this function:
#
# print ("Going into deep sleep in 5 seconds for 15 seconds...")
# time.sleep(5)
# DeeperSleeper(15)
#
# buh-bye
############################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment