Open Draxiss314 opened 1 year ago
using your program as_is (albeit with SPI(0) and thus other pins assignments) works the 1st time and thereafter fails with: OSError: [Errno 1] EPERM
I found out some time ago that for reason not clear to me the program needs uos.umount("/sd") before terminating, if I want to run it again. I could not reproduce any corruption of the file or disk itself, as you experience it. So, creating the file, reading it back, opening the file on a pc, deleting the file and rerunning your pgm by Pico all works (with the unmount added).
Btw: I use 16GB sd cards; for some reason 32GB cards give repeatedly errors (card not detected, timeout).
(My setup is a WAVESHARE 2040_zero and for my test above I was running MicroPython v1.20.0-24-g867e4dd3d on 2023-04-27 but the results go back at least 4 months, so various v1.19.1 nightly builds.)
using your program as_is (albeit with SPI(0) and thus other pins assignments) works the 1st time and thereafter fails with: OSError: [Errno 1] EPERM
I found out some time ago that for reason not clear to me the program needs uos.umount("/sd") before terminating, if I want to run it again. I could not reproduce any corruption of the file or disk itself, as you experience it. So, creating the file, reading it back, opening the file on a pc, deleting the file and rerunning your pgm by Pico all works (with the unmount added).
Btw: I use 16GB sd cards; for some reason 32GB cards give repeatedly errors (card not detected, timeout).
(My setup is a WAVESHARE 2040_zero and for my test above I was running MicroPython v1.20.0-24-g867e4dd3d on 2023-04-27 but the results go back at least 4 months, so various v1.19.1 nightly builds.)
I completely reformatted and erased my MicroSD card, added the line uos.umount("/sd")
and got this error:
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
How do I check the version of MicroPython I'm running?
I get this line in the shell, but I don't have any of the numbers that follow it:
MicroPython v1.19.1 on 2022-06-18; Raspberry Pi Pico with RP2040
Okay, follow-up question: How do I update to a more recent version?
Okay, follow-up question: How do I update to a more recent version?
Get the new firmware from the Download page at https://micropython.org/download/rp2-pico/ and follow the short instruction.
Thank you. Okay, I'm updated to MicroPython v1.20.0 on 2023-04-26; Raspberry Pi Pico with RP2040
and I'm still getting this error:
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
I got it running under CircuitPython, so it's probably not an error inherent to the SD card.
To be clear, getting it working under CircuitPython doesn't mean it works under MicroPython. MicroPython's sdcard.py kind-of looks like a python version of CircuitPython's sdcardio.c, but I don't fully understand what I'm looking at.
what sdcard driver are you using ? This one I am using.
what sdcard driver are you using ? This one I am using.
That's the one.
I re-tested this with a Rp2040 "maker board" (the only other sdcard reader with an "authentic Raspberry Pi Pico I have available) icm an old version: MicroPython v1.19.1 on 2022-06-18. I used your code as well as the sdcard driver referenced in the link above. It works. That is: writing to the file, reading the file, putting the file in a W10 pc, accessing the file, deleting it and rerunning the program on the Pico.
Do not wish to push back on this problem but could there be any aspect specific to your configuration ? Perhaps Robert with all his experience has the insights to interprete the fact that it does work under CPython but not under MP.
Hard to say. For cross-check I have taken
and it works. I can repeat it dozen of times. Another test, which just writes a large file, works as well. It works as well with SCK set to 16MHz. Wiring with patch cables and breadboards is a common problem. SDCard.py is also very picky about SD card models, and it is a simple driver, which does not cover all possible states. Transcend cards usually work well, but I never tried a 2GB card.
Interesting thing to add: For me, since this was last written, (And thank you all for bringing up this issue, I just ran into it), I discovered that a 4GB microSD does not work (at least, it did not for me, yes it was FAT32 formatted with 1024-etc etc), but a 32GB right outta the box (was FAT32 formatted I suppose) worked just fine. Just leaving this little nugget of information for someone if they too got stuck by this. (Sorry if this was previously mentioned elsewhere)
Originally posted here, posted here as there's no response over on micropython-lib:
I am not able to consistently write to my microSD card using the sdcard.py library. EDIT/UPDATE: I'm running "MicroPython v1.20.0 on 2023-04-26." My errors still look like what I've written below.
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 to micropython-lib (and that the tutorial is slightly out-of-date) and copied over the sdcard.py code from micropython-lib 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.
These issues may (?) be replicated by following the steps I followed and using the SDcard.py code.
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
That is the expected output.
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: