Struggling to read/write to 2nd SD card

I have 2 SD cards wired up on a breadboard and connected to my WT-SC01.
Currently they are wired up to share the MISO/MOSI/CLK pins and they have separate CS pins.
SD1 is using pin 4
SD2 is using pin 12

(I am using the esp32-micro-sdcard library)
I begin my code by calling:

digitalWrite(4, HIGH);
digitalWrite(12, LOW);
SD.begin(4,xx,xx,xx);

Later down the track when I would like to stop read/write to SD1 and start writing to SD2 I call:

SD.end();
digitalWrite(4, LOW);
digitalWrite(12, HIGH);

SD.begin(12,xx,xx,xx);

It returns true and begins however when I write to SD again, It instead writes to SD1.
I would like to be able to switch between the 2 SD's

Hi @bartdabom

welcome to the arduino-Forum.

directly after registering you got a message presented to read this

you should take 20 minutes time to really read it.

After reading it RE-edit your posting through clicking on the pencil-icon below your post.

One of the quesions that you should answer is:
what is a

??
best regards Stefan

As far as i know, the CS pins on a SD card are active LOW, so it should be

// digitalWrite(4, LOW); // this is not needed initially since begin(4) calls this also
digitalWrite(12, HIGH);
SD.begin(4,xx,xx,xx);

and then

SD.end();  // this is probably not needed either
digitalWrite(4, HIGH);
// digitalWrite(12, LOW); // again not needed.

SD.begin(12,xx,xx,xx);

between every action you would like to perform, you should switch both CS pins if you are not calling begin(), but i think it may be better to have to different pointers to 2 different objects, rather than just to use 'SD'
regardless, the SD library will not switch the CS pin HIGH for you when it is done, and unless you call begin() you will need to switch it LOW manually also.

Thank you Deva this is very informative.
I found out that my 2nd SD reader is not actually working (It is a different model to my first) So first thing I will buy another functioning one.
I will also create a 2nd SD object like you say since that makes a lot of sense.

Cheers.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.