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

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
lorenz
Posts: 8
Joined: Sat Dec 12, 2020 8:11 pm

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

Post by lorenz » Wed Jan 27, 2021 12:29 pm

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

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

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

Post by dhylands » 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.

lorenz
Posts: 8
Joined: Sat Dec 12, 2020 8:11 pm

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

Post by lorenz » Sat Feb 06, 2021 11:57 pm

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.

Post Reply