# How to generate report?

**URL:** <https://discourse.processing.org/t/how-to-generate-report/10938>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [May 5, 2019, 11:13am UTC](https://discourse.processing.org/t/how-to-generate-report/10938 "2019-05-05T11:13:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![68jai90](https://avatars.discourse-cdn.com/v4/letter/6/77aa72/32.png) [@68jai90](https://discourse.processing.org/u/68jai90)\
**Post date:** [May 5, 2019, 11:13am UTC](https://discourse.processing.org/t/how-to-generate-report/10938/1 "2019-05-05T11:13:52Z")

</div>

Hi everyone,

I would like to know how to generate report using processing software based on values read from arduino.

The requirement for the report is to log every 5 minutes for 8 hours. and create new report file after finish the 8 hours.

The format must be in .csv.

is it possible?

Thank you  
Jai kumaran

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 5, 2019, 11:32am UTC](https://discourse.processing.org/t/how-to-generate-report/10938/2 "2019-05-05T11:32:39Z")

</div>

-a- make a table  
[https://processing.org/reference/Table.html](https://processing.org/reference/Table.html)  
-b- add the values  
[https://processing.org/reference/Table\_addRow\_.html](https://processing.org/reference/Table_addRow_.html)  
-c- save to csv ( on timer or keyPress )  
[https://processing.org/reference/saveTable\_.html](https://processing.org/reference/saveTable_.html)

example:

```auto
// v01 get CSV line // like: 1023,927,843,761,693,0,0 A0,1,2,3,4 D2,3
// v02 save to table

Table table;
String outfile = "data/arduino.csv";
/*
A0,A1,A2,A3,A4,D2,D3
1023,927,839,751,672,0,0
*/

import processing.serial.*;
Serial port;

String ports, inString;
String[] elements;
boolean diagp = true;//false;//true;
int baud = 115200; // 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 230400, 250000, 500000, 1000000, 2000000
boolean getrecord= false;
int many = 0, expect = 7, recs=0;
int[] values = new int[expect];
float zoom;

void setup() {
  size(300, 300);
  if ( diagp ) printArray(Serial.list());
  ports = Serial.list()[1];
  port = new Serial(this, ports, baud);
  port.bufferUntil('\n');
  stroke(0);
  zoom = (height-60)/1023.0;
  background(200, 200, 0);
  println("use \nkey [p] for diagnostic print\nkey [c] clear\nkey [s] save table");
  setup_table();
}

void draw() {
  if ( getrecord ) {
    getdata();
    stroke(200, 200, 0);
    line(recs, 0, recs, height); // the actual line is init with the background color first ( overwriting old graph ) 
    for (int i=0; i<expect; i++ ) { 
      float ypos = height-50 - values[i]*zoom;
      if ( i > 4 ) ypos = height-10*(i-4) - 5*values[i]; // for the digital vals
      if ( diagp ) println(" values ["+i+"] "+values[i]+" xpos "+recs+" ypos "+ypos);
      stroke(0, i*40, 200-i*40);
      point( recs, ypos ); // graph
    }
    recs++; // next pix xdir
    if ( recs > width ) recs = 0;
    stroke(255);
    line(recs, 0, recs, height); // and draw a white line ahead to show "cursor"
    stroke(200, 0, 0); // grid on cursor! analog
    for (int k=0; k<6; k++ ) line(recs, 10 + k*( height-60)/5, recs+3, 10 + k*( height-60)/5);
    stroke(0, 0, 200); // grid on cursor! digital
    for (int k=0; k<=3; k++ ) line(recs, height -10 - k*5, recs+5, height -10 - k*5);

    getrecord = false;
  }
}

void getdata() {
  if ( diagp ) println(inString);
  elements = splitTokens(inString, ","); // split and set some globals...
  int many = elements.length;
  if ( many >= expect ) {
    for (int i=0; i<expect; i++ ) { // convert the string to int only for the expected value list
      if ( diagp ) print(elements[i]+" , ");
      values[i] = int(elements[i]);
    }
    if ( diagp ) println();
    store_record();
  } else {
    println("com error, found short line:"+inString);
  }
}

void serialEvent(Serial thisport) { // read the serial buffer:
  inString = thisport.readString();
  if ( inString != null ) {
    inString = trim(inString); // clean
    getrecord = true;
  }
}

void keyPressed() {
  if ( key == 'p' ) println("diagp: "+(diagp = ! diagp));
  if ( key == 'c' ) background(200, 200, 0);
  if ( key == 's' ) { 
    saveTable(table, outfile);
    println("save to: "+outfile);
  }
}

void setup_table() {
  table = new Table();
  table.addColumn("A0");
  table.addColumn("A1");
  table.addColumn("A2");
  table.addColumn("A3");
  table.addColumn("A4");
  table.addColumn("D2");
  table.addColumn("D3");
}

void store_record() {
  TableRow newRow = table.addRow();
  for ( int c =0; c<7; c++) newRow.setInt(c, values[c]);
}

/*
// arduino code tested Arduino Leonardo Arduino IDE 1.8.9 hourly 
 
 String aline; // readable char line
 
 void make_aline() {
 aline = "";
 aline += analogRead(0);
 aline += ',';
 aline += analogRead(1);
 aline += ',';
 aline += analogRead(2);
 aline += ',';
 aline += analogRead(3);
 aline += ',';
 aline += analogRead(4);
 aline += ',';
 aline += digitalRead(2);
 aline += ',';
 aline += digitalRead(3);
 // ++ CR LF
 }
 
 int wait = 500;
 long baud = 115200; // 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 230400, 250000, 500000, 1000000, 2000000
 
 void setup() {
 Serial.begin(baud);
 while (!Serial) {
 ; // wait for serial port to connect. Needed for native USB port only ( arduino leonardo )
 }
 }
 
 void loop() {
 make_aline();
 Serial.println(aline);
 delay(wait);
 }
 
 */

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 5, 2019, 1:56pm UTC](https://discourse.processing.org/t/how-to-generate-report/10938/3 "2019-05-05T13:56:40Z")

</div>

here is a timer

```auto

int timer; 
int i;

void setup() {
  size(555, 555);
  background(0);
  timer = millis();
}

void draw() {
  background(0);

  if (millis()-timer > 1000) {
    timer = millis();
    i++;
  }
  text(i, 33, 33);
}//
//

```

---

<div class="post-metadata">

**Author:** ![68jai90](https://avatars.discourse-cdn.com/v4/letter/6/77aa72/32.png) [@68jai90](https://discourse.processing.org/u/68jai90)\
**Post date:** [May 7, 2019, 8:56am UTC](https://discourse.processing.org/t/how-to-generate-report/10938/4 "2019-05-07T08:56:29Z")

</div>

Hello kll,

Much appreciate your guide, will give a try asap

Thank you  
best regards

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [May 7, 2019, 5:04pm UTC](https://discourse.processing.org/t/how-to-generate-report/10938/5 "2019-05-07T17:04:41Z")

</div>

I provide links to other discussions relevant to your topic. It is important to manage IO operations inside draw/serial functions specially if you have higher event rates scenarios.

- [Saving serial data](https://forum.processing.org/one/topic/serial-data-writing-to-a-text-file.html)
- [Append data #1](https://forum.processing.org/two/discussion/20427/append-a-text-file)
- [Append data #2](https://forum.processing.org/two/discussion/561/easiest-way-to-append-to-a-file-in-processing)
- [Append data #3](https://forum.processing.org/two/discussion/11883/how-to-append-a-text-to-a-file)

I include _“append data posts”_ as it might be useful in your use case.

Kf
