USB Data Logger

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!

Couple things to try, not sure if either will work, but:

Try using "\n" for a new line,

Serial.print("\n");

and try printing just 13:

Serial.print(13);

or(doubt this one will work):

Serial.write(13);

I'm guessing it'll be the top one, but haven't worked with the chip.

Best of luck. :slight_smile:

Thanks CaptainObvious I tried all of your suggestions (and other variations of them also) and still no luck!

I might just fall back on comma delimited if I need to. :-/

Serial.print("\r") or Serial.print("\n") should work.

(* jcl *)


www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks
blog: http://luciani.org

I actually just got it working with \r and \n, needed both.

Thanks so much! :smiley:

... all in one line ....

i think you opend the file on your computer. the editor you use do not support differnt kinds of "new line". the are some differnt way to make new line.

some editor do LF (lineFeed) and other CR (carrige return) and some do LFCR or CRLF or LFLF or LFLFCR

if you send your file to a serial port and connect a terminal-program link hyperterminal in windows, you can parameter the kind of line-end

LF is decimal 10
cr is decimal 13

can you send me info where i can get library and schematic to write to usb ? my 1st version with sd-card do not work really well

thanks

w. :slight_smile:

On the Arduino the USB port is connected to UART using an FTDI IC. To write
to the USB port you just write to the UART. For the Arduino use Serial.print
commands.

If you need a schematic for connecting the FTDI chip to an ATmega IC look int my NB1A datasheet at http://tinyurl.com/y8exe7k

(* jcl *)


www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks
blog: http://luciani.org