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()
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:
Where is the "next data1"?['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
Why i always get a mistake in "next data8"?
What do I need to do to get stble connection to SD card?