Offline
Newbie
Karma: 0
Posts: 20
|
 |
« on: June 27, 2012, 06:54:24 am » |
Hi everyone, I use Arduino uno + SD shield and use external power, save data in sd card but sometime I read SD card from PC , data write to SD card stop how can I solve the question ? Thanks. my code. void setup() { Serial.begin(9600); Serial.print("Initializing SD card..."); pinMode(10, OUTPUT); if (!SD.begin(10)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done.");
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) { Serial.print("Writing to test.txt..."); Serial.println("done."); } else { Serial.println("error opening test.txt"); }
myFile = SD.open("test.txt"); if (myFile) { Serial.println("test.txt:");
myFile.close(); } else { Serial.println("error opening test.txt"); } }
void loop() { myFile = SD.open("test.txt", FILE_WRITE); ...... myFile.print(temp, DEC); ...... myFile.close(); delay(1000); }
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #1 on: June 27, 2012, 07:02:07 am » |
I don't know if this is your problem, but my rule for files is if you open a file, you should close it. myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) { Serial.print("Writing to test.txt..."); Serial.println("done.");
// close the file here, just like below. myFile.close();
} else { Serial.println("error opening test.txt"); }
// with your sketch, myFile is still open from above myFile = SD.open("test.txt"); if (myFile) { Serial.println("test.txt:");
myFile.close(); } else { Serial.println("error opening test.txt"); }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #2 on: June 27, 2012, 07:14:19 am » |
hi my problem ,example.. i save data to SD card every second from Arduino if it operation 30 min ,i should get 600 data but i see SD card , maybe write 10min stopped so i lose after 10 minutes of data
thank.
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #3 on: June 27, 2012, 07:24:55 am » |
You should post your code. Your code above does not compile. No headers, no global variables, and my compiler does not like the "......" deal in the loop function.
Here are some of my other rules: If the user thinks it isn't important enough to include, it probably is. If the user says "don't worry about that", you probably should. If the user says "it is taken care of", it probably isn't.
|
|
|
|
« Last Edit: June 27, 2012, 07:27:16 am by SurferTim »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #4 on: June 27, 2012, 07:36:31 am » |
hi SurferTim #include <SD.h>
File myFile; int t;
void setup() { Serial.begin(9600); Serial.print("Initializing SD card..."); pinMode(10, OUTPUT); if (!SD.begin(10)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done.");
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) { Serial.print("Writing to test.txt..."); Serial.println("done."); myFile.close(); } else { Serial.println("error opening test.txt"); }
myFile = SD.open("test.txt"); if (myFile) { Serial.println("test.txt:"); myFile.close(); } else { Serial.println("error opening test.txt"); } }
void loop() { int analogValue0; t++; myFile = SD.open("test.txt", FILE_WRITE); analogValue0 = analogRead(0); myFile.print(t); myFile.print("\t"); myFile.println(analogValue0); myFile.close(); delay(1000); }
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #5 on: June 27, 2012, 07:51:28 am » |
What kind of equipment are we discussing? What Arduino and SD device are you using? And I would add some error checking. Change the loop to this, then upload and open the serial monitor. Does it still fail after 10 minutes? Does it always open the file? void loop() { int analogValue0; t++;
Serial.print("Open "); myFile = SD.open("test.txt", FILE_WRITE);
if(myFile) { analogValue0 = analogRead(0); myFile.print(t); myFile.print("\t"); myFile.println(analogValue0); myFile.close(); Serial.println("OK"); } else Serial.println("failed");
delay(1000); }
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #7 on: June 27, 2012, 08:25:26 am » |
OK. Now I see. It is a power supply challenge.
Have you checked the +5v on the Arduino after the fail? Is it still +5v? That sounds like an overtemp shutdown on the voltage regulator. Is the regulator getting really hot?
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #9 on: June 27, 2012, 08:58:49 am » |
Did you monitor the +5v pin on the Arduino during the test?
I would try a check to see if that is it. Remove the SD shield and run the blink example on the batteries. Does it fail after 10 minutes? Does the regulator still get as hot?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #10 on: June 27, 2012, 11:42:49 am » |
hi I try Remove SD card and add LED blink for some time , regulator sill hot , LED alway working the Arduino out 5V pin , I monitor about 4.5V
|
|
|
|
|
Logged
|
|
|
|
|
Greenville, IL
Offline
Edison Member
Karma: 11
Posts: 1288
Warning Novice on board! 0 to 1 chance of errors!
|
 |
« Reply #11 on: June 27, 2012, 11:44:02 am » |
analogValue0 = analogRead(0); What are reading? Does the device use power from the Uno?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #12 on: June 27, 2012, 12:04:12 pm » |
Yes , power from Uno ,the device(sensor) also need 5V
|
|
|
|
|
Logged
|
|
|
|
|
Greenville, IL
Offline
Edison Member
Karma: 11
Posts: 1288
Warning Novice on board! 0 to 1 chance of errors!
|
 |
« Reply #13 on: June 27, 2012, 12:06:34 pm » |
Yes , power from Uno ,the device(sensor) also need 5V The device may need too much current for the Uno to supply. Can you tell us more about it or supply a datasheet?
|
|
|
|
|
Logged
|
|
|
|
|
|
|
|