PyDuino is a Python-to-Arduino transpiler and uploader. Write Arduino sketches in Python, automatically convert them to C++ .ino files, and upload to your Arduino board.
- Convert C++ headers to Python stubs (
.py) π - Transpile Python scripts to Arduino
.inofiles βοΈ - Auto-generate
setup()andloop()if missing π - Upload sketches directly to Arduino from Python π
- Detect Arduino headers in Python files π
- List available COM ports π‘
- Support for multiple function overloads and basic Python-to-C++ expressions β¨
- Your comments are retained! π£οΈ
- Clone or download the PyDuino repo.
- Ensure that Python 3.11+ is installed.
- Run
build.bat. - Enjoy!
- Examples at: https://github.com/pro-grammer-SD/pyduino_seperate_tests/
python main.py create <project_name>Creates a folder with main.py and lib/ for headers.
python main.py convert-header <header_file> [--libclang <path_to_libclang>] # or you can skip --libclang by default!Generates Python .py stubs in lib/.
python main.py to-ino <python_file> [--auto-loop]Generates .ino file. --auto-loop will call all functions in loop() automatically.
python main.py setupavrInstalls the Arduino AVR core using arduino-cli.
python main.py upload <python_file> [--auto-loop] [--port <COM>] [--list-ports] [--fqbn <fqbn>]--auto-loop: auto-call functions inloop()--port: specify COM port--list-ports: show available boards--fqbn: Fully Qualified Board Name (default:arduino:avr:uno)
- Converts Python
for,while,if, and function definitions to Arduino C++. - Supports arithmetic, boolean, comparison, and unary operations.
- Detects headers from
from lib.<header> importlines.
- Upload logs are stored in
<sketch_dir>/logs/YYYYMMDD_HHMMSS.log
# Create a project
python main.py create MyProject
# Convert a header
python main.py convert-header lib/CheapStepper.h
# Transpile Python to .ino
python main.py to-ino main.py --auto-loop
# List ports
python main.py upload main.py --list-ports
# Upload to board
python main.py upload main.py --port COM3 --fqbn arduino:avr:uno
#π‘ Tip: the port is auto-detected, so generally in normal cases you don't need to specify it. Only use it if you really need to.- π PyDuino currently supports Windows only. It would be great if you could help me to port it to other operating systems.
- π Also, feel free to help me improve this library, block-by-block! PRs are always welcome and openly supported!
Made with π by @pro-grammer-SD