Can I use two SD Cards on my Mega 2560?
One is in a TFT LCD module, and one will be in a datalogger module. Can I individually address and use each one for different things?
The one in the screen will only be being used to display pictures from, and the datalogger will log the various current weather conditions. The reason it is difficult to only use one is that I need to be reading and writing at "the same time" obviously NOT exactly the same time, but as close to the same time as possible as it is a high accuracy device that I am making.
I don't have code for the datalogging part yet, only the screen.
I don't know if you need the code for the screen or not, let me know if I'm wrong and I'll post it.
Be aware in your design that SD cards ONLY read and write in 512 byte buffers. Your program reads and writes are actually only using the current 512 byte buffers until they are emptied by reading or filled by writing. Just exactly like the old floppy disk logic.
Also make provisions to CLOSE the written files or the data will be lost.
@Paul_KD7HB
So it is possible to use two cards then?
Do I need different libraries for each card as they (obviously) can't both be on the same pins?
Someone else will have to answer that question.
Yes, you can
You can also use all the same pins except for the chip select pin, you will need one CS pin for each SD card.
Google "Arduino 2 SD cards"
The SPI article at Wikipedia has a diagram that shows very clearly that it's a bus. edit- removing this in the light of later posts below: That two (or more) devices are of the same type (SD cards in your case) is neither here nor there.

Not all libraries are written in such a way that they support multiple instances.
For example, they may use hardware resources like timers or other global resources or may actually instantiate themselves. If it is not clear, you have to do some careful testing.
@6v6gt
I am using the included SD library (the one that comes with the IDE)
OK. Here is an example from someone who appears to have done it: Arduino Project Hub Sorry now Dead Link.
The library does instantiate itself with the name SD, however, it appears to work somehow. Maybe it is because the begin() method clears any history so you can then work with the next SD card drive.
Yes, that's it.
It's slow because you have to close out the file you are working on and re-begin each card as well as swapping the cs pins.
It's much less than ideal.
So, the expanded answer is that OP can use both cards but not at the same time and generally the plan envisioned will not work.
It would be far better to use 1 SD card and 1 external RAM module. Along with some house cleaning stuff.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.