Detecting an inserted SD card
-
Hi,
As
sd = SD()seems to blocking infinitely if no SD card is inserted I would love to know how I can detect if a SD card is inserted. -
This post is deleted! -
You would do it like this:
from machine import SD try: sd = SD() except: sd = None if sd: .... ....But if course, calling
SD()with no card inserted should not hang the board. I'll have a look at it and fix it. Thanks!Cheers,
Daniel -
@daniel
interesting - i have tested this before and this does not hang the board
Something was changed.But will be good to see some callback that someone plug/unplug SD
Is this somehow possible? I suppose that yes. -
But will be good to see some callback that someone plug/unplug SD
Is this somehow possible?Yes, it is. Card detection is simply done via a GPIO pin, so registering a callback on the card detection pin it's that is needed. Just note that on our Expansion Board there are no connections for the card detect signal, so it would have to be done with custom SD card hardware. In any case, in an embedded system, plugin the SD card in an out is not something that happens really often.
-
@kanu @livius I just test this and the behaviour is still as before. Trying to initialize the SD card without a SD inserted raises a OSError exception, which is OK.
@kanu which firmware version are you running and on which board? Do you have anything else connected to the SD card pins?
Cheers,
Daniel -
I just test this and the behaviour is still as before. Trying to initialize the SD card without a SD inserted raises a OSError exception, which is OK.
my English is bad and when i wrote
Something was changed.
than this was only assumption - i do not test this with current 1.6.3 firmware
i tested this on 1.5.0 and it worked - and if for @kanu it does not work
then i supposed that he tested this with current firmwareCard detection is simply done via a GPIO pin
good point - i must connect it :)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login