1

I know it's possible to hook up multiple SPI devices, but how can one access the second drive from a sketch?

Looking at the SDWebServer.ino example, my doubt is with the SD.begin(SS); part. If I call begin() again with the other CS pin, it seems that I would lose a reference to my first volume, or maybe it won't work at all. I would instantiate another SD instance, but the sketch never seems to instantiate that object, it first appears in setup() with SD.begin(SS);

If I copy the lib (sd.h+sd.cpp) and replace all literal instances of SD with SD2, can I then include and use SD2 just like the original (provided the different .begin(pin))? Is there a less hacky way of using two SD cards in ESP8266 Arduino?

In case anyone's wondering, it's for a crypto project where one card will contain one-time-pads of plaintext length and the other contains the XOR'd ciphertext, both are fed by wifi upload, and the max file size must be bigger than SPIFFS, so I really need two SD cards...

dda
1,5951 gold badge12 silver badges17 bronze badges
asked May 22, 2018 at 6:38
2
  • 2
    Can't you just create another instance of SDClass SD2 in the sketch? Commented May 22, 2018 at 8:17
  • 2
    and of course choose a different pin for slave select signal Commented May 22, 2018 at 8:23

2 Answers 2

1

Not possible without changing the library code. Because the current library code is written intended for only one SD card, ie not intended for multiple SD cards because it will be complicated to do so. The SPI library also uses FatFS library, which is a bottleneck in this scenario.

Worth a try.

sdfatlib is library written for Arduino. I have never used it, but you can give a try on ESP.

Let us know if it works.

dda
1,5951 gold badge12 silver badges17 bronze badges
answered May 22, 2018 at 17:09
0

You should (I have not tested it) be able to do it if the library is well coded and doesn't use global variables and you do something like this:

// Don't know what the class name is so replace TYPE with what it should be.
TYPE SDCardOne;
TYPE SDCardTwo;
SDCardOne.begin(CS1);
SDCardTwo.begin(CS2);
....
Juraj
18.3k4 gold badges31 silver badges49 bronze badges
answered May 22, 2018 at 11:52
2
  • Thanks for the edit Juraj, it makes a lot more sense now :) Commented May 23, 2018 at 10:35
  • Unfortunately, standard SD.h library is designed as a singleton, so the sketch code does not instantiate card interfaces, as @Devidas pointed out in another answer Commented Nov 10, 2018 at 6:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.