Unable to mound SD Card

  • Trying to write to a file on an SD card with LoPy4 connected to an expansion board.

    Used the following code:

    from machine import SD
    sd = SD()
    os.mount(sd, '/sd')

    and get the following error on the os.mount(sd,'/sd') command:

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    OSError: the requested operation is not possible

    The SD card is FAT32 formatted, 8GB. Reads and writes perfectly on my mac.
    I previously managed to read and write files on the SD card, but since rebooting the device no joy at all.

    Now what? Has anyone been succesful in using an sd card in the expansion board?

  • @robert-hh yes. FAT 32 with one partition. Kingston 8GB SD card straight out of the box.
    I did manage to write some files to it at some point but i think continuous mounting and resetting the board may have corrupted the SD card. Right now i can't even do os.listdir('/sd').

    I'll reformat the SD card and see what happens.

  • @robin error 5 is unspecific. Are you sure that you are using a FAT formatted card with exactly one partition?

  • @robert-hh said in Unable to mound SD Card:

    import os
    import machine

    sd = machine.SD()
    os.mount(sd, '/sd')

    Yep you're right, i was performing os.mount twice which was caught in my exception handler and led me to think that was the problem..

    however that leads to OSError: [Errno 5] EIO
    while doing file.write. Here is the offending line.

    with open('/sd/%s' % 'log.txt', 'a+ ') as file:


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

    Any clues what Errno 5 is or why its occuring?

  • @robin Sure, I made that just now. The commands are:

    import os
    import machine
    sd = machine.SD()
    os.mount(sd, '/sd')

    So besides the import os, which you not showed, it#s the same. That works however only after a hard reset (pushing the reset button).

Pycom on Twitter

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.