Writing values to CSV file and some data is randomly shifting to another column.


I have a problem that when i leave my measuring station running for over a long period of time, the values are sometimes shifted in the middle of the data file - not in the right column. (see added picture of the file)

For example, I get 3 hours of normal data in the right columns, than the values shift a column to the right (or left), and I get these shifts in the file, just a couple of lines, and then the values go back to normal. Sometimes I lose one hour of data at that shift point and then the values get back again in the right columns for another 12h.

I am running SDfat library, and I have a switch that closes the file, before I remove the SD card.

I tried different code variations, but this seems to happen at random.

I am also adding the code (in attachment) that I am running on my arduino UNO, that has 3 different sensors and an LCD and this SD card slot shield.

Any help would be greatly appreciated. Thank you.

_3s_switch_Sdfat_noSerial.ino (6.53 KB)

No one?

Someone must have had this happen or can at least try to explain? :o

I tried changing the SD card but it still does this data shifts.

Thank you.

I can't see anything obvious wrong, but I'm suspicious of your interrupt routine. Can you get rid of the stuff in it regarding time and do it in the main loop instead?