Pages: [1] 2   Go Down
Author Topic: arduino + SD card Question  (Read 2415 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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 Offline
Faraday Member
**
Karma: 144
Posts: 5977
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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 Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Faraday Member
**
Karma: 144
Posts: 5977
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi SurferTim

Code:
#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 Offline
Faraday Member
**
Karma: 144
Posts: 5977
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5977
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5977
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
analogValue0 = analogRead(0);

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


Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1] 2   Go Up
Jump to: