Pages: [1]   Go Down
Author Topic: SD Card and power "outage"  (Read 974 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All,

I'm about to write a sketch that writes sensor values to a file on an SD card in every second. I'd like to close/sync the file after every line to avoid dataloss when powering off.
My question is, how to avoid corrupting the file? The arduino will be shut down by pulling out the power chord. What if it happends in the wrong time, and the file on the card get corrupted? Any solution/idea?

Thanks!

Brucez
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46063
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What if it happends in the wrong time, and the file on the card get corrupted?
Turn a red LED on. Open the file, write to it, close the file. Turn the red LED off. Don't pull the power while the red LED is on.
Logged

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

Quote
What if it happends in the wrong time, and the file on the card get corrupted?
Turn a red LED on. Open the file, write to it, close the file. Turn the red LED off. Don't pull the power while the red LED is on.

Thanks, but as it will write in every second and will be powered by a vehicle I won't be able to check the led... Maybe I'll use some kind of conductor for a temporary powersource and will use a digital pin to check if the board is running on main power or on the backup power. The temporary power source should only keep up for 2-3 seconds.


Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46063
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Maybe I'll use some kind of conductor for a temporary powersource and will use a digital pin to check if the board is running on main power or on the backup power. The temporary power source should only keep up for 2-3 seconds.
I'm having a bit of difficulty imagining how that would work. But, if you can, and can figure out how to turn the temporary power source off when the Arduino can safely be powered off, go for it.
Logged

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

Quote
Maybe I'll use some kind of conductor for a temporary powersource and will use a digital pin to check if the board is running on main power or on the backup power. The temporary power source should only keep up for 2-3 seconds.
I'm having a bit of difficulty imagining how that would work. But, if you can, and can figure out how to turn the temporary power source off when the Arduino can safely be powered off, go for it.
Well, the temporary power source would be a capacitor. It would discharge in a few seconds, and it would be enough to finish the last write and skip the next write cycles until it shuts down.
Logged

Pages: [1]   Go Up
Jump to: