Running boot script on flash then attaching SD card

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
shaun5773
Posts: 1
Joined: Mon Aug 02, 2021 10:35 pm

Running boot script on flash then attaching SD card

Post by shaun5773 » Mon Aug 02, 2021 10:48 pm

I have built my own version of the Pyboard. It is mostly the same but one of the changes I made is to switch the power to the SD card via a GPIO. The reason for this is that I am building a datalogger that uses deepsleep to save power but if I leave the SD card powered on the whole time the sleep current is about ~3ma which is much to high for my battery operated purposes. If I remove the SD card it drops down to 5uA which is much better.

Now what I am trying to do is when the Pyboard wakes up from sleep it runs the boot script on the flash memory which is fine. I then turn on a GPIO in that script which provides power to the attached SD card. I then want to mount that SD card and run the main.py file on that SD card. Is that possible?
I have tried the below code but it returns OSError: [Errno 19] ENODEV

Code: Select all

if pyb.SDCard().present():
    os.mount(pyb.SDCard(), '/sd')
    sys.path[1:1] = ['/sd', '/sd/lib'][code]
[/code]

I am not entirely sure how the boot.py works but it seems that if the SD card is not present when that script first runs I can't mount the SD card afterwards? Is there a way around this issue? Thanks

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

Re: Running boot script on flash then attaching SD card

Post by jimmo » Wed Aug 04, 2021 6:10 am

shaun5773 wrote:
Mon Aug 02, 2021 10:48 pm
I am not entirely sure how the boot.py works but it seems that if the SD card is not present when that script first runs I can't mount the SD card afterwards? Is there a way around this issue? Thanks
I don't have an easy way to test this right now, but based on what you're saying my guess as to what's happening is that similar logic is already implemented in the startup code (i.e. check if SD is present, then try and mount it). Even though there's no power, it will still be detected as present I'm guessing. Have you tried disabling SD-card-mount-at-boot (i.e. add a file named SKIPSD to the flash filesystem). See https://docs.micropython.org/en/latest/ ... nd-sd-card

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Running boot script on flash then attaching SD card

Post by pythoncoder » Thu Aug 05, 2021 5:15 am

I don't know the answer re the built-in SD card, but I solved this problem by fitting a separate SD card using the official driver. Power to the SD card is switched by a MOSFET, and the Pyboard has no SD card fitted. So I power up the external SD card, initialise it, write to it, close the file and power it down.
Peter Hinch
Index to my micropython libraries.

Post Reply