# The table is not displaying updated data

**URL:** <https://discourse.processing.org/t/the-table-is-not-displaying-updated-data/42931>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [October 9, 2023, 7:48pm UTC](https://discourse.processing.org/t/the-table-is-not-displaying-updated-data/42931 "2023-10-09T19:48:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kusspuss](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@kusspuss](https://discourse.processing.org/u/kusspuss)\
**Post date:** [October 9, 2023, 7:48pm UTC](https://discourse.processing.org/t/the-table-is-not-displaying-updated-data/42931/1 "2023-10-09T19:48:34Z")

</div>

the table is not displaying updated data , processing ide recieved parsed values

```auto
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);
    }
  }
}

```

 ![Capture](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/2/b/2b37b60f9b2f56138d9abdf232cac8ed69907b1c.png)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [October 9, 2023, 8:04pm UTC](https://discourse.processing.org/t/the-table-is-not-displaying-updated-data/42931/2 "2023-10-09T20:04:21Z")

</div>

This is what to expect with the data you are sending:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/8/68095853a1f545349620e383803c4804fb2cf24b.png)

Try to modify the data you are sending so that the string can be converting to a float:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/4/6/461383ef931f655a96c5bb94e8c49f64764b50f1.png)

`:)`

---

<div class="post-metadata">

**Author:** ![kusspuss](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@kusspuss](https://discourse.processing.org/u/kusspuss)\
**Post date:** [October 9, 2023, 8:32pm UTC](https://discourse.processing.org/t/the-table-is-not-displaying-updated-data/42931/3 "2023-10-09T20:32:47Z")

</div>

thank you for reply , so i have to declare for every string data for new values ?

---

<div class="post-metadata">

**Author:** ![kusspuss](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@kusspuss](https://discourse.processing.org/u/kusspuss)\
**Post date:** [October 11, 2023, 8:34am UTC](https://discourse.processing.org/t/the-table-is-not-displaying-updated-data/42931/4 "2023-10-11T08:34:58Z")

</div>

> [@glv](#):
>
> Try to modify the data you are sending so that the string can be converting to a float:

```auto
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

---

<div class="post-metadata">

**Author:** ![kusspuss](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@kusspuss](https://discourse.processing.org/u/kusspuss)\
**Post date:** [October 11, 2023, 9:08am UTC](https://discourse.processing.org/t/the-table-is-not-displaying-updated-data/42931/5 "2023-10-11T09:08:07Z")

</div>

![Capture](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/a/6/a6da97d63baf3f3956899d1c6c518564677cd2fc.png)

---

<div class="post-metadata">

**Author:** ![kusspuss](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@kusspuss](https://discourse.processing.org/u/kusspuss)\
**Post date:** [October 11, 2023, 10:11am UTC](https://discourse.processing.org/t/the-table-is-not-displaying-updated-data/42931/6 "2023-10-11T10:11:41Z")

</div>

please how can i save table as excel . this is confusing

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [October 11, 2023, 1:09pm UTC](https://discourse.processing.org/t/the-table-is-not-displaying-updated-data/42931/7 "2023-10-11T13:09:00Z")

</div>

Hi @kusspuss,

You can use the [`saveTable()`](https://processing.org/reference/saveTable_.html) function to write the content of a `Table` object to a `.csv` file which can be natively read by Excel.
