Library esp32

To use this library in your code:

import esp32
ESP32 related functionality.

Classes

The ESP32 power management lock.

Globals

The shortest duration supported by deep-sleep.

Deprecated. Use RESET-EXTERNAL.

Deprecated. Use RESET-PANIC.

Deprecated. Use RESET-SDIO.

Deprecated. Use RESET-SOFTWARE.

Brownout reset (software or hardware).

Reset due to a CPU lock up.

Reset after exiting deep sleep.

Reset due to an efuse error.

Reset due to external pin. (Not applicable to the ESP32).
Also see WAKEUP-EXT1.

Reset (software or hardware) due to the interrupt watchdog.

Reset by JTAG.

Reset due to an other (non interrupt or task) watchdog.

Reset due to an exception or a panic.

Reset because a power glitch was detected.

Reset due to power-on.

Reset over SDIO (secure digital input output).

Reset via esp_restart.

Reset due to the task watchdog.

Unknown reset reason.

Reset by the USB peripheral.

Size of the user accessible RTC memory.
Deprecated.

This constant isn't a wakeup cause, but is used to disable all wakeup sources with esp_sleep_disable_wakeup_source.

Wakeup caused by an external signal using RTC_IO.

Wakeup caused by external signal using RTC_CNTL.

Wakeup caused by GPIO (light sleep only).

Wakeup caused by timer.

Wakeup caused by the touchpad.

Wakeup caused by UART (light sleep only).

Wakeup caused by the ULP program.

Undefined wakeup.
In case of deep sleep, the reset was not caused by exit from deep sleep.

Functions

adjust-real-time-clock adjustment/Duration -> none
Adjusts the real-time clock with the specified adjustment.
The adjustment may not be visible immediately through calls to Time.now in case techniques like time smearing are used to prevent large jumps in time.

deep-sleep duration/Duration -> none
Enters deep sleep for the specified duration (up to 24h) and does not return. Exiting deep sleep causes the ESP32 to start over from main.
Durations shorter than DEEP-SLEEP-MIN-DURATION are increased to that duration. Use reset instead when no sleep is intended.
If you need to deep sleep for longer than 24h, you can chain multiple deep sleeps.
If the ESP32 wakes up due to the duration expiring, then reset-reason is set to RESET-DEEPSLEEP and the wakeup-cause is set to WAKEUP-TIMER.

dump-heap -> none
Sends (as a system message) a detailed report over the usage of memory at the OS level.

enable-external-wakeup pin-mask/int on-any-high/bool -> none
Sets the ESP32 to wake up from deep sleep if the GPIO pins in pin-mask matches the mode.
The pin-mask is a bit mask of the pins to monitor.
If the ESP32 wakes up due to the GPIO pins, then reset-reason is set to RESET-DEEPSLEEP and wakeup-cause is set to WAKEUP-EXT1.
If on-any-high is true, the ESP32 will wake up if any pin in the mask is high.
If on-any-high is false, then the behavior depends on the chip. An ESP32 will wake up if *all* pins in the mask are low. All other chips wake up if *any* pin in the mask is low.
The following GPIO pins can be used:
  • ESP32: 0, 2, 4, 12-15, 25-27, 32-39
  • ESP32-S2: 0-21
  • ESP32-S3: 0-21
Support for the ESP32-C3 is not yet implemented.
Examples
Wake up when GPIO pin 33 goes high:

esp32.enable-external-wakeup (1 << 33) true

Enables waking up from touchpad triggers.
The ESP32 wakes up if any configured pin has its value drop below their threshold.
Use touchpad-wakeup-status to find which pin has triggered the wakeup.
If the ESP32 wakes up due to the touchpad, then reset-reason is set to RESET-DEEPSLEEP and wakeup-cause is set to WAKEUP-TOUCHPAD.

The WiFi MAC address of the ESP32.

Sends (as a system message) a report over the usage of memory at the OS level.

pm-configure --min-frequency-mhz/int --max-frequency-mhz/int --enable-light-sleep/bool -> none
Sets the power management configuration.
See the documentation for the ESP32 power management for more details.

Returns whether the current power management has light-sleep enabled.

Returns the current power management max-frequency in MHz.

Returns the current power management min-frequency in MHz.

reset -> none
Resets the ESP32 and does not return.

One of the RESET-* enum values (such as RESET-POWER-ON) that indicates why the ESP32 was reset.

Constructs a ByteArray backed by the RTC user data.
Deprecated. Use storage.Bucket instead.
Advanced
RTC memory is volatile memory that is powered during deep sleep. RTC memory is random access and significantly faster than flash memory.
It is recommended to ensure the integrity of the stored data with a checksum.
There is only one RTC memory on the device, so all tasks or processes have access to the same RTC memory.

Sets the real-time clock to the new time.
The new time is visible immediately through calls to Time.now.

Returns the total number of microseconds this device has been in deep sleep.

Returns the total number of microseconds this device has been running (including deep sleep).

Returns the pin number that triggered the wakeup.
Returns -1 if the wakeup wasn't caused by a touchpad.

One of the WAKEUP-* enum values (such as WAKEUP-TIMER) that indicates why the ESP32 was woken up from deep sleep.

Disables the watchdog timer.

watchdog-init --ms/int -> none
Initializes the watchdog timer.
If there is an interval of ms milliseconds between calls to watchdog-reset, the ESP32 will reset.
Use watchdog-deinit to disable the watchdog timer.

Resets the watchdog timer.