###SOLVED###
Failed by design. To many open files
###/SOLVED###
I've wrote a measured value every 0.025 seconds to an sd card.
that works fine so far.
but after ~250 times (+/-25) it fails.
In SerialMonitor it fails e.g. after 266 writings, but the file has just written 237 times.
The loop() function is called in an endless loop. What purpose does it serve to create an infinite loop inside an infinite loop?
myFile.print(startTime, 4);
You want to print the time in base 4? Why? Seems a strange base to me...
Perhaps the thing you need to do is open the file once, then close it in the halt() function, rather than opening and closing the file every 25 milliseconds.
PaulS:
The loop() function is called in an endless loop. What purpose does it serve to create an infinite loop inside an infinite loop?
Yay, because
if (Serial.available()) //wenn daten am usb port ankommen
{
ch=Serial.read();
if(ch == 0)
{
halt();
}
else
{
startlogging();
}
}
}
just starts startlogging() just one time.
PaulS:
myFile.print(startTime, 4);
You want to print the time in base 4? Why? Seems a strange base to me...
This was just a bit playground. I just need a straight forward timeline
PaulS:
Perhaps the thing you need to do is open the file once, then close it in the halt() function, rather than opening and closing the file every 25 milliseconds.
if (myFile) {
myFile.print(startTime);
myFile.print(", ");
myFile.print(vout);
myFile.println();
// close the file:
//myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
i get "done" feedback in serial monitor for every print/write until it failed.
i'm guessing the library gets in trouble when to many files are opened !?
so i have to open the file one time in void.setup when start logging and close it in void.setup when stop logging. (not try yet, will do it soon)
but that would not explain why it fails in my first code version, where the file was opened and closed in every measure step.
so i have to open the file one time in void.setup when start logging and close it in void.setup when stop logging. (not try yet, will do it soon)
You could do it that way. I wouldn't. I'd open the file when the request came to start logging. I'd close it when the request came to stop logging.
yay, i was wrong with my explanation (bad english skills and interchanged void.setup and void.loop). i've meant just opening one time for logging and closing when stopping. however, like that way it seems to work now. but now i can't stop it anymore with 0 input on serial monitor.
How are you sending data to the Arduino? Sending a binary 0 seems like a strange thing to do.
startlogging() is incorrectly named, since it does not start the logging. The else clause is misplaced, now, since the file is not created in startlogging().
How are you sending data to the Arduino? Sending a binary 0 seems like a strange thing to do.
With ch=Serial.read();
and now with char ch = '0';
don't?
PaulS:
startlogging() is incorrectly named, since it does not start the logging.
O_o but it starts. that works fine. stopping don't work.
PaulS:
The else clause is misplaced, now, since the file is not created in startlogging().
i've created the file when checking for ch (serial.read).
and startlogging will just execute when ch get's something else, but not 0. and if ch is not 0, i've opened the file.