2

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...

  • 2
    Can't you just create another instance of SDClass SD2 in the sketch? – KIIV May 22 '18 at 8:17
  • 2
    and of course choose a different pin for slave select signal – Juraj May 22 '18 at 8:23
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);
....
  • Thanks for the edit Juraj, it makes a lot more sense now :) – Code Gorilla May 23 '18 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 – Maple Nov 10 '18 at 6:20
0

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.

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.