ESP32IO is a Python API that turns an ESP32‑S3 into a USB‑connected I/O device.
Project description
ESP32IO Python API
日本語 / English
日本語
ESP32IO は、ESP32-S3 を USB シリアル経由で Python から扱うための軽量クライアントです。 ESP32 側で JSON コマンドを受け取るファームウェアと組み合わせることで、デジタル入出力、ADC、PWM をシンプルな Python API で操作できます。
特徴
- USB シリアル経由で ESP32-S3 と通信
- JSON プロトコルを
ESP32IOクラスが隠蔽 ping、DIO、ADC、PWM、全体状態取得をサポート- タイムアウト、プロトコル不整合、ESP32 側エラーを例外として統一処理
- 低レベル API
command()も用意
動作環境
- Python 3.8 以上
pyserial>=3.5- 対応する ESP32-S3 ファームウェア
インストール
開発中のローカル環境で使う場合:
pip install -e .
依存関係だけ入れる場合:
pip install -r requirements.txt
クイックスタート
from esp32io import ESP32IO
esp = ESP32IO("COM4", debug=False, recv_timeout=2.0)
print("ping =", esp.ping())
print("di0 =", esp.read_di(0))
print("adc0 =", esp.read_adc(0))
esp.set_do(0, 1)
esp.set_pwm(0, 128)
state = esp.get_io_state()
print(state)
esp.close()
サンプル実行:
py -m examples.esp32io_sample
API 一覧
ESP32IO(port, baud=115200, timeout=2.0, debug=False, recv_timeout=None)シリアルポートを開いて ESP32 に接続します。ping() -> bool疎通確認を行い、pong応答を検証します。read_di(pin_id) -> intデジタル入力を 0 または 1 で返します。set_do(pin_id, value) -> dictデジタル出力を設定します。read_adc(pin_id) -> intADC 値を返します。set_pwm(pin_id, duty) -> dictPWM デューティを設定します。get_io_state() -> dictDIO、ADC、PWM の状態をまとめて返します。command(cmd, **kwargs) -> dict任意の JSON コマンドを送る低レベル API です。close() -> Noneシリアルポートを閉じます。
例外
ESP32IOErrorESP32 がstatus=errorを返した場合ESP32IOTimeoutError応答待ちがタイムアウトした場合ESP32IOProtocolErrorJSON 不正や期待しない応答を受けた場合
想定コマンド
このクライアントは、少なくとも以下のコマンドを実装したファームウェアを前提にしています。
pingread_diset_doread_adcset_pwmget_io_state
プロジェクト構成
.
├── esp32io/
│ ├── __init__.py
│ ├── client.py
│ ├── exceptions.py
│ └── protocol.py
├── examples/
│ └── esp32io_sample.py
├── pyproject.toml
├── requirements.txt
├── LICENSE
└── README.md
ファームウェアについて
この Python パッケージ自体には ESP32 側ファームウェアは含まれていません。 別途、同じ JSON コマンド仕様に従う ESP32-S3 ファームウェアを用意してください。
ファームウェア:
https://github.com/noritama-lab/esp32io-firmware
ライセンス
MIT License
Copyright (c) 2026 Noritama-Lab
English
ESP32IO is a lightweight Python client for controlling an ESP32-S3 over USB serial. When paired with firmware that accepts JSON commands, it provides a small and practical API for digital I/O, ADC, and PWM control.
Features
- USB serial communication with ESP32-S3
- JSON protocol hidden behind the
ESP32IOclient - Support for
ping, DIO, ADC, PWM, and full I/O state reads - Unified exception handling for device errors, timeouts, and protocol issues
- Includes a low-level
command()API for custom commands
Requirements
- Python 3.8+
pyserial>=3.5- Compatible ESP32-S3 firmware
Installation
For local development:
pip install -e .
To install dependencies only:
pip install -r requirements.txt
Quick Start
from esp32io import ESP32IO
esp = ESP32IO("COM4", debug=False, recv_timeout=2.0)
print("ping =", esp.ping())
print("di0 =", esp.read_di(0))
print("adc0 =", esp.read_adc(0))
esp.set_do(0, 1)
esp.set_pwm(0, 128)
state = esp.get_io_state()
print(state)
esp.close()
Run the sample:
py -m examples.esp32io_sample
API Summary
ESP32IO(port, baud=115200, timeout=2.0, debug=False, recv_timeout=None)Opens the serial port and prepares the client.ping() -> boolVerifies connectivity by checking for apongresponse.read_di(pin_id) -> intReads a digital input and returns0or1.set_do(pin_id, value) -> dictSets a digital output.read_adc(pin_id) -> intReads an ADC value.set_pwm(pin_id, duty) -> dictSets a PWM duty cycle.get_io_state() -> dictReturns DIO, ADC, and PWM state in one response.command(cmd, **kwargs) -> dictLow-level API for sending custom JSON commands.close() -> NoneCloses the serial port.
Exceptions
ESP32IOErrorRaised when the device returnsstatus=errorESP32IOTimeoutErrorRaised when waiting for a response times outESP32IOProtocolErrorRaised for invalid JSON or unexpected responses
Expected Firmware Commands
The client expects firmware that implements at least these commands:
pingread_diset_doread_adcset_pwmget_io_state
Project Structure
.
├── esp32io/
│ ├── __init__.py
│ ├── client.py
│ ├── exceptions.py
│ └── protocol.py
├── examples/
│ └── esp32io_sample.py
├── pyproject.toml
├── requirements.txt
├── LICENSE
└── README.md
Firmware
This repository contains the Python package only. Prepare separate ESP32-S3 firmware that follows the same JSON command protocol.
Firmware repository:
https://github.com/noritama-lab/esp32io-firmware
License
MIT License
Copyright (c) 2026 Noritama-Lab
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file esp32io-0.1.1.tar.gz.
File metadata
- Download URL: esp32io-0.1.1.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c609e9dc32b08c7f5817fef49177488164d751904ba7d2cfe9888d4488da753
|
|
| MD5 |
3221597c48a8653c57f74f7f9cb4c7f9
|
|
| BLAKE2b-256 |
3d8f083bfb9b1a56d26b319871447ec9daf58dcbabfdcbb7e248e5d44918528b
|
File details
Details for the file esp32io-0.1.1-py3-none-any.whl.
File metadata
- Download URL: esp32io-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a926b1de7206b4c50d532a4da1b4cef429dd03c25f5a1b9e6c84bf587d8c06d4
|
|
| MD5 |
dda19695802c39b434adfd8b59a7136f
|
|
| BLAKE2b-256 |
de326be903a5837cd7a686e9147545df8cb9f4f2773f8699defaa37e23bdca97
|