2

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()
{
}
  • 1
    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
  • Seems that last time I had this issue, simply replacing the battery on my datalogger board fixed the issue – BackTracer May 7 '17 at 16:25
1

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?

  • 1
    There is no "5v pin" on an SD card!!! – Chris Stratton May 15 '15 at 3:56
  • @ChrisStratton There is a 5v pin on my sdcard module – Stephen York Apr 15 at 13:06
  • Then the problem would be with some circuutry on the module which you have failed to.mention – Chris Stratton Apr 15 at 13:42
0

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.

  • 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

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.