Call from main.py

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Maleda
Posts: 1
Joined: Tue Sep 19, 2017 8:19 pm

Call from main.py

Post by Maleda » Tue Sep 19, 2017 8:25 pm

Hello,

I would like to start my python script from main.py. I tried to simplify the script by only having one line within the file test.py

The line is:
print('test')

Now, I want to avoid to past this line directly into the main.py, instead I want to simply start the test.py.
I already read the pdf micropython8266.pdf but the information within the document didn't work.

I know that it must be a completely stupid solution but after 2 hours I didn't find a solution.

BR Marcus

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Call from main.py

Post by dhylands » Wed Sep 20, 2017 5:40 pm

The micropython main loop goes something like this:

Code: Select all

start-of-loop:
    call boot.py
    call main.py
    enter REPL
    goto start of loop
If you want the code to stay in main.py and not leave it, then you need to write the code to do that. Something along the lines of:

Code: Select all

while True:
    print('Wasting time. Press Control-C to exit main.py')
    utime.sleep(5)
Technically, you don't need the delay, but it will cause less CPU to be consumed since the MCU will enter a lower sleep state.

Post Reply