Problem with Processing

Hi,

I'm a beginner of Arduino and processing so i have some problems.
Just for information I made an elevator and i need save the data as current over motor and speed, that Arduino read with an encoder, from arduino to a .txt file.

Well, as you can see i just realized a .pde file that save the rpm motor in a .txt file.

The real problem is that I need, also, save the data current in that, or another, file but i don't know how I can do because current is a float.

So what i need to do?

Thank you

PS rpm is an integer

rpm.pde (1.09 KB)

the code is also here:

import processing.serial.*;
Serial port;
PrintWriter output;

int rpmAv;

void setup() {
// Create a new file in the sketch directory
output = createWriter("rpmAv.txt");

// GO FIND THE ARDUINO
println(Serial.list()); // print a list of available serial ports
// choose the number between the [] that is connected to the Arduino
port = new Serial(this, Serial.list()[0], 9600); // make sure Arduino is talking serial at this baud rate
port.bufferUntil('\n'); // set buffer full flag on receipt of carriage return
}

void serialEvent(Serial port){
String inData = port.readStringUntil('\n');
inData = trim(inData); // cut off white space (carriage return)

rpmAv = int(inData); // convert the string to usable int
}

void draw() { // Could use void loop() here instead?
output.println(rpmAv); // Write the RPM to the file

}

void keyPressed() {
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}

I once made a sample sketch that saves two ';' seperated values per line in a csv file with a timestamp.
The datatype that generated the single fields does not matter, the text representation gets passed.

import processing.serial.*;
Serial mySerial;
PrintWriter output;
int lf = 10;    // Linefeed in ASCII
void setup() {
  printArray(Serial.list());
  mySerial = new Serial( this, Serial.list()[3], 115200 );
  output = createWriter( "log12.csv" );
  mySerial.bufferUntil(lf);
}
void draw() {
}
void serialEvent(Serial p) {
  String rStr = p.readString();
  if ( rStr != null ) {
    if (rStr.length() > 2) {
      String[] fld = splitTokens(rStr, ";");
      if (fld.length>=2) {
        output.print(year());
        output.print(".");
        output.print(month());
        output.print(".");
        output.print(day() );
        output.print("-");
        output.print(hour() );
        output.print(":");
        output.print(minute());
        output.print(":");
        output.print(second());
        output.print("-");
        output.print(millis());
        output.print(";");
        output.print(fld[0]);
        output.print(";");
        output.println(fld[1]);
      }
    }
  }
}
void keyPressed() {
  output.flush();  // Writes the remaining data to the file
  output.close();  // Finishes the file
  exit();  // Stops the program
}

Thank You :slight_smile:

later i'm gonna try this script.