ESP32 SDCard OSError: 16 #10581
-
Hi Community, Problem: My Device:
Pre-Analyse import os
import machine
sd = machine.SDCard(slot=2)
os.mount(sd, "/sd") # mount
os.listdir('/sd') # list directory contents Error-Msg (always the same, it doesn't matter if other code is commented out or not):
Looking into the world wide web, github issues and other discussions While I was reading I got the feeling that it has not something to do with the board directly. It looks like to me that the error is inside the ESP-IDF or there was a change in Micropython that was making that error existing? After reading some Issues, Documentation, Discussions and Tutorials I marked down the following links: *Note: tutorials excluded, because old solutions with a blob from @dpgeorge was used. But I found something similar of the blob here. **Issue 429 and 8940 maybe not related to this question, but I'm not very fimilar to ESP-IDF, so added them just in case. SD-Card Frequenz One try was to set a frequenz. -> Note: I'm using a 32GB SanDisk Ultra MicroSdCard. Question: Any Idea how this OSError: 16 is coming up? With these Information I wanted to ask here first, before opening a new issue. |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 18 replies
-
try this:-
However, I have had problems with slot=2 (and slot=3). If the code is re-run ,without pressing Stop in Thonny, I get
This can be repeated with a very very simple program:-
So, as long as your code runs immediately after a reboot it should run fine but it's a pig during development with REPL. It looks like a bug in "MicroPython v1.19.1 on 2022-06-18; ESP32 module with ESP32" to me. The SDCard isn't deleted properly when the program ends. I'm switching to a Pico & CircuitPython for my logger code, maybe I'll have more luck there. |
Beta Was this translation helpful? Give feedback.
-
Try:
The difference is in the mount command, where it uses the vfs as first argument. Besides that, sdcard.py is a little bit picky about SD card brand, layout & sizes. The card has to have a single FAT partition only, and I used it with cards in the size range from 8GB to 64GB, brands Samsung, Sandisk and Transcend. |
Beta Was this translation helpful? Give feedback.
-
How did you put micropython on your esp32 before?
Basically, use esptool. For doing it on Windows there's this tutorial
https://microcontrollerslab.com/flash-micropython-firmware-esptool-py-esp32-esp8266/#:~:text=The%20esptool.py%20tools%20can%20be%20used%20on%20Windows%2C,with%20ROM%20bootloader%20to%20flash%20and%20erase%20fimware.
One thought crossing my mind is 'have you connected the SD card CS,MOSI,MISO,SCK,GND,VCC" correctly?
On 01/02/2023 14:04:56, EngineerTrooper ***@***.***> wrote:
reflash the UF2
I haven't done this before. Would be my first time. How I do that with my ESP32 Dev Kit C V2 ?
The Internet shows some tutorials but do you have a specific way in mind, @BNNorman [https://github.com/BNNorman] ?
—
Reply to this email directly, view it on GitHub [#10581 (reply in thread)], or unsubscribe [https://github.com/notifications/unsubscribe-auth/ADY5NXJJIJ2H5COZBAFHQ6DWVJUQRANCNFSM6AAAAAAUFPDZ5Q].
You are receiving this because you were mentioned.Message ID: ***@***.***>
[14fcd5d4-d920-46ac-9234-f760a27f16c0]
|
Beta Was this translation helpful? Give feedback.
-
So I took a plain vanilla ESP32 NodeMCU type, similar to what you use. Firmware version:
Everything works fine. |
Beta Was this translation helpful? Give feedback.
-
Has the SD card hdw worked on another device? OR perhaps use Arduino IDE to flash an SD card test program? If you have another Dev Kit that would be more convenient.
Sorry to ask such basic questions, I'm running out of ideas and clutching at straws.
On 01/02/2023 14:25:37, EngineerTrooper ***@***.***> wrote:
How did you put micropython on your esp32 before? Basically, use esptool. For doing it on Windows there's this tutorial
I used esptool and also the commands in the tutorial. I reflashed fully the board yesterday to make sure it isn't corrupted. Also I tested v1.18, but error still comes up.
Also checked the pins twice or more times. If the cables aren't connected right I get error [0;31mE (120) sdmmc_sd: sdmmc_init_sd_if_cond: send_if_cond (1) returned 0x108[0m (I did that just to make sure everything is fine, and the hardware is connected correct.)
—
Reply to this email directly, view it on GitHub [#10581 (reply in thread)], or unsubscribe [https://github.com/notifications/unsubscribe-auth/ADY5NXMN5CX7RB7QUM7C4YDWVJW6BANCNFSM6AAAAAAUFPDZ5Q].
You are receiving this because you were mentioned.Message ID: ***@***.***>
[89fa8b53-407f-46e1-916f-228719903429]
|
Beta Was this translation helpful? Give feedback.
-
My friend was giving me a TTGO-Koala Esp32 Board. tested the following code: import os
import machine
sd = machine.SDCard(slot=2)
vfs=os.VfsFat(sd)
os.mount(vfs, "/sd") # mount
fn = open('/sd/textsd.txt', 'w')
fn.write('some data')
fn.close()
os.listdir('/sd') # list directory contents works like a charm! Thank you for your help and ideas. I think my ESP32 Dev Kit C V2 has a broken arm or leg... don't know. Time for a new one. I close this discussion as solved, now. |
Beta Was this translation helpful? Give feedback.
-
I've encountered a similar issue before; eventually, switching the power supply from 3.3V to 5V did the trick even though the SD card module specifications state that it supports 3.3V. |
Beta Was this translation helpful? Give feedback.
-
@
Advik
Not yet, I assumed it was a hardware failure in my board.
Lets see if someone solves it
Matheus Cafalchio, PhD
…On Sat, 20 Apr 2024 at 19:28, Brian ***@***.***> wrote:
Perhaps a large capacitor close to the SDcard VCC and GND might help. I
should have tried that before. Right now I can't test that idea.
—
Reply to this email directly, view it on GitHub
<#10581 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALI3WZB6YZZFQSKKUQ6FY6LY6KXVZAVCNFSM6AAAAAAUFPDZ5SVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TCNZVG4YTC>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
So I finally figured it out, MicroPython seems to only support unpartitioned sd cards, that is without any partition table, I also tried creating a partition table with only one primary partition but that didn't work. sudo mkfs.fat -F 32 /dev/sda |
Beta Was this translation helpful? Give feedback.
-
@advik Thank you very much for finding it.
I bet more people will come here to find it out.
Matheus Cafalchio, PhD
…On Sat, 20 Apr 2024 at 23:07, Advik ***@***.***> wrote:
So I finally figured it out, MicroPython seems to only support
*unpartitioned* sd cards, that is without any partition table, I also
tried creating a partition table with only one primary partition but that
didn't work.
If you're facing the same issue then you can format your card on linux
like this (change sda with the block device of your card, find it using
lsblk)
sudo mkfs.fat -F 32 /dev/sda
—
Reply to this email directly, view it on GitHub
<#10581 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALI3WZGTFLEKQ5BG67PYQ33Y6LRIHAVCNFSM6AAAAAAUFPDZ5SVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TCNZWGUYDS>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
I am also having this issue. I know it's not hardware related because I was able to get this to work using circuit python. |
Beta Was this translation helpful? Give feedback.
My friend was giving me a TTGO-Koala Esp32 Board.
With
MicroPython v1.18 on 2022-01-17; ESP32 module with ESP32
tested the following code:
works like a charm!
Thank you for your help and ideas. I think my ESP32 Dev Kit C V2 has a broken arm or leg... don't know. Time for a new one.
I close this discussion as solved, now.