I want to copy an SD card to another.

What is the best way to attack this problem?

Should i get two sd card shields? If yes, is it possible to stack two together, or will there be problems with the interface protocols (SPI/I2C)?

  • 1
    Why would you want to do this with an Arduino when you can do it on a PC so easily?
    – Majenko
    Sep 29 '19 at 22:18
  • 1
    Because sometimes, a pc just isn't available. Sep 29 '19 at 22:27
  • 1
    Fair enough then.
    – Majenko
    Sep 29 '19 at 22:28

It should be perfectly possible to do it. As long as the SD cards and shields play ball then there should be no problem from a hardware perspective.

From a hardware perspective you should be able to share the MOSI, MISO and SCK lines and just have separate CS pins per card.

However some SD card shields employ level translation that doesn't properly release the SPI bus when idle, and some cheap SD cards don't release the bus in a timely manner too.

From a software perspective though it may be a different matter. I am not sure how well you can run two instances of the SD classes at once on an Arduino. You may be better off looking at FatFS instead which is far more flexible.

You have two strategies when copying cards, each of which has a different way of programming it.

  1. Block copy the entire card: this involves reading a 512 byte block from one card and writing it to the other one. This would be the most efficient from a resource perspective (you don't need to care about the contents of the card, so don't need any filesystem code), but if the card is not close to full it will be very inefficient from a runtime perspective. Also the two cards have to be the same size for it to work well.
  2. File copy. For this you need much more complex code, but it you only copy each file from one card to the other. It's much better though if the cards don't have much data on them - also the cards can be different sizes.
  • 2
    The time it takes to block-copy a complete "small" 16 GB SD-card via SPI is probably longer than finding a PC around :) Sep 30 '19 at 11:47
  • Maybe, if two arduinos - where each has an SD card shield, and they communicate somehow? Maybe this is a better choice? Oct 12 '19 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.