Hi there,
I'm trying to log data to a csv-file on a SD-Card. When I open the file on my computer with an editor (tried different editors...) The file is corrupted. It contains all the data, some of the data or weird data, depending on how I wrote to the file. Generating the exact same content of the file is not generally repeatable. I tried different sketches, other people seemed to use successfully, and different libraries, but had no success so far.
First of all, some information about my project in general: I'd like to design a data logger to log the flight control data and accelerations of a remote controlled helicopter. Due to the higher writing speed, I log the data to EEPROM-Chips during the flight and copy the data to the SD-Card, afterwards. For very high resolutions, I can fly for only a couple of minutes. Therefore, I would like to land, store the data on the SD-Card , erase the EEPROM and take-off without restarting the Arduino. Thus, I need to close the file each time I finished writing to the SD-card.
Now about my issue: I would like to store some data (ints and floats) separated by ";" in a text-file. If I open the file on my PC, the editor shows random information and in the last row(s) of most files red highlighted \FF, @ and/or \00 several times. I suppose this is due to erroneous control characters. I reckon , file.close() should print a "end of file" to the file and open(filename) should remove it before printing new lines to the file. I tried to find some information by studying the SD-Library, but couldn't find anything. I couldn't find anyone else with this problem, so I assume there is a problem with my code or even more general (compiler, os, editor...).
At the end of the post, you can find some piece of example code. I chose the SD-Library provided by the Arduino-IDE, since I reckon this library should work most reliably. The sketch writes into several test files, using the functions file.print(), file.println() and file.write(). Furthermore I use "\r\n" and "\n" as control character for the end of a line. Reading the files on the serial terminal works fine. In the following, some examples of the output of some files, when I open them with gedit. The outputs of the other files is similar ot the examples given. If I open the file with nano (a terminal based editor), \00 is replaced by @. If I run the code several times, the number of \00 increases. test1.txt seems to be alright, if I open it after the first run. After a third run, it returns the output given in the third example, however the serial monitor returns the correct output.
Output test0.txt:
[Cached]
Size=9531
\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00
Output test3.txt:
15751
kio_trash
Laptop
\00\00\00\00\00\00
btw: Laptop is the name of my Computer;)
Output test1.txt after third run:
1;2;3;
1;2;3;
1;2;3;
1;2;3;
1;2;3;
1;2;3;
1;2;3;
1;2;3;
1;2;3;
1;2;3;
1;2
Can anyone point me in the right direction, please?