Skip to main content

Reduino transpiles Python scripts into efficient Arduino C++ and uploads automatically. A simple, intuitive way to control sensors, LEDs, and actuators without touching C++.

Project description

Reduino project illustration

Reduino

Write expressive Python that turns into Arduino-flavoured C++ and optional PlatformIO projects. Reduino lets you describe LED-centric sketches with familiar control flow, transpiles the script into Arduino code, and (optionally) compiles/uploads it for you.


Table of contents

Quick start

  1. Install dependencies
    pip install -e .
    pip install platformio  # required for uploads
    
  2. Create a script
    from Reduino import target
    from Reduino.Actuators import Led
    from Reduino.Time import Sleep
    
    target("/dev/ttyACM0", upload=False)
    
    led = Led(13)
    for _ in range(3):
        led.toggle()
        Sleep(250)
    while True:
        led.toggle()
        Sleep(500)
    
  3. Run the script – the transpiled C++ is printed and written into a temporary PlatformIO project. If upload=True, Reduino also calls pio run -t upload for you.

Generated projects target an Arduino Uno by default and live in a temporary folder. You can re-run pio run manually to rebuild or flash again.

How Reduino works

  1. ParsingReduino.transpile.parser.parse() reads your Python script and builds an intermediate representation (Program, LedDecl, Sleep, etc.).
  2. Analysis – literals and expressions are folded where possible (for example constant arithmetic or tuple unpacking), and control structures like if/elif/else are preserved in the IR.
  3. EmissionReduino.transpile.emitter.emit() turns the IR into Arduino-ready C++. Pin declarations create pinMode calls and global state, and sleep nodes become delay() statements.
  4. Toolchain integrationReduino.target() calls emit(parse(src)), prints the result, and uses the PlatformIO helpers in Reduino.toolchain.pio to write a main.cpp plus platformio.ini pointing at the requested serial port.

The pipeline keeps parsing/emission side-effect free so your host machine never drives hardware directly—hardware interaction only happens once the generated sketch runs on the board.

Supported devices & primitives

Primitive Description Key operations
Reduino.Actuators.Led(pin=13) Represents a digital output LED. The helper mirrors the generated C++ and is safe to use in tests. .on(), .off(), .toggle(), .get_state()
Reduino.Time.Sleep(ms) Millisecond delay helper that can also execute waits on the host side. .wait(), callable shortcut (e.g. Sleep(500)())
Reduino.target(port, upload=True) Transpile the calling module, emit C++, and optionally compile/upload with PlatformIO. Prints generated code, writes a project, triggers pio run/pio run -t upload

Supported Python features

Reduino focuses on a lightweight DSL that feels like idiomatic Python while staying safe for static analysis.

Control flow

  • while True: blocks become the Arduino loop() body.
  • for i in range(N): loops at top-level unroll into repeated setup statements.
  • if / elif / else constructs are preserved with their conditions.

Variables & assignments

  • Regular assignments, tuple unpacking, and reassignments in setup scope create matching C++ declarations.
  • Branch-local assignments are promoted to globals so both sides of an if can mutate them safely.

Expressions & built-ins

  • Integer, float, string, and boolean literals.
  • Arithmetic, bitwise, boolean, and comparison operators.
  • Safe casts: int(), float(), bool(), str().
  • Built-ins: len(), abs(), max(), min() (with helper snippets emitted automatically).

Device primitives

  • Instantiate LEDs with literal pins or symbolic expressions; actions translate to digitalWrite calls (HIGH, LOW, and toggled states are handled automatically).
  • Sleep expressions become delay(ms) even when the argument is symbolic.

Target directive

  • target("PORT") can appear anywhere at top level; the last call wins and is written into platformio.ini.

Testing

Install the optional development dependencies and run the test suite:

pip install -e .[dev]
pytest

The tests exercise parser behaviour, code generation, runtime helpers, and the public actuator/time primitives.

Contributing

We welcome new actuators, sensors, and improvements to the transpiler. See CONTRIBUTING.md for a detailed guide.

License

Reduino is released under the GNU General Public License v3.0 (GPL-3.0).

This means you are free to:

  • Use, modify, and distribute Reduino under the terms of the GPL-3.0.
  • Build upon it in your own open-source projects, provided your derivative works remain open-source under the same license.

However, if you would like to:

  • Use Reduino in a closed-source, commercial, or proprietary product,
  • Obtain a custom or dual license for integration in commercial environments,

please reach out for licensing options:

📧 Commercial inquiries: arnavbajaj9@gmail.com


© 2025 Arnav Bajaj. All rights reserved.

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

reduino-0.0.2.tar.gz (43.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reduino-0.0.2-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file reduino-0.0.2.tar.gz.

File metadata

  • Download URL: reduino-0.0.2.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for reduino-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2bb73d7c25c894732d1e7fce2c187228a40bc7f5e40a2bc5d06da7bb300e724f
MD5 0a402b6a065f96b774aec3acfd296758
BLAKE2b-256 a233086ab8e7b94c554fb4a35ab9b21c2eb0b63c8a550b7e3bcf5f674e4c572b

See more details on using hashes here.

File details

Details for the file reduino-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: reduino-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for reduino-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 89298fc4f49cdfec842de21239ee479ff03967f0b85eb45f7f6f332d831a3c54
MD5 fa699d993b98692cbb6f0d8d402b318e
BLAKE2b-256 7cbb685c99b77ab4b7655fc71205ba8aa6ce25dd03be249c79e5e95247dfbef2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page