Need Help With Processing

Hello, i am fairly new when it comes to arduino and processing. I am having an issue getting a CSV file to populate with the data that is coming from arduino. How do I do I make it populate the CSV file?

I will provide both codes I am using below.

Arduino Code:

const int pwPin = 7; 
//variables needed to store values
long pulse, mm, cm;

int sensorVals[] = {0};

void setup() {

  //This opens up a serial connection to shoot the results back to the PC console
  Serial.begin(9600);
}

void loop() {

  pinMode(pwPin, INPUT);
    //Used to read in the pulse that is being sent by the MaxSonar device.
  //Pulse Width representation with a scale factor of 147 uS per Inch.

  pulse = pulseIn(pwPin, HIGH);
  //1uS per mm
  mm = pulse/1;
  //change mm to m
  cm = mm/10;
  Serial.print(mm);
  Serial.print("mm, ");
  Serial.print(cm);
  Serial.print("cm, ");
  Serial.println();
  delay(1);
}

Processing Code:

import processing.serial.*;
PrintWriter output;
Table table;

Serial myPort;  // Create object from Serial class
String val;     // Data received from the serial port
void setup(){
// I know that the first port in the serial list on my mac
// is Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[1]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600); 
 table = new Table();
  
  table.addColumn("id");
  table.addColumn("mm");
  table.addColumn("cm");
  
  TableRow newRow = table.addRow();
  newRow.setInt("id", table.lastRowIndex());
  newRow.setString("mm","Distance 1");
  newRow.setString("cm","Distance 2");
  
  saveTable(table, "data/new.csv");
}
void draw()
{
  if ( myPort.available() > 0) 
  {  // If data is available,
  val = myPort.readStringUntil('\n');         // read it and store it in val
println(val); //print it out in the console
}
}

Hi

From your description, I guess you want to merge your own code into the CSV processing code, right?

If cm and mm are the int value, try to add the following code

TableRow newRow = table.addRow();
newRow.setInt("id", table.lastRowIndex());
newRow.setInt("mm",mm);
newRow.setInt("cm","cm);

Once it all gets finished

call
saveTable(table, "data/new.csv");