Hey all,
I'm trying to create a data logger for a space bound rocket. I'm using an Arduino Mega, and the VDIP1 circuit to interface with USB. The code being used is based off Nick's code. In my current set up, I am using a potentiometer to create simple analog data. I am then reading the analog pin and storing that data onto the USB drive. Currently, I can get data to the drive, in an appropriate file, but all the data is on the same line. The carriage return is not working properly.
I've spent hours on end trying different things to fix the problem but have had no such luck. I'm hoping to find some good advice here.
Nick's code in its original form also put all the data in a single line.
Here's what I have for the actual data logging part:
if (incomingByte=='5')
{
Time=0; //restart counter
while (Time<=dataTime)
{
activityToLog='V'; // Letter to label data
valToWrite=analogRead(0); // read and store analog data
noOfChars=1; // reset number of characters to be written
x=valToWrite; // need to copy valToWrite as getting no of characters will consume it
while (x>= 10)
{ // counts the characters in the analog data
noOfChars++;
x/=10;
}
noOfChars +=2; // add 2 to the num as will also write the letter V and a return character
Serial.print("WRF "); // write to file (file needs to have been opened to write first)
Serial.print(noOfChars); // needs to then be told how many characters will be written
Serial.print(13, BYTE); // return to say command is finished
Serial.print(activityToLog); // followed by the info to write
Serial.print(valToWrite);
Serial.print(13, BYTE); // Return character for new line
Time++; // Add 1 to time counter
delay(500); // Delay .5s
}
}
Any help at all would be great. This is driving me nuts! :o
Thanks!