I hope this is the correct place to ask this question. I think I have a code problem, rather than a hardware problem. I am trying to write the input of an analog pin to a .csv file, once per second. I am using an Arduino Uno with the Wireless SD shield, writing to a 1GB micro SD card formatted to FAT16.
The problem is that it writes several files, and then just seems to stop. The number of files it writes each time is not consistent ... so it is difficult to diagnose the exact problem.
I am quite new to coding, and to the Aduino in particular so it is most likely that I have made an obvious error. I have spent many days going over it and I can not think of any other way to fix it. Perhaps a more experienced person can spot my mistake?
The code is intended to: Create a temporary string composed of 5 readings from the analog 0 pin, each spaced 1 second apart, each separated by line feed. (Add a timestamp to each line if the RTC is attached). Write that string to two files; "mainfile" and another file with a dynamically assigned file name. Reset the string to empty, and repeat.
It is taking the voltage reading of a GSR sensor which is plugged into analog 0. The project is intended to allow the Arduino to be powered from a battery and worn all day while readings are taken every second and recorded to SD card. It is writing to two files because sometimes the files seem to get corrupted if power is removed during the write process. The "mainfile" is a continuous record of the data. In case this single massive file gets corrupted, the series of backup files contain the same data spread over many files. The series of backup files are called "split file" in the code. Currently each file is composed of only one file write (but this can be adjusted), and then a new file is created, and so on. (At the moment each file consists of only 5 seconds worth of data, but that will be adjusted to about 5 mins when it is working properly). The file name for each "split file" is composed of a single letter followed by a 7 digit number, and each file is named sequentially, for example, "A0000001", "A0000002", "A0000003", etc.
It seems to be correctly writing data to the file for the first few rounds, but eventually it stops. It seems to stop most often at split file number 9 or 26.
In addition it seems to go wrong when I plug the RTC in. I DID have the RTC working correctly, but now when I plug it in, the data which is written to the file just comes out as random characters (squares, currency signs, symbols, etc.). I had no idea why it is doing that, because I can't remember changing anything to cause it to happen!
Can anyone see if there is something majorly wrong that I am doing in the code?
(I will post the code in the next post, because I have run out of characters here).