I would like to use with Arduino Mega the sd slot on the ethernet shield to log events, and another sd shield to log differents datas. Both shields work fine separately, but I can't use them together.
So, first I would like to know if it's possible... I think yes because they use SPI bus and two differents CS pin. But how manipulate the SD library? I tried to create two instances of SD library and it doesn't seem to work.
I finally downloaded the library from GitHub - adafruit/SD: fixes & updates to the Arduino SD library - totally in progress. works but in beta.
Indeed, you have to make changes to the class to support multiple instances, but just one at the line 453 in SD.cpp.
I replaced if ( ! file.open(SD.root, filepath, mode)) by if ( ! file.open(root, filepath, mode))
I don't understand why the SD object is used in the class...
It seems to works fine now.
You just need to edit SdFatConfig.h and change this line. Set USE_MULTIPLE_CARDS nonzero:
/**
* To use multiple SD cards set USE_MULTIPLE_CARDS nonzero.
*
* Using multiple cards costs about 200 bytes of flash.
*
* Each card requires about 550 bytes of SRAM so use of a Mega is recommended.
*/
#define USE_MULTIPLE_CARDS 0
See TwoCards.ino in the examples folder for how to use two SdFat objects.
Ok, indeed I tried to compile on the Arduino IDE and it works fine.
But I noticed that I have to explicitly include the SdFat library in the ino file (and not through a header file). So I tried to do the same with Code:Blocks, and it works fine... (except for some warnings).
I don't know why we can't include arduino libraries through a header file ...?