Page 1 of 1

Resetting board will not run main.py

Posted: Sun Jun 14, 2015 10:02 pm
by rankor
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()

Re: Resetting board will not run main.py

Posted: Sun Jun 14, 2015 10:26 pm
by dhylands
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.

Re: Resetting board will not run main.py

Posted: Mon Jun 15, 2015 7:43 am
by Damien
You can also try using pyb.main("file.py") in boot.py to set the script to run after boot.py finishes.

Re: Resetting board will not run main.py

Posted: Mon Jun 15, 2015 6:16 pm
by dhylands
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).

Re: Resetting board will not run main.py

Posted: Sun Jun 21, 2015 10:38 pm
by rankor
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?

Re: Resetting board will not run main.py

Posted: Mon Jun 22, 2015 5:34 am
by dhylands
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.
>>> 

Re: Resetting board will not run main.py

Posted: Mon Jun 22, 2015 5:23 pm
by rankor
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.

Re: Resetting board will not run main.py

Posted: Mon Jun 22, 2015 6:25 pm
by rankor
Works now, had to upgrade the board.