Using two SD Cards on one MEGA

Is it possible to use two separate Micro SD readers for data logging on one Arduino mega? There is only one chip select pin 53 to use. Is it possible to connect two to that pin? Or is there another pin that I am not aware of?

Also, if they connect to the same pin, how would I go about coding that? Does the SD.h library support that?

you can choose any pin as CS.
you need to create a second SD object instance.
why do you need two SD cards?

Pin 53 is the cs pin for the Mega itself, which as an input would turn the Mega into a slave to some other master if made low by an external stimulus.

So to prevent that happening you need to make 53 an output. Then, since it's an output anyway, you might as well use it as cs for a device that is the Mega's slave.

But just because 53 is the Mega's cs pin does not mean you are obliged to use it as cs for any other device. The only requirement is to make it an output.

Juraj:
you can choose any pin as CS.
you need to create a second SD object instance.

Would I just need to setup both cards like this, and then read and write from each one like normal?

int chip1 = 53; //SD 1
int chip2 = 48; //SD 2
File mySensorData1;
File mySensorData2; 

void setup() {
  // put your setup code here, to run once:
   Serial.begin(9600);
   pinMode(chip1, OUTPUT);
   pinMode(chip2, OUTPUT);
   SD.begin(chip1);
   SD.begin(chip2);
}

Juraj:
why do you need two SD cards?

For a certain project, we want a back up SD card in the event one fails or something goes wrong.

ahayes24:
Would I just need to setup both cards like this, and then read and write from each one like normal?

int chip1 = 53; //SD 1

int chip2 = 48; //SD 2
File mySensorData1;
File mySensorData2;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(chip1, OUTPUT);
  pinMode(chip2, OUTPUT);
  SD.begin(chip1);
  SD.begin(chip2);
}




For a certain project, we want a back up SD card in the event one fails or something goes wrong.

Interesting project. Have you written the program that will determine when one card fails and you know to use the backup card?

Paul

I didn't really think about it like that. It's more like copying it to two separate SD Cards in the event that one doesn't work. We just want to be overly cautious.

you need

SD.begin(chip1);
SD2.begin(chip2);

but I don't know if SD2 would work