the table is not displaying updated data , processing ide recieved parsed values
import processing.serial.*;
import java.util.ArrayList;
Serial myPort; // Create a Serial object
Table dataTable; // A table to store the data
void setup() {
size(400, 400); // Set the canvas size
myPort = new Serial(this, "COM3", 9600); // Replace "COM3" with your Arduino's port
// Create a new table with headers
dataTable = new Table();
dataTable.addColumn("Voltage (V)");
dataTable.addColumn("Strain");
dataTable.addColumn("Stress (MPa)");
}
void draw() {
background(255); // Clear the background
// Display table data
textAlign(LEFT, TOP);
fill(0);
text("Data Table:", 20, 20);
while (myPort.available() > 0) {
String data = myPort.readStringUntil('\n');
if (data != null) {
println(data);
String[] dataValues = data.trim().split(",");
if (dataValues.length == 3) {
float voltage = float(dataValues[0]);
float strain = float(dataValues[1]);
float stress = float(dataValues[2]);
// Store the values in the table
TableRow newRow = dataTable.addRow();
newRow.setFloat("Voltage (V)", voltage);
newRow.setFloat("Strain", strain);
newRow.setFloat("Stress (MPa)", stress);
} else {
println("Invalid data format: " + data);
}
}
}
// Display the table
displayTable(dataTable, 20, 40);
}
// Function to display a table
void displayTable(Table table, float x, float y) {
float lineHeight = 20; // Height of each row
float tableWidth = 300; // Width of the table
// Display headers
for (int i = 0; i < table.getColumnCount(); i++) {
text(table.getColumnTitle(i), x + i * tableWidth / table.getColumnCount(), y);
}
// Display rows
for (int i = 0; i < table.getRowCount(); i++) {
TableRow row = table.getRow(i);
for (int j = 0; j < table.getColumnCount(); j++) {
text(row.getFloat(j), x + j * tableWidth / table.getColumnCount(), y + (i + 1) * lineHeight);
}
}
}
glv
2
This is what to expect with the data you are sending:
Try to modify the data you are sending so that the string can be converting to a float:
:)
thank you for reply , so i have to declare for every string data for new values ?
import processing.serial.*;
import java.util.ArrayList;
Serial myPort; // Create a Serial object
Table dataTable; // A table to store the data
void setup() {
size(400, 400); // Set the canvas size
myPort = new Serial(this, "COM3", 9600); // Replace "COM3" with your Arduino's port
// Create a new table with headers
dataTable = new Table();
dataTable.addColumn("Voltage (V)");
dataTable.addColumn("Strain");
dataTable.addColumn("Stress (MPa)");
}
void draw() {
background(255); // Clear the background
// Display table data
textAlign(LEFT, TOP);
fill(0);
text("Data Table:", 20, 20);
while (myPort.available() > 0) {
String data = myPort.readStringUntil('\n');
if (data != null) {
println(data);
String[] dataValues = data.trim().split(",");
if (dataValues.length == 3) {
float voltage = float(dataValues[0]);
float strain = float(dataValues[1]);
float stress = float(dataValues[2]);
// Store the values in the table
TableRow newRow = dataTable.addRow();
newRow.setFloat("Voltage (V)", voltage);
newRow.setFloat("Strain", strain);
newRow.setFloat("Stress (MPa)", stress);
} else {
println("Invalid data format: " + data);
}
}
}
// Display the table
displayTable(dataTable, 20, 40);
}
// Function to display a table
void displayTable(Table table, float x, float y) {
float lineHeight = 20; // Height of each row
float tableWidth = 300; // Width of the table
// Display headers
for (int i = 0; i < table.getColumnCount(); i++) {
text(table.getColumnTitle(i), x + i * tableWidth / table.getColumnCount(), y);
}
// Display rows
for (int i = 0; i < table.getRowCount(); i++) {
TableRow row = table.getRow(i);
for (int j = 0; j < table.getColumnCount(); j++) {
text(row.getFloat(j), x + j * tableWidth / table.getColumnCount(), y + (i + 1) * lineHeight);
}
}
}
i adjust code but still table not displaying data , please can you see this
please how can i save table as excel . this is confusing
Hi @kusspuss,
You can use the saveTable()
function to write the content of a Table
object to a .csv
file which can be natively read by Excel.
2 Likes