Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to write and read some data from SD card. I link SD card(LC STUDIO) to Arduino (UNO). I use this link for create my project. In first day I don't have any problem and data correctly save to file. But now my circuit isn't work nicely. When Arduino is running the sketch I don't saw any error message.But when I link the SD card to my laptop, I don't saw any file on card!! The code is here:

#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

File file;

void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ;
  }


  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);

  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
  }
  Serial.println("card initialized.");
  //creating file
  file = SD.open("test.txt",FILE_WRITE);
  file.close();
  //write data to file
  file = SD.open("test.txt",FILE_WRITE);
  if(file){
    file.println("OK!!");
    file.println("1");
    file.println("2");
    file.println("3");
    file.println("OK!!");
    file.close();
  }
}
void loop()
{
}
share|improve this question
    
Welcome to Arduino SE! Can you please add more information to your post? We can't help you much here. What have you tried? Has anything changed? – Anonymous Penguin Oct 8 '14 at 0:37
    
Try using one of the SD library examples unchanged (at least beyond making sure chip select, etc are correct) to verify the hardware before you modify it in other ways. – Chris Stratton Oct 9 '14 at 19:49
    
First, are you running the board off of USB power from your computer? If so, can you open the serial monitor to see if things are running correctly? If you aren't, the SD card can be picky if your board is running on battery, if the power drops, your SD card can no longer be written or read from. – Ian M Oct 10 '14 at 12:31

If there is no file on the card, you must first create the "test.txt" file and put it in the main directory of your SD card. Your code doesn't create a file and I don't think you can even do that with the SD library. If you want to create a file, you are going to have to use the SDfat library. Also take out this part of your code : file.close(); file = SD.open("test.txt",FILE_WRITE);

You are just opening, then closing, and then reopening.

share|improve this answer
    
Note that the poster's code isn't far from the SD library examples, so for example "Your code doesn't create a file and I don't think you can even do that with the SD library." is probably untrue. – Chris Stratton Oct 9 '14 at 19:49
    
"If the file is opened for writing, it will be created if it doesn't already exist" ­— documentation for SD.open – hobbs Oct 9 '14 at 20:20
up vote 0 down vote accepted

Thank you all... I found solution for my problem. The circuit and the sketch isn't any problem. But I saw this and I think problem is because of LC Studio's SD card. In previous circuit I connect 5v pin of SD card to 5v pin on arduino. But now I disconnect that and connect 3v3 pin on card to 3v3 on arduino. Now it's work very nice. And I don't know "why?" . Any idea?

share|improve this answer
    
There is no "5v pin" on an SD card!!! – Chris Stratton May 15 '15 at 3:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.