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

    Write to SD: OSError [Errno 5] EIO

    Scheduled Pinned Locked Moved Expansion Board
    sdcardwipyerrorlogmount
    7 Posts 3 Posters 2.1k Views 3 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.
    • E Offline
      Epstein
      last edited by Epstein

      Hi guys,

      I'm having some trouble writing to the SD card with my WiPy 2.0

      release='1.14.0.b1', version='v1.8.6-849-86da809
      

      I get the following error when i run the main.py:

      Traceback (most recent call last):
        File "<stdin>", line 73, in <module>
      OSError: [Errno 5] EIO
      

      Where line 73 represents:

      if SDcard == True:
          files = os.listdir('/sd')
          l = len(files)
          name = 'Datalog' + str(l+1)
          log = open('/sd/%s.csv' % name, 'wb') # line 73
      

      The SD card is fat32 (worked before) mounted in boot.py as follows:

      # boot.py -- run on boot-up
      from machine import SD
      import os
      
      try:
          sd = SD()
          os.mount(sd, '/sd')
          print('SD card mounted')
      except:
          print('No SD card inserted')
      

      Would appreciate any suggestions
      DISCLAIMER: Noob requesting some assistance

      p.s. when is a good time to unmount the SD? After the program is done?

      Thanks!

      robert-hhR D 2 Replies Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @Epstein
        last edited by

        @epstein I cannot replicate the error here. My release is 1.17.3.b1. What is the content of line 74?

        1 Reply Last reply Reply Quote 0
        • E Offline
          Epstein
          last edited by

          Hi Robert,

          Thanks for the reply and trying it out. That complete block is:

          if SDcard == True:
              try:
                  files = uos.listdir('/sd')
                  l = len(files)
                  name = 'Datalog' + str(l+1)
                  log = open('/sd/%s.csv' % name, 'w')
                  for T,P in zip(t,p):
                      log.write('{},{}\n'.format(T-t[0],P))   
                  log.close()                                
              except Exception as e:
                  print('Can not save data to SD card')
          

          With the exception implemented it does not throw a error. Just the print 'Can not save data to SD card'

          I've read something about pin assignments conflicting with the SD card pins These are the pins i use:

          ## Define i/o ADC & DAC
          hx = HX711('G9', 'G10')
          hx.tare()
          dac = DAC('P21')                # create a DAC object
          Button = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
          

          Could that throw me an error?: OSError [Errno] 5 EIO

          Thanks appreciate it!

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @Epstein
            last edited by

            @epstein G10 (P23) is used for the SD, as well as G11 (P4) and G15 (P8). Please refer to the Pinout diagrams. It may also be better to use either the Pxx or the Gxx numbering in a script, to avoid confusion. The Pxx numbers are those use in the module Pinout, the Gxx numbers are used in the expansion board Pinout, and it used to be the numbering used by the WiPy1 module.

            So, as young as Pycom is, it already has a legacy burden.

            E 1 Reply Last reply Reply Quote 1
            • D Offline
              DDA @Epstein
              last edited by

              @epstein
              I had quite a bit of trouble working with my SD card myself, I found the issue to be with how Windows formats the SD card in FAT32 mode.
              I tried this routine prior, which is have the Pycom module format the card instead:

              import os
              from machine import SD
              sd=SD()
              os.mount(sd,'/sd')
              os.mkfs(‘/sd')
              
              robert-hhR 1 Reply Last reply Reply Quote 1
              • E Offline
                Epstein @robert-hh
                last edited by

                @robert-hh Thanks, I think you are right.

                I think after Boot.py loads and it mounts the SD there is indeed no problem. However as soon as pin G10 is declared it conflicts when trying to call the SD.

                However i'm using a breakout board that needs the SDA and CLK on pin9 and pin10. Any suggestions a how i should go about?

                I think i could keep everything in ram and release pin10 before writing to SD.
                I have yet to test this (crude) strategy. Or does it have to be physically disconnected?

                Thanks again!

                1 Reply Last reply Reply Quote 0
                • robert-hhR Offline
                  robert-hh @DDA
                  last edited by

                  @dda Are you sure that you are not mixing up number schemes P and G? P9 and P10 are the default pins for SDA and SCA, and these are not used for the SD card.
                  Besides that, switching uses might be possible, but you would have to re-init and re-mount every time between each access. Better change the board.

                  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