pyb.main() won't execute my file

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
MrRobot
Posts: 31
Joined: Mon May 11, 2020 11:30 am

pyb.main() won't execute my file

Post by MrRobot » Mon Jul 27, 2020 10:57 am

So I have a boot.py like this:

Code: Select all

import machine
import sys, os, pyb
import time

pyb.usb_mode('VCP') # Virtual COM Port Only

if pyb.SDCard().present():

    try:
        os.mount(pyb.SDCard(), '/sd')
        sys.path[1:1] = ['/sd','/sd']
        os.chdir('/sd')
    except Exception as e:
        sys.print_exception(e)
        print('Error mounting SD')

else:
    print('SD Card not present')

pyb.main('/sd/main.py')

The SD card mounts correctly but it won't run the main.py on the SD card.

I only have a boot.py on the flash and all my other files on the SD card.

What am I doing wrong?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: pyb.main() won't execute my file

Post by jimmo » Tue Jul 28, 2020 6:12 am

MrRobot wrote:
Mon Jul 27, 2020 10:57 am
I only have a boot.py on the flash and all my other files on the SD card.
If the SD card is present, then boot.py will run from there instead. (i.e. I don't think your boot.py is being run at all).

See https://docs.micropython.org/en/latest/ ... nd-sd-card

You have a couple of options:
- move boot.py to the SD card and remove the code to mount the SD card (it happens automatically)
- add SKIPSD to the flash and keep boot.py on the flash (and then have it mount SD manually as you're currently doing)

MrRobot
Posts: 31
Joined: Mon May 11, 2020 11:30 am

Re: pyb.main() won't execute my file

Post by MrRobot » Tue Jul 28, 2020 9:42 am

I found the problem:

In my program I enter a deep sleep state then loop over and over.

When the pyboard started up rshell automatically connected to it and must kill the loop.

When I don't use rshell the loop/sleep works fine.

So if you use deepsleep and rshell be aware of rshell killing the repl

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

Re: pyb.main() won't execute my file

Post by dhylands » Tue Jul 28, 2020 3:13 pm

rshell uses raw mode. In order to enter raw mode a control-C is issued to break any running program and then it enters raw mode which also does a soft reset. When entering raw mode boot.py is executed but main.py isn’t.

MrRobot
Posts: 31
Joined: Mon May 11, 2020 11:30 am

Re: pyb.main() won't execute my file

Post by MrRobot » Wed Jul 29, 2020 11:20 am

Thanks for clarifying.

I was puzzled for ages! :lol:

Post Reply