Help sdcard recovery with arduino (I can see my files)

Hello, I have a dead micro SDHC card from my phone.

The card dimply died one day in my phone, it is no longer listed. On PC the same thing - card is not listed in device manager etc.

I tried the Cardinfo and was able to get file list!

But how to recover the files?
I read the site
I downloaded the

But I do not understand how to use it. If I try to upload the sd_recovery_files.ino to arduino, I I get one line of text “done!”

The sdrecovery (sd_recovery_files.ino) was not even uploading on arduino IDE 1.8.0, only on 1.8.5 it uploads without errors.

I downloaded RealTerm and can log the arduino output to file.
I downloaded the python for windows x68 and when I open the I get error:

How do I suppose to use this python thing?

Whenever I have accidentally damaged/formated a file system I have used photorec to recover them.

My card is not detected by PC itself, I cant use any PC software to recover.

The current problem making arduino spit the data to serial.

sd_recovery_files.ino makes it print text “done!” nothing else happens .

Do I need to change the 10 to 4 here? In cardinfo example:
"(const int chipSelect = 4;)" Such like is missing from sd_recovery_files.ino

void setup()
pinMode(10, OUTPUT);


root ="/");
readDirectory(root, “”);


It should not matter if your pc sees the card or not. Photorec does not use the partition table at all. It sees raw bits and guesses what type of file it is. I assume you are a windows user and with Windows it hides partitions from you even if Windows can actually see them. You can see this easily if you try and partition an extrernal drive with more than one partition, windows will hid all but the first partition. I say this because I believe photorec should still be able to recover the files even if windows does not admit it sees the drive. I am a linux user and we can see all drives/partitions regardless of their flagged state so I could be wrong on it still seeing it. If it doesn’t see it I would then download the Gparted live cd and put it on a bootable drive and try using the tools it includes to recover the sdcard.

I tried Active@ Partition Recovery and it does not see the card.

You have likely been bitten by a python2 to python3 feature. In python3 (which you likely have) you need print ("Name: " + name) same with the one below it (which it will complain about next) and any other print statements. I’d try downloading photorec and trying it. It is available for Windows and as Sublimeartistry said it ignores the file system which may or may not be what your problem is, it may be corrupted enough that the USB card readers can’t read it either in which case the arduino would be your only hope.


So if your card doesn’t register in the PC, what makes you think it will register with an Arduino?

Fire up a linux distro…

IE Debian or a spin off say Ubuntu
sudo fdisk -l
@sublimeartistry it does matter if the PC recognizes the card or not. See it could be recognized yet partition is bad. This is a recoverable situation. BUT from the sounds of it… THIS SD card is dead. That most likely means it’s beyond recovery :frowning:

USING fdisk, do you see the card listed??

If so you can also use
sudo testdisk
IF the disk registers, you can attempt to recover the partition…

You are wasting your time with that Arduino route. Why? I used to do data recovery for a living… IF the SD card is dead, well it’s dead. More time then its worth. What is the lesson? Take a backup of your files… OR be okay with loosing them. I will always suggest a good backup for anyone not doing it. If even monthly. You’ll surely loose less data.

Because unlike the PC or linux which access the card via USB (which looks to need a FAT file system) his Arduino solution is using spi to read individual blocks from the SD card. Doesn’t care about the fat file system. He already knows he can read at least some of the blocks (probably not all) on the Arduino, he just needs to get the data in to usable format via python. It may be easiest to find a python 2.7 version (or change
change the line




(which if both versions are in fact present may run 2.7 for him).


Realize all that… Infact, fiddled around with this on a bad card. On with my day. BUT I do wish you guys good luck playing around.

It should be educational about why proper backup procedures are useful :slight_smile: , but I think he is mostly there other than lack of experience with python. There seem to be tools available to recover the fat file system (or some of it) if spi will read the blocks.


I’d say if you have the time to put into figuring it out. DO IT! It’s always great to learn something new and come away with a win!! :smiley: :smiley:

If you do find success, make sure you post what you did for everyone. I’d be interested to hear the outcome. This could be very useful in certain situations. The card I tried, is just simply dead :frowning: I was hoping for a quick win myself.

Thank you for all the input.

Can anyone who is fluent with arduino make the files closed fix because I would not like to get stuck in middle of recovery the file is sd_recovery_files.ino
available at github in my first post
bug description

Thank you, this would be very helpful for everyone. So far I found nobody to fix the code, and I’m too stupid to do it myself.

I don’t think “too stupid” is accurate, more like “not experienced enough yet”. That said this may fix your problem:

void readDirectory(File dir, String folder) {
  boolean files = true;
  while(files) {
    File entry =  dir.openNextFile();
    if (! entry) {
      files = false;
    } else {
      if (entry.isDirectory()) {
        String folder_new = folder;
        folder_new +=;
        folder_new += "/";
        readDirectory(entry, folder_new);
      } else {
        outputFile(entry, folder);

The added entry.close() statements close the file handles after use which may help. The python code really does need python2 (or more work than I’m prepared to do right now) as there are more problems than just the brackets on print. I don’t have an Arduino ide up at the moment so I don’t know if this even compiles but it should. I think that once you get that “done” from the arduino you should see a stream of data from the arduino on the serial output console (assuming the SD card is in the reader when you load the sketch) the same as when you ran cardinfo.