Go Down

Topic: SD Card and power "outage" (Read 1 time) previous topic - next topic

Brucez

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

PaulS

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.

Brucez


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.



PaulS

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.

Brucez


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.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview