pfalcon / pycopy

Pycopy - a minimalist and memory-efficient Python dialect. Good for desktop, cloud, constrained systems, microcontrollers, and just everything.

Home Page:http://pycopy.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] Is it possible to integrate Pycopy into existing Arduino project

mrkeuz opened this issue · comments

I very new in "micro" python and does not have a long experience in c/c++. I have a question about proper and idiomatic way to running embedded pycopy on single-threaded with any given way:

  • Return to top of call stack. With save state. I mean in loop call something like "run python on 300 millisecond and pause".
  • Or via dispatched yield() on Arduino.

I googled for several hours and found two solutions (related to cPython):

  1. Use Py_AddPendingCall function. But written in the documentation it is not guaranteed to call this method periodically. Also, I was unable to use it together with "PyRun_SimpleString", this solution does not work and is called only once at the beginning. Since I have not work with C/Python bindings before, and I don’t know his kitchen, maybe something needs to be adjusted.

  2. Second solution as I see is to use call some native C call and call yield(). If I understand correctly it should be something like next c-function called with every some timeout:

    Scheduler.yield();
    

In summary my question is what APIs and methods can be used in pycopy to pause all current threads and return control to the dispatcher. My goal is understood can I use pycopy/micropython along standard Arduino project. I.e. link pycopy as library, but not via prepared firmware.

My potentially target is ESPHome project. It processes sensors in loop. All logic called in common loop() with recommended time limit to each module (I.e. not more 200 milliseconds).

I want to understand can I integrate interpreter (with long live scripts) in such environments?

Thanks for your interest in Pycopy. Potentially, that would be possible. But the paradigm of Pycopy is that it is the main, high-level system which controls a computer system or device, and you integrate other parts into it, not vice-versa. That's how I use and perceive it. Obviously, you can use it in any way you like [but I can't help with uses I'm currently not interested in].