how to show multiple data from arduino

edited July 2018 in Arduino

how to read the value from arduino and then i want to displaying that on processing window. This is my arduino code:

      #include <TimerOne.h>            
      #include <PZEM004T.h>
      #include <LiquidCrystal.h>


      int dutycycle = 0;     // Initailize duty cylce variable as integer data type
      int incomingByte = 0;
      PZEM004T pzem(2,3);  // (RX,TX) connect to TX,RX of PZEM
      IPAddress ip(192,168,1,1);
      LiquidCrystal lcd(12, 11, 4, 5, 6, 7);


       void setup()               // Setup function
      {
        Serial.begin(9600);
        pinMode (9, OUTPUT);             // set pin 9 as an output pin for pwm
        pinMode (10, OUTPUT);            // set pin 10 as an output pin for pwm
        Timer1.initialize(20000);             // Initailize timer1 time period as 20 milli second (50 Hz frequency)
        TCCR1A = (TCCR1A & 0x0F) | 0xB0 ;             // set pin 10 inverted of pin 9
        pzem.setAddress(ip);
        lcd.begin(16, 2); // lcd rows and columns
       }


      void loop()              // loop function starts
      { 
      if (Serial.available() > 0)
      {
      incomingByte = Serial.read ();  
      dutycycle = map(incomingByte, 0, 255, 0, 1023);
      Timer1.pwm(9, dutycycle, 20000);            // Timer1.pwm function takes argument as (pin no. , dutycycle , time period)
      Timer1.pwm(10, 1023-dutycycle, 20000);


      float v = pzem.voltage(ip);
      if (v < 0.0) v = 0.0;

      Serial.print(v);Serial.print("V; ");
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("V= ");
      lcd.setCursor(2,0);
      lcd.print(v);


      float i = pzem.current(ip);
      if (i < 0.0) i = 0.0;

      Serial.print(i);Serial.print("A; ");
      lcd.clear();
      lcd.setCursor(9,0);
      lcd.print("A= ");
      lcd.setCursor(11,0);
      lcd.print(i);


      float p = pzem.power(ip);
      if (p < 0.0) p = 0.0;

      Serial.print(p);Serial.print("W; ");
      lcd.clear();
      lcd.setCursor(9,1);
      lcd.print("W= ");
      lcd.setCursor(11,1);
      lcd.print(p);


      float e = pzem.energy(ip);

      Serial.print("PF= ");Serial.print((p)/(v*i));
      lcd.setCursor(0,1);
      lcd.print("PF=");
      lcd.setCursor(3,1);
      lcd.print((p)/(v*i));

      Serial.println(v);
      Serial.println(i);
      Serial.println(p);
      Serial.println((p)/(v*i));

     delay(100);  
     }
     }               // loop function ends

i want to send the value of "v","i","p" and "pf" and show it in processing window, this is my processing code :

      import controlP5.*;
      import processing.serial.*;

      ControlP5 cP5;

      Serial arduino;
      String val= "0";

      void setup() 
      {
      size(800, 550);
      println(Serial.list());
      String portName = Serial.list()[0];
      arduino = new Serial(this, portName, 9600);

      cP5 = new ControlP5(this);
      cP5.addSlider("ATUR DUTY CYCLE", 0, 255, 0, 210, 155, 350, 50);
      }

      void draw() 
      {
      background(#614DED);
      textSize(20);
      fill(#F5ED00);
      text("PENGENDALIAN INVERTER FULL BRIDGE SATU FASA", 140, 30);
      textSize(20);
      text("SECARA WIRELESS BERBASIS ARDUINO", 200,60);
      text("ARUS", 210, 300);
      text("TEGANGAN", 460, 300);
      text("DAYA", 210, 400);
      text("FAKTOR DAYA", 460, 400);

      if (arduino.available() >0){
      delay(100);
      val=arduino.readString();}  

      textSize(18);
      fill(#FAFF08);
      text(val, 210 ,330 );

      textSize(18);
      fill(#FAFF08);
      text(val, 460, 330);

      textSize(18);
      fill(#FAFF08);
      text(val, 210, 430);

      textSize(18);
      fill(#FAFF08);
      text(val, 460, 430);

      }

       void controlEvent(ControlEvent theEvent) {
       if(theEvent.isController()) {

       int val = int(theEvent.getController().getValue());
       arduino.write(val);
       } 
       }

Thank you very much

Answers

Sign In or Register to comment.