Go Down

Topic: arduino + SD card Question (Read 2967 times) previous topic - next topic

a760109

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.
Code: [Select]

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);
}

SurferTim

I don't know if this is your problem, but my rule for files is if you open a file, you should close it.
Code: [Select]
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");
}

a760109

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.

SurferTim

#3
Jun 27, 2012, 02:24 pm Last Edit: Jun 27, 2012, 02:27 pm by SurferTim Reason: 1
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.


a760109

hi SurferTim

Code: [Select]

#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);
}

SurferTim

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?
Code: [Select]
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);
}


a760109

hi SurferTim
I use equipment list
Arduino Uno(http://arduino.cc/en/Main/ArduinoBoardUno/)
SD shield(http://www.seeedstudio.com/depot/sd-card-shield-p-492.html?cPath=109)
series two  3.7V 1100mAh battery(like http://arduino.cc/playground/Learning/9VBatteryAdapter)

I used USB to computer always success(not loss data to sd card)
but because some required i need go out
so i can't use serial monitor

thank very much.

SurferTim

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?

a760109

hi SurferTim
i touch regulator very hot
If the problem is that it..
how can i do ?

http://softsolder.com/2010/10/15/arduino-mega-voltage-regulator-heatsink/
do you think it is a good idea ?

thanks.

SurferTim

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?

a760109

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


cyclegadget

Quote
analogValue0 = analogRead(0);


What are reading?  Does the device use power from the Uno?
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

a760109

Yes , power from Uno  ,the device(sensor) also need 5V

cyclegadget

Quote
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?
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

a760109

in fact, i use Arduino Uno power support
CO sensor(MQ-7  http://probots.co.in/Datasheets/MQ7.pdf)
Humidity and Temperature Sensor(SHT15  http://www.emesystems.com/pdfs/parts/SHT15.pdf )

because can working at the beginning , so i think current enough

Go Up