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

Reduino

Write friendly Python. Get Arduino-ready C++. Upload Easily to MCUs.

License GitHub Repo stars GitHub forks GitHub watchers GitHub followers Closed PRs Closed issues Repo size Latest release PyPI version PyPI downloads

Table of contents

Overview

Reduino lets you write a small, Pythonic DSL that transpiles to clean Arduino C++ and optionally flashes your board via PlatformIO. You get readable Python during development and reliable C++ on the device.

Quick start

Requirements: Python 3.10+, PlatformIO for building/flashing.

pip install Reduino
pip install platformio  # required for uploads

If upload=True, Reduino will run pio run -t upload for you in a temporary PlatformIO project (Arduino Uno by default). You can re-run pio run later to rebuild or flash again.

How it works

  1. ParseReduino.transpile.parser.parse() builds an intermediate representation (IR) from your script.
  2. Analyze – Constant folding, control-flow preservation, and safety checks happen on the IR.
  3. EmitReduino.transpile.emitter.emit() produces Arduino-ready C++ (main.cpp).
  4. ToolchainReduino.target() writes a platformio.ini (serial port & board), and optionally calls PlatformIO to build/flash.

Hardware side effects only occur on the device after upload—host-side execution is side-effect free.

API reference

Reduino.Actuators.Led

Member Description
Led(pin=13) Create a virtual LED bound to an Arduino pin.
on() / off() Turn LED fully on/off.
toggle() Flip between on/off.
get_state() True if LED is currently on.
get_brightness() / set_brightness(v) PWM level (0–255) read/write. Raises ValueError if out of range.
blink(duration_ms, times=1) Blink helper with internal waits.
fade_in(step=5, delay_ms=10) / fade_out(step=5, delay_ms=10) Gradual brightness ramp.
flash_pattern(pattern, delay_ms=200) Iterate over [0/1 or 0–255] values.

Example

from Reduino.Actuators import Led
led = Led(5)
led.set_brightness(128)
led.blink(250, times=3)

Reduino.Time.Sleep

Member Description
Sleep(ms, sleep_func=None) Delay helper; custom sleep_func is injectable for tests.

Example

from Reduino.Time import Sleep
Sleep(500)

Reduino.target

Member Description
target(port, upload=True) Transpile the current module; return generated C++. If upload is true, also build & flash via PlatformIO. The last call wins if used multiple times at top level.

Example

from Reduino import target
cpp = target("/dev/ttyACM0", upload=False)
print(cpp)

Supported Python features

Control flow

  • while True: becomes the Arduino loop() body.
  • for over range(...), lists/tuples, or generator expressions.
  • if / elif / else, ternaries, break/continue.

Variables & assignment

  • Regular assignment, tuple unpacking, pythonic swap a, b = b, a.
  • Augmented ops (+=, -=, ...). Branch-local vars are promoted safely.

Collections & comprehensions

  • Lists/tuples/dicts, membership tests, list methods (append, extend, ...).
  • List comps & generators (evaluated eagerly into temps for safety).

Functions & expressions

  • def/return, defaults, lambdas (on supported expressions).
  • Literals: int/float/str/bool; casts: int/float/bool/str.
  • Built-ins: len, abs, max, min, sum, range.

Device primitives

  • LED pin init creates pinMode; actions become digitalWrite/PWM; sleeps become delay(ms).

Target directive

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

Testing

pip install pytest
pytest

The suite covers parsing, emission, runtime helpers, and public primitives.

Contributing

PRs for new actuators/sensors and transpiler improvements are welcome. See CONTRIBUTING.md for guidelines and the IR/emitter architecture.

License

Reduino is distributed under GPL-3.0.

You may:

  • Use, modify, and distribute under GPL-3.0.
  • Build upon it in your open-source projects (derivatives must also be GPL-3.0).

For closed-source or commercial use, dual/custom licensing is available.

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.3.tar.gz (53.8 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.3-py3-none-any.whl (46.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: reduino-0.0.3.tar.gz
  • Upload date:
  • Size: 53.8 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.3.tar.gz
Algorithm Hash digest
SHA256 173af4adbf905f209b235affbbb7197ef1f90974cba3d7ac5746b55235fe2028
MD5 636189964171ebfd546829eed4c8c52d
BLAKE2b-256 04e1a4421a012e7306d5e9185b240537f057b27be16eef4dce3a66ec8b117672

See more details on using hashes here.

File details

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

File metadata

  • Download URL: reduino-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 46.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8b8a1f9e35cab06509c7bce88b638c3e0688eb0feb238cebed0e8388a8f4698e
MD5 ffaeb016c8d929b2d9b8ccbf102a9121
BLAKE2b-256 b9806c7375cf1e6232f20fa9f7e73f4a3abddfbd8fee217f0451fa394508d92a

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