Is there a way to “compile” Python code onto an Arduino (Uno)?

后端 未结 4 822
生来不讨喜
生来不讨喜 2021-01-30 12:48

I have a robotics type project with an Arduino Uno, and to make a long story short, I am experimenting with some AI algorithms. However, I need to implement some high level matr

4条回答
  •  生来不讨喜
    2021-01-30 13:16

    I've started work on a "Little Python" to C++ (called Pyxie - a play on Py CC- Pyc-C) compiler, with the specific aim of compiling a sane subset of python to C++ such that it can run on an arduino.

    This is far from complete at time of writing (0.0.16), but it can currently compile a very small subset of python - enough for the arduino "blink" example to run. To support this, it has a compilation profile - which essentially means "compile using the arduino toolchain."

    A program it can compile looks like this:

    led = 13
    
    pinMode(led, OUTPUT)
    
    while True:
      digitalWrite(led, HIGH)
      delay(1000)
      digitalWrite(led, LOW)
      delay(1000)
    

    This parses, performs analysis (like type inference, etc), compiles to C++, which is then compiled to a hex file, which you can load onto your device.

    There's a long way to go before it's useful, but it is progressing and does have a roadmap/etc.

    • PyPI - http://pypi.python.org/pypi/pyxie
    • Homepage - http://www.sparkslabs.com/pyxie/index.html

    In particular a key difference from Micropython (and PyMite) is that it's designed to compile to devices too small to run either implementation. (This also means it's very different from things like ShedSkin which while a Python to C++ compiler target larger execution environments)

提交回复
热议问题