Page 1 of 1

sd card init in boot.py, sd card deinit in main.py - possible?

Posted: Wed Jan 27, 2021 12:29 pm
by lorenz
Hello,

first of all thanks a lot for this forum (and the core team of people answering) and micropython in general. I really enjoy working with it and the forum has already helped me a lot.

Now my question:
I was wondering whether it is possible be able to get the machine.SDCard() in main.py also?
If I declare it again, like in the example below, I get an error. But is it somehow possible to get the existing sd card that was declared in boot.py?

Currently using an esp32 ai thinker camera board.
Background is that I would like to deinit the SD card in main.py and then use the pins for sth else and once that's done init the sd card again.

Code: Select all


# in boot.py
>>> sd = machine.SDCard(slot=1, width=1)

# in main.py (would like to deinit the sd card)
>>> sd = machine.SDCard(slot=1, width=1)
OSError: (-259, 'ESP_ERR_INVALID_STATE')

Thanks a lot in advance,

Lorenz

Re: sd card init in boot.py, sd card deinit in main.py - possible?

Posted: Wed Jan 27, 2021 6:56 pm
by dhylands
Variables delcared in boot.py are available inside main.py.

So you can just access "sd".

The same goes for modules imported in boot.py are already imported when main.py executes.

Re: sd card init in boot.py, sd card deinit in main.py - possible?

Posted: Sat Feb 06, 2021 11:57 pm
by lorenz
dhylands wrote:
Wed Jan 27, 2021 6:56 pm
Variables delcared in boot.py are available inside main.py.

So you can just access "sd".

The same goes for modules imported in boot.py are already imported when main.py executes.
Thanks for that. I will try it out.