-
Notifications
You must be signed in to change notification settings - Fork 345
machine
machine module contains various methods and classes related to ESP32 hardware.
Get or set the current ESP32 CPU clock in Hz
Executed without an argument returns the current CPU clock in Hz.
When setting the frequency, new_freq
argument can be entered in Hz or MHz.
Only frequencies 2MHz, 80Mhz, 160MHz, 240MHz and crystal frequency are supported.
If Power Management is enabled, the maximum frequency is set.
Reset the ESP32
Returns 2-items tuple containing numeric representation of reset and wake-up reasons
Returns 2-items tuple containing string description of reset and wake-up reasons
Returns bytearray (6 bytes) of unique ESP32 id.
Base MAC address which is factory-programmed by Espressif is used as unique_id.
Prints the detailed information about the ESP32 heap space outside the MicroPython heap.
If psRAM is used, the information about psRAM heap is also printed.
>>> machine.heap_info()
Heap outside of MicroPython heap:
#--------------------------------
Free: 237632
Allocated: 20196
Minimum free: 236212
Total blocks: 87
Largest free block: 113804
Allocated blocks: 82
Free blocks: 5
SPIRAM info:
#-----------
Free: 1048532
Allocated: 3145728
Minimum free: 1048532
Total blocks: 2
Largest free block: 1048532
Allocated blocks: 1
Free blocks: 1
>>>
Put the ESP32 into deep sleep mode.
You may want to configure some wake-up sorces using RTC module.
timeout
sets the sleep time in ms. If set to 0
, the timer is not used as wake-up source.
>>> machine.deepsleep(10000)
ESP32: DEEP SLEEP
ets Jun 8 2016 00:22:57
rst:0x5 (DEEPSLEEP_RESET),boot:0x3f (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:4852
load:0x40078000,len:0
load:0x40078000,len:14728
entry 0x40078d64
Internal FS (SPIFFS): Mounted on partition 'internalfs' [size: 1048576; Flash address: 0x1F0000]
----------------
Filesystem size: 956416 B
Used: 512 B
Free: 955904 B
----------------
FreeRTOS running on BOTH CORES, MicroPython task running on both cores.
Running from Factory partition starting at 0x10000, [MicroPython].
Reset reason: Deepsleep wake-up
Wakeup source: RTC wake-up
uPY stack: 19456 bytes
uPY heap: 3073664/5520/3068144 bytes (in SPIRAM using heap_caps_malloc)
MicroPython ESP32_LoBo_v3.1.16 - 2017-02-04 on ESP32 board with ESP32
Type "help()" for more information.
>>> import machine
>>> machine.wake_description()
('Deepsleep wake-up', 'RTC wake-up')
>>>
Returns random number between 0
and limit
If the optional upper_limit
argument is given, returns random number between limit
and upper_limit
Read the internal ESP32 temperature sensor
Returns tuple of raw value and the temperature in °C
>>> import machine
>>> machine.internal_temp()
(134, 56.66666793823243)
Non-volatile storage (NVS) is designed to store key-value pairs in flash.
Currently NVS uses a portion of main flash memory through spi_flash_{read|write|erase} APIs.
Integer and string values can be saved into NVS.
Key - Value
pairs are used as arguments for NVS methods.
Variables saved in NVS are preserved on power off.
Save the integer value
with name key
in NVS
Return the saved integer key
from NVS
>>> machine.nvs_setint('myvar', 12345678)
>>> machine.nvs_getint('myvar')
12345678
>>>
Save the string value
with name key
in NVS
Return the saved string key
from NVS
>>> machine.nvs_setstr('mystr', "String saved in NVS")
>>> machine.nvs_getstr('mystr')
'String saved in NVS'
>>>
Erase the variable key
from NVS
Erase all variables from NVS
ESP32 log messages can be disabled or enabled with the desired log level.
Logging for the individual components or all components can be set.
The following constants can be used for setting the log level:
machine.LOG_NONE
, machine.LOG_ERROR
, machine.LOG_WARN
machine.LOG_INFO
, machine.LOG_DEBUG
, machine.LOG_VERBOSE
Set the log level of the component
to level log_level
component
is the name of the component as it apears in log messages.
'*'
can be used to set the global log level.
machine.loglevel("wifi", machine.LOG_DEBUG)
Neopixel
ADC
PWM
Onewire/DS18x20
RTC
Timer
UART
I2C
Pin
DAC
SPI
DHT