I'm working on a data logger for a racing sidecar. This will read various sensors and record the values to an SD card. I'm looking to record at a frequency of 10Hz.
I understand this is entirely doable using the SDFat library.
If I use the fastest method, I will need to use the binary logging method, this also means I will need to convert the file to a csv file once the data logging session is finished. The problem is that power could be cut to the Arduino at any time.
So, I need a way to detect that power has been lost, and a capacitor to keep the Arduino and SDCard module powered on long enough to convert the binary card into a csv file.
I am going to be powering the arduino from a buck converter, set to output 5V. So I could connect this to a digital pin, if this goes low I can deduce that the Arduino has lost power. Does this seem reasonable?
Then I guess I would need a capacitor to keep the Arduino powered long enough to write the unwritten data to the SD Card, and finalise the binary file. Any ide how long this would take, and what size of capacitor would be needed?
rickerman:
Then I guess I would need a capacitor to keep the Arduino powered long enough to write the unwritten data to the SD Card, and finalise the binary file. Any ide how long this would take, and what size of capacitor would be needed?
Who can tell, it would likley depend on what your software is actually doing.
Get the logger (or some test code) working and use a switch to simulate power down, then record how long it actually takes.
rickerman:
The problem is that power could be cut to the Arduino at any time.
I suppose that's true, no matter how much effort you put into making the supply robust. But in the interests of completeness, you have "robustified" the power supply haven't you ?
The power supply is a motorcycle 12V lead acid battery. Running in a racing sidecar. When you turn the "ignition" off, the power will be lost to the arduino.
I suppose it is possible I could take a feed directly from the battery, and use this when the ignition is off, but I don't want it to be powered all the time.
I will do some testing once my SD card module arrives. Once I have a time it should take to finish writing data to the card, how would I work out the value of capacitor that I need?
juma_yetu:
Ah I thought you were more concerned about accidental shutdown.
Could you include a powerDownIsImminent button to do an orderly shutdown including writing the final data?
Yes, I can do this. But there are times when it may be forgotten about, and the ignition just turned off. I want to make it so that we never loose any data, if possible.
Maybe you can restructure the way you handle the data.
Write small batches of raw data to the SD card as an when the data is collected. That means at power failure, only a small amount of data is vulnerable to loss.
Periodically, read the raw data from the SD card, convert it to a CSV file and, finally, delete the raw data.
Why does the in-car device have to format the data into a CSV?
Save it in raw format.
After the race, convert the data to the format of your choice on a process that is not dependent on race conditions.