Skip to content

Create beautiful .ino (Arduino) sketches with only Python knowledge - no extra skills needed! 🌟 It's effortless, fun and free! 😎

Notifications You must be signed in to change notification settings

pro-grammer-SD/pyduino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌟 PyDuino - Python to Arduino Bridge 🌟

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.


⚑ Features

  • Convert C++ headers to Python stubs (.py) πŸ“
  • Transpile Python scripts to Arduino .ino files βš™οΈ
  • Auto-generate setup() and loop() 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! πŸ—£οΈ

πŸ› οΈ Setup Guide

  1. Clone or download the PyDuino repo.
  2. Ensure that Python 3.11+ is installed.
  3. Run build.bat.
  4. Enjoy!
  5. Examples at: https://github.com/pro-grammer-SD/pyduino_seperate_tests/

πŸš€ Commands

1️⃣ Create a new project

python main.py create <project_name>

Creates a folder with main.py and lib/ for headers.

2️⃣ Convert C++ header to Python stub

python main.py convert-header <header_file> [--libclang <path_to_libclang>] # or you can skip --libclang by default!

Generates Python .py stubs in lib/.

3️⃣ Transpile Python to .ino

python main.py to-ino <python_file> [--auto-loop]

Generates .ino file. --auto-loop will call all functions in loop() automatically.

4️⃣ Setup Arduino AVR core

python main.py setupavr

Installs the Arduino AVR core using arduino-cli.

5️⃣ Upload Python script to Arduino

python main.py upload <python_file> [--auto-loop] [--port <COM>] [--list-ports] [--fqbn <fqbn>]
  • --auto-loop: auto-call functions in loop()
  • --port: specify COM port
  • --list-ports: show available boards
  • --fqbn: Fully Qualified Board Name (default: arduino:avr:uno)

πŸ“¦ Python-to-C++ Conversion

  • Converts Python for, while, if, and function definitions to Arduino C++.
  • Supports arithmetic, boolean, comparison, and unary operations.
  • Detects headers from from lib.<header> import lines.

πŸ’‘ Logging

  • Upload logs are stored in <sketch_dir>/logs/YYYYMMDD_HHMMSS.log

βš™οΈ Example Workflow

# 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.

πŸ’β€β™‚οΈ Extra Info

  • πŸ”’ 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

About

Create beautiful .ino (Arduino) sketches with only Python knowledge - no extra skills needed! 🌟 It's effortless, fun and free! 😎

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published