Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Detecting an inserted SD card

    Scheduled Pinned Locked Moved WiPy 2&3
    wipyhelpexpansionboardsdcard
    7 Posts 4 Posters 2.5k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      kanu
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • B Offline
        bucknall
        last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • D Offline
          daniel
          last edited by

          @kanu

          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

          L 1 Reply Last reply Reply Quote 1
          • L Offline
            livius @daniel
            last edited by

            @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.

            think about people first, then computers

            1 Reply Last reply Reply Quote 0
            • D Offline
              daniel
              last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • D Offline
                daniel
                last edited by

                @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

                L 1 Reply Last reply Reply Quote 0
                • L Offline
                  livius @daniel
                  last edited by livius

                  @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 firmware

                  Card detection is simply done via a GPIO pin

                  good point - i must connect it :)

                  think about people first, then computers

                  1 Reply Last reply Reply Quote 0

                  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
                  • 1 / 1
                  • First post
                    Last post

                  Pycom on Twitter

                  Pycom