Dynamically programming Arduino from Python3

Anyone know of a program/library that allows for the dynamic generation of Arduino code? I would like to use python 3 to generate Arduino code dynamically. I have found some posts online, but they are all kind of older.

Arduino code is a binary CPU dependent executable, it is not some high level interpreted language.

What are you trying to achieve exactly ?

(If this is dynamic code level generation, Easiest way would be to generate from python a C or C++ file doing what you need, possibly linking with pre-existing files, and trigger the compilation/upload in the same way the arduino IDE builds the code and transfers it into your arduino)

lonesoac0:
I have found some posts online, but they are all kind of older.

If you post some links to them we may have a better idea what you want to achieve.

Is this a Python3 vs Python2 question?

...R

GitHub - sudar/Arduino-Makefile: Makefile for Arduino sketches. It defines the workflows for compiling code, flashing it to Arduino and even communicating through Serial. seems to be the best choice for what I am up to. I would like to be able to program LEDs from a Python based web app. The LEDs are NeoPixels.

I have no experience with Neopixels nor with Arduino as a web client, but can't you just load a pattern file that the Arduino will 'play'?

//Edit
To elaborate

Write a sketch that can take data (the pattern) from your web server; once the data is loaded, let the sketch control the Neopixels based on on the received data. You might want to (or have to) store the received data in non-volatile memory (internal eeprom or e.g. external eeprom as the pattern might get quite big) so after a reset / power cycle it's still available.

I'm sensing an XY question here - why would you want to dynamically generate code in python?

Would you like a python app to tell your arduino to do various things - to have a python slider that adjusts the colour of an LED? Generally, you don't do this by having pythoon generate a sketch with the right colour, compile it, and upload it. Instead you write a sketch that accepts control input "I would like the LED to be red, now" and responds to that input.

You might want to have a look at the Arduino and Python playground ideas and read the serial basics tutorial to understand how to best structure your arduino side listening to commands

Remember also that on many arduino when a serial connection is established it resets the Arduino so don't open and close the serial all the time, open it once, allow time for your arduino to boot and reach the point where it awaits serial commands and send pattern data either to be saved in memory and played or just played instantly in which case care will need to be given to handling timing ((remember your desk computer/laptop is much faster than your arduino and the arduino has a small memory)

lonesoac0:
I would like to be able to program LEDs from a Python based web app. The LEDs are NeoPixels.

I suspect that all you need to do is use your Python program to send some data to an Arduino program telling it which LEDs should light and for how long. That is not at all the same as programming the Arduino using Python.

This Python - Arduino demo may help.

It may need a little modification for Python 3 as it was written with 2.7

...R

Thank you all for the information. I think issuing commands via serial would be best.

jsmith2021:
On the topic of dynamic code generation,

It is good of you to share your code but I can see no reason for adding your Post into this old Thread about Python.

I suggest you click Report to Moderator and ask to have you Post moved to its own Thread maybe in the Exhibition / Gallery section.

...R

PS ... my link will make more sense if my comment is moved with your Reply #9