Go Down

Topic: How to log data to a file from arduino (Read 1 time) previous topic - next topic


I have been trying to use processing to log data to a file,but all i could get is an empty file,the code is here below.Is there a smart way of overcoming it.
import processing.serial.*;
Serial mySerial;
PrintWriter output;
void setup() {
   mySerial = new Serial( this, Serial.list()[0], 9600 );
   output = createWriter( "timedg.csv" );
void draw() {
    if (mySerial.available() > 0 ) {
         String value = mySerial.readString();
         if ( value != null ) {
              output.println( value );



Does that code work on an Arduino? It doesn't look like it.

What code is running on the Arduino? How is it sending serial data?

Why is the print statement that demonstrates that something was read from the serial port commented out?

What do you expect readString() to use to define the end of the string?
The art of getting good answers lies in asking good questions.


That stuff looks completely alien, so I submit you have been badly advised, or are on the wrong forum. If you really want to work with Arduino, one of the beauties of it is that there are basic sketches that do what you want already available.

FWIW, I don't think you can actually record from the IDE serial monitor, it is just for debugging. The way I see it, you have two options, both of which are in the standard examples, I'm sure.

1. If your Arduino operates tied to your PC by USB cable,  the simplest "Hello world!" loop will prove the point.  Al you need is a freebie terminal programme like RealTerm which will receive the signal and write it to a .csv. The serial monitor must be off in order to do this, but you see it all on the screeen anyway.

2. If it is standing alone, you need a recording medium - the SD card and the appropriate few lines of code to write the same "Hello world!" to it.

Either way, these options have to be simpler than what you're trying to do and indeed, if that is supposed to be Arduino code, what I suspect you are trying to do is re-invent the wheel.

Once you have that sorted, it is a simple matter to log your more serious data in the same way. You might find the freebie PLX-DAQ system really useful.


I need an example sketch of how you can create a file and write to it.I have an arduino UNO at the moment so i cant write to an SD card because i even don't have anything like a shield to interface it with arduino.Therefore an example will be more appeasing as am still a newbie  looking for a way of writing data from arduino to a file.


Are you using the standard Arduino IDE? If not, desist from whatever you are using and install the proper Arduino IDE immediately.
Therein, under Examples,  you will find a raft of examples, one of which, in the SD section, is a datalogger writing to (surprise!) the SD card.

Since you don't have an SD facility, you  might get some value from trying option 1. I described above.

Here is the code
Code: [Select]

void loop() {
  Serial.print("hello, world!       ");

Yes, that's it. Good luck, I'm not in a position to test it at the moment, but sure it will work


GoBetwino can log data to a file from your Arduino, if you are running windows


I need an example sketch of how you can create a file and write to it.

Processing comes with examples, too. Click on Fil + Examples... Under the Topics node, there is File I/O, with 7 examples.

We still don't know what your Arduino code looks like.
The art of getting good answers lies in asking good questions.

Go Up