Creating a table of sensor data from arduino?

Hi there, im pretty new to the processing application, so bear with my knowledge.
Ive got a mpu6050 reading out yaw ptich roll angles on the serial monitor on aurdino IDE, but i want to save the output to a .csv file. im using “,” to split the values. im also using table() to create a table and add the values split by “’,” to its own colum. The file is not being created?

code below:

import processing.serial.*;
Table table;
String val;
Serial myPort;
void setup()
{
String portName = "COM3";
myPort = new Serial(this, portName, 115200);
table = new Table();
table.addColumn("id");
table.addColumn("sensor1");
table.addColumn("sensor2");
table.addColumn("sensor3");
}

void serialEvent(Serial myPort){
val = myPort.readStringUntil('\n');
val = trim(val);
println(val);
float sensorVals[] = float(split(val, ','));

TableRow newRow = table.addRow();
newRow.setInt("id", table.lastRowIndex());
newRow.setFloat("sensor1", sensorVals[0]);
newRow.setFloat("sensor2", sensorVals[1]);
newRow.setFloat("sensor3", sensorVals[2]);

saveTable(table, "data/new.csv");
}
void draw()
{
//visualize your sensor data in real time here! In the future we hope to add some cool and useful graphic displays that can be tuned to different ranges of values.
}

arduino serial output:

Screenshot_1

1 Like

I tested your code using the code below and it worked. Are you sure you are receiving the data in your sketch? A quick test is to add println() in your code to check those values been saved. Another suggestion is to use serial.list()[?] where ? should be replaced with the com port you want to connect to.

Also, make sure the arduino is not talking to the serial monitor while you are trying to connect to your arduino unit.

Kf

Table table;

void setup() {

  table = new Table();  
  table.addColumn("id");
  table.addColumn("species");
  table.addColumn("name");

  frameRate(5);
}

void draw() {

  println("Current frameRate ", frameCount);

  if (frameCount==20) exit();

  TableRow newRow = table.addRow();
  newRow.setInt("id", table.getRowCount() - 1);
  newRow.setString("species", "Panthera leo");
  newRow.setString("name", "Lion");

  saveTable(table, "data/new.csv");
}
2 Likes

Thanks for the help @kfrajer i’ve managed to get it saving to a csv file :smile: