table values Arduino

edited January 2018 in Arduino

Hi, I'm a processing pivot. I have a problem I have a value taken from Arduino, and I visualize it in a graph, but I would also like to be able to visualize it through a numerical table. How can I do? thank you!

import processing.serial.*;
import grafica.*;
Serial myPort;    // The serial port: 
float val;//i datiricevutidalla porta seriale
int xPos=0;
//Stringa di input dalla porta seriale:
int lf = 10;      // ASCII linefeed 
 GPlot plot1, plot2;





void setup() {
  size(440, 520);
 // Create the first plot  Crea il primo grafico
  plot1 = new GPlot(this);
  plot1.setPos(0, 0);
  plot1.setMar(0, 100, 0,100);
  plot1.setDim(300, 300);
  plot1.setAxesOffset(4);
  plot1.setTicksLength(4);

  // Create the second plot with the same dimensions 
  //Crea il secondo grafico con le stesse dimensioni
  plot2 = new GPlot(this);

  // Prepare the points Prepara i punti
  int val =0;
  GPointsArray points = new GPointsArray(val);

  for (int i = 15; i < 13; i++) {
    points.add(i, 20 + 10*noise(i*0.1));
    if(xPos==13){

    }
  }  

  // Set the points, the title and the axis labels 
  // Imposta i punti, il titolo e le etichette degli assi
  plot1.setPoints(points);
  plot1.setTitleText("Temperature");
  plot1.getYAxis().setAxisLabelText("MASSA ARIA (?)");
  plot1.getXAxis().setAxisLabelText("APERTURA VALVOLA (mm)");


  plot1.activatePanning();
    myPort = new Serial(this, "com3", 9600);
  myPort.bufferUntil(lf);

}




void draw() {
  background(255);
  println(val);
  fill(0);
  text("val  "+val,200,450);
 //Disegna la prima trama 
  plot1.beginDraw();
  plot1.drawBox();
  plot1.drawXAxis();
  plot1.drawYAxis();
  plot1.drawTitle();
 //plot1.drawPoints();//pallinorosso sul valore
  plot1.drawGridLines(GPlot.BOTH);
  plot1.drawLines();
  plot1.endDraw();
  }




  void serialEvent (Serial myPort) {
      //  // get the ASCII string:
  //  // ottiene la stringa ASCII: 
   String inString = myPort.readStringUntil('\n');

    if (inString != null) {
  //    // trim off any whitespace:

      inString = trim(inString);

     val = float(inString);
    println(val);
   }
  }

void mousePressed(){
   GPoint lastPoint = plot2.getPointsRef().getLastPoint();

  if (lastPoint == null) {

       plot1.addPoint(xPos, +val, "(" + str(xPos) + " , " + str(val) + ")");

  } 
  else if (!lastPoint.isValid() || sq(lastPoint.getX() - xPos) + sq(lastPoint.getY() + val) > 2500) {

  }

  if( mouseButton == LEFT ) xPos+=1; 

  fill(0);
   text ("val"+val,200,480);
}

Answers

  • edited January 2018

    for plotting see latest comments here:

    https://forum.processing.org/two/discussion/25248/plotting-data/p1

    this won't work:

    for (int i = 15; i < 13; i++) {
    

    see reference under for, you want for (int i = 0; i < 13; i++) {

  • for a simple table output see here:

    ArrayList<PVector> points = new ArrayList();
    
    void setup() {
      size(900, 800);
    
      for (int i = 0; i < 13; i++) {
        points.add(new PVector(i, 20 + 10*noise(i*0.1)));
      }//for
    
      background(190);
    }//
    
    void draw() {
    
      background(190);
    
      // show data 
      int y=50;
    
      for (PVector pv : points) {
        // show data 
        text(pv.x, 100, y);
        text(pv.y, 200, y);
        y+=20; //next line
        // middle line 
        line( 190, 30, 190, 440);
      }//for
    }//
    
  • > Thanks Chrisir for your advice, but I do not understand how to play "val" both with the graph and at the same time reproduced in a table ....>

  • just make your window more wide with size and then place the table right from the graph (using higher x-values).

    Where you say points.add(i, 20 + 10*noise(i*0.1)); also put the same value into my ArrayList (which needs another name like pointsTable)

  • Ciao, grazie per il tuo interessamento, il grafico usa le cordinate "val e xPos( aggiornato ad ogni "mousePressed"), non capisco come nello stesso momento compilare la tabella con "val" aggiornati ad ogni azione di "mousePressed"... Grazie...

    import processing.serial.*;
    ArrayList<PVector> points = new ArrayList();
     Serial myPort;    // The serial port: 
    float val;//i datiricevutidalla porta seriale
    int lf = 10;      // ASCII linefeed 
    void setup() {
      size(900, 800);
    
      for (int i = 0; i < 13; i++) {
        points.add(new PVector(i, 20 + 10*noise(i*0.1)));
      }//for
    
      //background(190);
    
        myPort = new Serial(this, "com3", 9600);
      myPort.bufferUntil(lf);
    }
    
    void draw() {
    
     // background(190);
    
      // show data 
      int y=50;
    
      for (PVector val : points) {
        // show data 
        text(1, 350, y);
        text(+val.y, 400, y);
        y+=20; //next line
        // middle line 
     //   line( 190, 30, 190, 440);
      }//for
    }//
    
      void serialEvent (Serial myPort) {
          //  // get the ASCII string:
      //  // ottiene la stringa ASCII: 
       String inString = myPort.readStringUntil('\n');
    
        if (inString != null) {
      //    // trim off any whitespace:
    
          inString = trim(inString);
    
         val = float(inString);
        println(val);
       }
      }
    
  • Answer ✓

    non capisco

    English please

    here, when you click the mouse, values are plotted AND in the table

    import processing.serial.*;
    ArrayList<PVector> points = new ArrayList();
    Serial myPort;    // The serial port: 
    float val;//i datiricevutidalla porta seriale
    int lf = 10;      // ASCII linefeed 
    
    int i; 
    
    void setup() {
      size(900, 800);
    
      for (int i = 0; i < 13; i++) {
        //   points.add(new PVector(i, 20 + 10*noise(i*0.1)));
      }//for
    
      //background(190);
    
      //myPort = new Serial(this, "com3", 9600);
      //myPort.bufferUntil(lf);
    }
    
    void draw() {
    
      // background(190);
    
      // show data 
      int y=50;
    
      //for (PVector val : points) {
      for (int i2 = 0; i2 < points.size(); i2++) {
        PVector val = points.get(i2);
        // show data 
        text(1, 350, y);
        text(+val.y, 400, y);
        y+=20; //next line
        // middle line 
        //   line( 190, 30, 190, 440);
    
        if (i2 < points.size()-1) {
          PVector val2 = points.get(i2+1);
          stroke(255, 2, 2); 
          line(val.x*3, val.y, 
            val2.x*3, val2.y);
        }
      }//for
    }//
    
    void mousePressed() {
      val = float(mouseX);
      points.add(new PVector(i, val));
      i++;
    }
    
    void serialEvent (Serial myPort) {
      //  // get the ASCII string:
      //  // ottiene la stringa ASCII: 
      String inString = myPort.readStringUntil('\n');
    
      if (inString != null) {
        //    // trim off any whitespace:
    
        inString = trim(inString);
    
        val = float(inString);
        println(val);
      }
    }
    
  • sorry........

    I am a young Italian and with English I still do a bit of effort and not to write oddities I use a translator ..... your sketch works, now I try to implement it to the sketch of the chart and I see what happens ....... Thanks again

  • You're welcome!

  • My intention is to see "val" with the graph of my sketch and complete it with the table that suggested me.

  • I keep you informed thanks

  • the sketch works only (and not always) only at the first mouse pressure .... after I write incorrect values ​​and even if various "val" the value in the table does not match .....

  • Answer ✓

    first the mouse clicks are just a simulation since my arduino is not on

    second, press ctrl-t in processing and then show your entire code here so we can have a look.

  • found!!! I deleted in line 49... val= float(mouseX);

  • Congratulations!

Sign In or Register to comment.