Is there a way to "compile" Python code on Arduino (Uno)?

I have a robotics type project with Arduino Uno , and to make a short story, I am experimenting with some AI algorithms. However, I need to implement some high-level matrix algorithms that would be fairly simple using NumPy / SciPy , but they are a complete nightmare in C or C ++. Even with libraries, this is just ridiculous.

Is there a way to make this project in Python? I think I heard something about Mega that has this feature, but I have Uno, and replacement at this point is not an option (to install the project a little back.) In addition, I heard something about How to use Python to communicate with Arduino via USB, but I can’t connect the USB cable while working. I need to be able to download the program and execute it.

Are there any options out there, or have I just reached a dead end?

+46
python arduino pyserial
Nov 13 2018-11-21T00:
source share
2 answers

There was talk of using Python with robotics in these years of PyConAU called Ah! I see that you have a car that goes "BING"! from Dr. Graham Cross.

The only option he recommended for using Python on a microcontroller board was PyMite , which I think is also called Python-On-A-Chip .

It has been ported to a number of boards - in particular, it mentions that the Arduino Mega that you said is not an option for you, but it is possible that it is supported on other Arduino boards.

However, since this is a version of Python that is not included in the package, it is more likely that you will have problems starting and running numpy / scipy, etc.

As other posters suggested, implementing in C might be the least resistance.

Update: again, not specifically for Arduino, but pyMCU offers to provide python on a chip. The author claims that he can study the development of the Arduino pyMCU version, if that is enough.

+17
Nov 15 2018-11-11T00:
source share
β€” -

I started working on Little Python in C ++ (called Pyxie - a game in Py CC-Pyc-C) with the specific goal of compiling a subset of the python routines in C ++ so that it could work in arduino.

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

The program that he can compile is as follows:

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

It analyzes, performs analysis (for example, type inference, etc.), compiles in C ++, which then compiles to a hex file, which you can download to your device.

Before that, he must go a long way useful , but he is progressing and has a roadmap, etc.

In particular, the key difference from Micropython (and PyMite) is that it is designed to compile devices that are too small to run or implement. (This also means that it is very different from things like ShedSkin, which, although the Python compiler for C ++ targets the larger runtimes)

+3
Aug 03 '15 at 13:03
source share



All Articles