esptool
esptool is a Python-based, open-source, platform-independent utility for flashing, provisioning, and interacting with Espressif Systems' SoCs like ESP32 and ESP8266. It facilitates tasks such as reading, writing, erasing, and verifying flash data, alongside functions for reading chip features and preparing binary executable images. The current version is 5.2.0, and the library maintains an active development cycle with frequent updates and major releases.
Warnings
- breaking `esptool` v5.0.0 introduced significant breaking changes, including a major refactoring, CLI alterations, and a redesigned public Python API. Existing scripts and workflows from v4.x will likely require updates.
- breaking The `image-info` command output format changed, and the `--version` argument was removed in `esptool` v5.0.0. Additionally, the `execute-scripts` command was removed.
- gotcha The latest `esptool` (v5.x) requires Python 3.10 or newer. Using older Python versions will necessitate installing compatible older `esptool` releases.
- gotcha On some Python installations, `pip install esptool` may fail. Also, direct execution of `esptool.py` might not work in all environments, especially Windows Store Python.
- gotcha Since `esptool` v5, the recommended command-line invocation no longer uses the `.py` suffix (e.g., `esptool chip_id` instead of `esptool.py chip_id`). The `.py` versions are deprecated.
- gotcha Older versions of `esptool` (prior to v5.0.2 and v4.9.1) experienced buffering issues with CP2102 USB-to-UART converters, leading to connection failures.
- gotcha In certain older versions, stub flasher execution with active Secure Boot might fail on ESP32-S3 and ESP32-C3 chips.
Install
-
pip install esptool
Imports
- esptool
import esptool # Example of using the public API (v5+) # from esptool import ESPLoader, detect_chip # loader = detect_chip(port='/dev/ttyUSB0', baud=115200)
Quickstart
# To detect an attached Espressif chip and read its flash ID: # Replace '/dev/ttyUSB0' with your actual serial port (e.g., 'COM1' on Windows) # Ensure your ESP device is in flashing mode or connected correctly. esptool --port /dev/ttyUSB0 flash_id