This is the tutorial that I have followed to make my first SD Card Related Program to work.
//SIMPLE WRITE AND READ
#include<SPI.h> //sd cARD USES spi bUS
#include<SD.h> //contains library functions
#define CSPIN 10 //slecting DPin-10 requires to set direction as output
File myFile; //file pointer variavle declaration
void setup()
{
Serial.begin(9600);
SD.begin(CSPIN); //SD Card is initialized
SD.remove("Test1.txt"); //remove any existing file with this name
myFile = SD.open("Test1.txt", FILE_WRITE); //file created and opened for writing
if(myFile) //file has really been opened
{
myFile.println("Arduino!"); //Arduino is written into SD Card
}
myFile = SD.open("Test1.txt", FILE_READ); //file created and opened for writing
if(myFile) //file has really been opened
{
while(myFile.available())
{
Serial.print((char)myFile.read()); //Arduino read back from SD Card and is shown on Monitor
}
myFile.close();
}
}
void loop()
{
}