Strange problems with SD card

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
ParaPashka
Posts: 4
Joined: Tue Apr 20, 2021 6:18 pm

Strange problems with SD card

Post by ParaPashka » Sun Apr 25, 2021 9:24 pm

Hello.
I have connected SD cardreader to a esp-wroom-32 using VSPI.
This is my simple test code:

Code: Select all

import machine, uos
uos.mount (machine.SDCard(slot = 2), "/sd")

print(uos.listdir('/'))
file = open('/sd/test.txt', 'w')
file.close()

for i in range(10):
    file = open('/sd/test.txt', 'a')
    file.write('\nnext data'+str(i))
    file.close()
    
file = open('/sd/test.txt', 'r')
print(file.read())
file.close()
The connection is very unstable.
Without any changes to hardware or software, just restarting the programm,
sometimes i get OSError: 16,
sometimes OSError: [Errno 19] ENODEV,
sometimes the SD is mounted. But then i get strange results when reading and writing to file. Here it is:
['sd', 'SDCard_test.py', 'boot.py', 'log.txt', 'sdcard.py', 'test.txt']

next data0
next data2
next data3
next data4
next data5
next data6
next data7
next da48
next data9
>>> %Run -c $EDITOR_CONTENT
['sd', 'SDCard_test.py', 'boot.py', 'log.txt', 'sdcard.py', 'test.txt']

next data0
next data2
next data3
next data4
next data5
next data6
next data7
next dat`8
next data9
>>> %Run -c $EDITOR_CONTENT
['sd', 'SDCard_test.py', 'boot.py', 'log.txt', 'sdcard.py', 'test.txt']

next data0
next data2
next data3
next data4
next data5
next data6
next data7
next da4!8
next data9
>>> %Run -c $EDITOR_CONTENT
['sd', 'SDCard_test.py', 'boot.py', 'log.txt', 'sdcard.py', 'test.txt']

next data0
next data2
next data3
next data4
next data5
next data6
next data7
next da0!8
next data9
Where is the "next data1"?
Why i always get a mistake in "next data8"?
What do I need to do to get stble connection to SD card?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Strange problems with SD card

Post by pythoncoder » Tue Apr 27, 2021 7:43 am

Could there be electrical issues? The interface runs at 40MHz so lead lengths need to be kept very short. Another option might be to try different SD cards. There have been issues with certain types of card.
Peter Hinch
Index to my micropython libraries.

Post Reply