Resetting board will not run main.py

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
rankor
Posts: 38
Joined: Sun Nov 30, 2014 12:38 am

Resetting board will not run main.py

Post by rankor » Sun Jun 14, 2015 10:02 pm

When I run the program below the new main.py is created and the old files are removed. A reset is made but the new main.py does not start to execute until after I manually press reset as well. Then the blue LED is turned on. it does not make a difference if I use pyb.reset or pyb.hard_reset.
What am I missing?


#CodeSwap.py
import os

def write_to_file(file_name, text):
with open(file_name, 'w') as source_file:
source_file.write(text)

def remove_old_code():
os.remove("CodeSwap.py")
os.remove("main.py")

class CodeSwapper(object):
def __init__(self):
pass

def write_file(self):
pass

def reset(self):
pass



#main.py
import CodeSwap as CS

green = pyb.LED(2)
green.on()

CS.remove_old_code()
CS.write_to_file("main.py", "blue = pyb.LED(4)\nblue.on()\n")

yellow = pyb.LED(3)
yellow.on()

#pyb.hard_reset()
pyb.reset()

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

Re: Resetting board will not run main.py

Post by dhylands » Sun Jun 14, 2015 10:26 pm

Try adding a call to pyb.sync() before the reset

If you want to see the yellow led turn on, add a delay before the reset. The way it's coded now the yellow led will only be on for about a microsecond before it gets turned off by doing the reset.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Resetting board will not run main.py

Post by Damien » Mon Jun 15, 2015 7:43 am

You can also try using pyb.main("file.py") in boot.py to set the script to run after boot.py finishes.

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

Re: Resetting board will not run main.py

Post by dhylands » Mon Jun 15, 2015 6:16 pm

I had to change your pyb.reset() to pyb.hard_reset() (in the latest firmware its still called hard_reset). You can determine this from the repl:

Code: Select all

Micro Python v1.4.3-154-g1082234-dirty on 2015-06-15; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> 
>>> pyb.reset
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'reset'
>>> pyb.hard_reset
<function>
I also added an import pyb to the top of your CodeSwap.py file and also added an import pyb to your generated main.py file.

To find these "issues", I copied CodeSwap.py and called main.py code_swap.py, and then from the repl I used:

import code_swap

and that showed me various errors with the script. I also tried taking your generated main.py and importing it.

With the changes mentioned above, it seems to be working properly (I also added a delay after turning on the yellow led so I could see it turn on).

rankor
Posts: 38
Joined: Sun Nov 30, 2014 12:38 am

Re: Resetting board will not run main.py

Post by rankor » Sun Jun 21, 2015 10:38 pm

Hmm, I don't have pyb.reset or pyb.hard_reset.

pyb.info() or help() do not show the micropython version, how can I see that?

Weren't they included from the start?

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

Re: Resetting board will not run main.py

Post by dhylands » Mon Jun 22, 2015 5:34 am

If you press Contol-D you should see the python version.

I don't believe that pyb.reset and pyb.hard_reset were included in the Kickstarter boards.

The current (latest) version fo the firmware is:

Code: Select all

Micro Python v1.4.4-16-ga06c38b-dirty on 2015-06-21; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> 

rankor
Posts: 38
Joined: Sun Nov 30, 2014 12:38 am

Re: Resetting board will not run main.py

Post by rankor » Mon Jun 22, 2015 5:23 pm

Micro Python v1.3.3 on 2014-10-02; PYBv1.0 with STM32F405RG
Type "help()" for more information.

Bought it after kickstarter but maybe it was the same batch, will try to update the board.

rankor
Posts: 38
Joined: Sun Nov 30, 2014 12:38 am

Re: Resetting board will not run main.py

Post by rankor » Mon Jun 22, 2015 6:25 pm

Works now, had to upgrade the board.

Post Reply