arduino + SD card Question

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

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

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.

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.

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

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

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 Arduino Playground - 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.

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?

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

do you think it is a good idea ?

thanks.

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?

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

analogValue0 = analogRead(0);

What are reading? Does the device use power from the Uno?

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

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?

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

Heater
Resistance
RH 31?±3? at Room Temp.

I think your CO meter may bring the total current usage up enough to cause you problems. This is just a guess. You could try disconnecting it and see if the problem goes away.

5v / 31ohms = 161ma

i will try.

thanks.

@cyclegadget: Thanks for covering for me. I was catching some of those great waves left over from tropical storm Debby. :slight_smile:

I think the CO sensor falls under one of my rules:
"If the user thinks it isn't important enough to include, it probably is."

Don't worry SurferTim, I will probably need your help if I ever get to working on my Ethernet shield. :slight_smile: