Help needed with csv output coding

Hi, can anyone help me with the code to output data from a 5-axis IMU through an arduino board straight to a CSV file? I'm an absolute novice when it comes to coding and any help would be much appreciated.

Here's the coding so far

int xpin = 0;                   // x-axis of the accelerometer
int ypin = 1;                   // y-axis
int zpin = 2;                   // z-axis 
int xspin = 3;                  // x-axis rotation
int yspin = 4;                  // y-axis rotation

void setup()


void loop()


This is all in aid of my final year project which is based on car PCs and race data logging, I'll post a link for anyone interested after this post.

We'll need to know a lot more about the hardware you're using and how it's connected to the Arduino before we can help! Your initial code looks OK as far as writing out CSV format goes, though.

I'm using an Arduino Duelmilanove board with a SFE 3 axis accelerometer and 2 axis gyro with 500 deg/s combo. The accelermoters are wired into the analogue connections 0-2 and the x & y gyros wired into analogue 3&4; i'm using XP as my OS. Is that enough?

Are the serial ports on the PC and Arduino configured with the same settings ?

Yes, i've managed to get the data to display using the serial monitor so i know it works, I just don't know the code to send the data to a csv file.

I use a terminal application instead of the Arduino IDE. I think hyperterm has a "log to file" or "save to file" sort of option; most terminal emulation applications do.


Unfortunately I can't use a seperate program as the sensor is going to be amalgamted into a piece of software called Evoscan; I need to pre-program it to output to csv when it gets activated.

Any file that gets created will be created by an application running on your computer. the arduino can't create a file on your computer any more than your TV can; there's simply no facility in place to allow that to happen.

The arduino provides a bidirectional data stream on an RS232 port (aka COM port in windoze terminology).


I just released a program that might do the trick on the PC side:

But it is of course a stand alone application.


Maybe the programmers behind EVOSCAN can implement the CSV logging. It's kind of the only alternative to using another program.

The guy at Evoscan has given me a load of XML stuff to do, so i'll let you know what happens.

Hi. I have done this and it was easy with python. you need to install the pySerial module.

there is an example script (miniterm) for reading from the serial port which you can modify easily to write the incoming data to a file.

open a file for writing in the init section self.f=open('logfile.csv','w')

in the section def reader(self) you add a line self.f.write(something) directly beneath every place you see sys.stdout.write (something)

Wow, it's really neat that someone is doing this... I'm a fellow turbo mitsubishi owner (1991 Eagle Talon TSI actually :P)... I'm highly interested in what you're doing and I already thought of using my Duemilanove for such purposes... good to see that someone is already a step ahead. I will be following this thread as it is interesting to me... Keep us posted on your progress!

--Jonathan Dallas, TX