Main Site Documentation

Can't figure out how to read/write file on SD card


I posted my code here, please help

Basically, I write_file() something into a file (sd\hello.txt). i can read_file() the same file to get its contents.

But then after I restart, read_file() reads . It seems that everything has been wiped out of the sd card.


I put Thread.Sleep(15000); between FlushAll() and UnmountFileSystem(). Still the same phenomenon.

sorry for the code on, i will clean it up once the problem is solved :-[


Try putting a sleep after the flush; give it time to complete.



the is not a pastebin. Please post your code here or use

Keep clean please.



I’m also noticing you’re doing volume[0] which may not be the SD card if, for example, you have a USB drive plugged in, etc. Try getting the correct voulme for the SD off RemovableMediaInsert. And when flushing cycle through all drives.


Here is the output window showing:

Files available on \SD:

test 1
test 1
end of session

then i restart, the output window still shows the same thing:

Files available on \SD:
(* should be test 1, which should be written in the file last time *)
test 1
test 1
end of session


@ iammegatron I agree with Eric the code site is not the place to ask code related questions. You are the first who ever did that. Not cool. Let the code site serve the purpose it was created for.

I would remove that entry. You can always put you driver/application/example back once it is working and worth sharing.