How to have micro python interpreter running on a very simple function

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
soibac35
Posts: 6
Joined: Thu Aug 24, 2017 2:48 pm

How to have micro python interpreter running on a very simple function

Post by soibac35 » Thu Aug 24, 2017 2:59 pm

Hi everyone,

I am new to micropython and all.

So i am trying to call a function in a .py file 10 time and display the result on the terminal.

The python script is extremely simple :
def hello:
print("hello")

I downloaded the micropython master folder on github, and using minimal makefile with some tweak to fit with the file name that i have.
I used py-cross to generate the .mpy file and everything seem to work as _hello.c was generate.

The main.c is from minimal folder and only tweak file name .py when created the frozen module.

So my question is how can I automatically called the function hello from the python file and display that on the terminal when i use make run ?

Am i understand this one correctly ? My end goal is being able to use the python script with C code using embeded static library and load that to Arm cortext M3/4 chip

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: How to have micro python interpreter running on a very simple function

Post by torwag » Thu Aug 24, 2017 3:55 pm

Hi and welcome,
I am not sure what you are trying to do. If you simply want to execute the python code, there is no need for tweaking and compiling. Simply install the latest firmware for your board and copy your python function in a file 'main.py'. The python interpreter on the board will call main.py and execute everything quite similar as if you all 'python main.py' on a regular computer. From there you can go on, call other files, etc.
How to copy the file to the board differs a bit from board to board. However, it is all well explained in the docs.
Frozen bytecode and C interactions are possible but more advanced topics.

soibac35
Posts: 6
Joined: Thu Aug 24, 2017 2:48 pm

Re: How to have micro python interpreter running on a very simple function

Post by soibac35 » Thu Aug 24, 2017 5:01 pm

[quote="torwag"]Hi and welcome,
I am not sure what you are trying to do. If you simply want to execute the python code, there is no need for tweaking and compiling. Simply install the latest firmware for your board and copy your python function in a file 'main.py'. The python interpreter on the board will call main.py and execute everything quite similar as if you all 'python main.py' on a regular computer. From there you can go on, call other files, etc.
How to copy the file to the board differs a bit from board to board. However, it is all well explained in the docs.
Frozen bytecode and C interactions are possible but more advanced topics.[/quote]


Hi, thanks for replying,

The idea right now is to be able to create "micropython environment" in C main. Ie: be able to call the function in python script. The reason Im doing this is that i will write a C code and load that to C code into an arm chip.

Right now, im testing with just terminal display first before loading anything to the chip.

The final goal is to write a python script that can collect channel value of input/output and manipulated it then pass it on to C code, then pass it on to the arm chip to config the hardware

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: How to have micro python interpreter running on a very simple function

Post by deshipu » Thu Aug 24, 2017 8:54 pm

I'm afraid that's not how micropython works. It pretty much "owns" the whole microcontroller.

chrismas9
Posts: 152
Joined: Wed Jun 25, 2014 10:07 am

Re: How to have micro python interpreter running on a very simple function

Post by chrismas9 » Thu Aug 24, 2017 10:03 pm

There are several RTOS ports, eg CC3200 (freertos) and Zephyr. These might be worth looking at. The CC3200 port runs the Wi-fi C code along side MicroPython.

Post Reply