The new version of DSPython is now under the development in dev branch!
DSPython is in the very initial stage of a development phase and should not be used in a production environment.
You can browse the examples directory to learn how DSPython interacts with Arduino.
Are you disappointed? Please consider contributing!
🐍 Python compiler intended to use in Arduino.
The Micropython project aims to put an implementation of Python 3 on microcontrollers, but it is not for Arduino.
DSPython uses LLVM to provide a way to compile programs written in the Python programming language. The generated LLVM bytecode is intended to be similar to C++'s.
Accordingly, DSPython is internally not a Python at all.
Here is an example program that blinks the built-in LED of Arduino Uno:
# Blink the built-in LED of Arduino Uno!
from arduino import *
def setup():
pin_mode(13, 1)
def loop():
digital_write(13, 1)
delay(1000)
digital_write(13, 0)
delay(1000)
To compile and upload this source, you can specify the serial port to upload by providing the --upload-to
option.
For example, this compiles and uploads the blink example to the Arduino:
dspython examples/Blink.py --upload-to YOUR_PORT
Currently, All examples have been tested only on Arduino Uno.
- LLVM 10 (include llvm-config)
On Windows, the official LLVM releases do not contain many important components. You have to use pre-built LLVM binary built for Ziglang
- Arduino IDE
You have to set the environment variable named ARDUINO_DIR
to your arduino IDE location.
This is because DSPython requires Arduino standard headers, avr-gcc compiler, and avrdude.
Contributions are more than welcome!
This is my first project using LLVM and Rust language. Please share your opinions. Any ideas would be highly appreciated!
- Damn small binary size
- Support Arduino or microcontrollers
- Programming Arduino with seemingly Python-like language
These are not impossible, but currently not our goals.
- Compile to other platforms
- Garbage collector
- Class and inheritance
- Complete Python implementation
- Compile all python standard libraries
- Support threading or asynchronous functions
I wanted to program Arduino in other languages as well as C++ and thought the Python language would be a good choice. That's why I decided to make a Python compiler that is available to upload directly to the Arduino.
The distinctive feature of DSP is that it uses LLVM internally instead of emitting C++.
Licensed under the MIT License
Copyright 2022 Donghyeok Tak
- The python parser is based on RustPython
- Value handler from testlang
- LLVM binding for rust is Inkwell