You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am not able to consistently write to my microSD card using the sdcard.py library.
I have been following this tutorial to get my Raspberry Pi Pico write to my SD card. As the requisite drivers are no longer available in the normal micropython branch, I assume that they've been moved here (and that the tutorial is slightly out-of-date) and copied over the sdcard.py code to my Pico.
I'm using a Raspberry Pi Pico with a Maker Pi breakout board. My IDE is Thonmy with the Micropython (Raspberry Pi Pico) interpreter. The SD card I use is a Transcend 2GB MicroSD Card, which I have formatted to be FAT32.
When I attempt to test my Pico's ability (see below for code) to read and write to the SD card, my results are inconsistent and frequently mangle the SD card's filing system, requiring me to reformat or repair the partition before I can access it from my computer. Here is a sample of my most recent results:
After having deleted all data from the SD card and subsequently repairing the card, my output acted as expected: Writing . . . Finished Writing. Reading . . . Hello, SD World! This is a test
Checking the SD card on my computer showed the expected result: a file called test01.txt containing Hello, SD World! This is a test and nothing else.
Returning the SD card to my Pico, I ran the test again with this result: Traceback (most recent call last): File "<stdin>", line 27, in <module> File "sdcard.py", line 252, in readblocks File "sdcard.py", line 190, in readinto OSError: timeout waiting for response
Checking the SD card on my computer, I found I could not mount it and had to repair the filesystem. After repairing, the data was garbled so I deleted it. Running the test again yielded this: Writing . . . Traceback (most recent call last): File "<stdin>", line 29, in <module> File "sdcard.py", line 252, in readblocks File "sdcard.py", line 190, in readinto OSError: timeout waiting for response
Again, filesystem must be repaired and data is garbled. After fixing and deleting: Writing . . . Traceback (most recent call last): File "<stdin>", line 34, in <module> File "sdcard.py", line 279, in writeblocks OSError: [Errno 5] EIO
I think the data was garbled again (can't remember precisely), but regardless I repaired and deleted everything and tried again with the same error. This time, however, my filesystem wasn't corrupted and I had a blank test01.txt file.
I've been dealing with this for a while now and these events represent the typical pattern of issues I've been having with this code. Any help explaining what's going on would be greatly appreciated.
This is the code that I am using to test being able to read/write to the SD card; it's very similar to the default but I've adjusted it to use the Maker Pi Pico board and added a few lines to tell me whether I'm reading or writing:
importmachineimportsdcardimportuosimportutime# Assign chip select (CS) pin (and start it high)cs=machine.Pin(15, machine.Pin.OUT) #It's 15 on the board we're using.# Intialize SPI peripheral (start with 1 MHz)spi=machine.SPI(1,
baudrate=1000000,
polarity=0,
phase=0,
bits=8,
firstbit=machine.SPI.MSB,
sck=machine.Pin(10),
mosi=machine.Pin(11),
miso=machine.Pin(12))
# Initialize SD cardsd=sdcard.SDCard(spi, cs)
# Mount filesystemvfs=uos.VfsFat(sd)
uos.mount(vfs, "/sd")
# Create a file and write something to itwithopen("/sd/test01.txt", "w") asfile:
print("Writing . . .")
file.write("Hello, SD World!\r\n")
#utime.sleep_ms(75)file.write("This is a test\r\n")
#utime.sleep_ms(75)file.close()
print("Finished Writing.")
# Open the file we just created and read from itwithopen("/sd/test01.txt", "r") asfile:
print("Reading . . . ")
data=file.read()
print(data)
file.close()
The text was updated successfully, but these errors were encountered:
Draxiss314
changed the title
Raspberry Pi Pico
Raspberry Pi Pico SD Card Errors
May 8, 2023
I know this is an old thread, but I was reading and wanted to ask if you had tried a different card. Getting EIO errors, sounds like the SD card might have a bad sector on it. I've has similar experiences with a USB stick on a raspberry pi 4, and it ended up being that the stick wasn't reliable when attempting to write any file from any source. Replacing the USB stick solved all problems.
I am not able to consistently write to my microSD card using the sdcard.py library.
I have been following this tutorial to get my Raspberry Pi Pico write to my SD card. As the requisite drivers are no longer available in the normal micropython branch, I assume that they've been moved here (and that the tutorial is slightly out-of-date) and copied over the sdcard.py code to my Pico.
I'm using a Raspberry Pi Pico with a Maker Pi breakout board. My IDE is Thonmy with the Micropython (Raspberry Pi Pico) interpreter. The SD card I use is a Transcend 2GB MicroSD Card, which I have formatted to be FAT32.
When I attempt to test my Pico's ability (see below for code) to read and write to the SD card, my results are inconsistent and frequently mangle the SD card's filing system, requiring me to reformat or repair the partition before I can access it from my computer. Here is a sample of my most recent results:
After having deleted all data from the SD card and subsequently repairing the card, my output acted as expected:
Writing . . .
Finished Writing.
Reading . . .
Hello, SD World!
This is a test
Checking the SD card on my computer showed the expected result: a file called test01.txt containing
Hello, SD World!
This is a test
and nothing else.
Returning the SD card to my Pico, I ran the test again with this result:
Traceback (most recent call last):
File "<stdin>", line 27, in <module>
File "sdcard.py", line 252, in readblocks
File "sdcard.py", line 190, in readinto
OSError: timeout waiting for response
Checking the SD card on my computer, I found I could not mount it and had to repair the filesystem. After repairing, the data was garbled so I deleted it. Running the test again yielded this:
Writing . . .
Traceback (most recent call last):
File "<stdin>", line 29, in <module>
File "sdcard.py", line 252, in readblocks
File "sdcard.py", line 190, in readinto
OSError: timeout waiting for response
Again, filesystem must be repaired and data is garbled. After fixing and deleting:
Writing . . .
Traceback (most recent call last):
File "<stdin>", line 34, in <module>
File "sdcard.py", line 279, in writeblocks
OSError: [Errno 5] EIO
I think the data was garbled again (can't remember precisely), but regardless I repaired and deleted everything and tried again with the same error. This time, however, my filesystem wasn't corrupted and I had a blank test01.txt file.
I've been dealing with this for a while now and these events represent the typical pattern of issues I've been having with this code. Any help explaining what's going on would be greatly appreciated.
This is the code that I am using to test being able to read/write to the SD card; it's very similar to the default but I've adjusted it to use the Maker Pi Pico board and added a few lines to tell me whether I'm reading or writing:
The text was updated successfully, but these errors were encountered: