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()
{
}
-
1Welcome 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– Anonymous Penguin2014年10月08日 00:37:02 +00:00Commented Oct 8, 2014 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– Chris Stratton2014年10月09日 19:49:33 +00:00Commented Oct 9, 2014 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– Ian M2014年10月10日 12:31:40 +00:00Commented Oct 10, 2014 at 12:31
-
Seems that last time I had this issue, simply replacing the battery on my datalogger board fixed the issueBackTracer– BackTracer2017年05月07日 16:25:02 +00:00Commented May 7, 2017 at 16:25
2 Answers 2
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?
-
1There is no "5v pin" on an SD card!!!Chris Stratton– Chris Stratton2015年05月15日 03:56:31 +00:00Commented May 15, 2015 at 3:56
-
@ChrisStratton There is a 5v pin on my sdcard moduleStephen York– Stephen York2019年04月15日 13:06:56 +00:00Commented Apr 15, 2019 at 13:06
-
Then the problem would be with some circuutry on the module which you have failed to.mentionChris Stratton– Chris Stratton2019年04月15日 13:42:03 +00:00Commented Apr 15, 2019 at 13:42
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– Chris Stratton2014年10月09日 19:49:00 +00:00Commented Oct 9, 2014 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– hobbs2014年10月09日 20:20:54 +00:00Commented Oct 9, 2014 at 20:20