Write to SD: OSError [Errno 5] EIO



  • 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!



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



  • @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!



  • @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')
    


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



  • 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!



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



Pycom on Twitter