Dynamic data to arduino from processing.

edited April 2017 in Arduino

Can you please tell me if we can send dynamic data to Arduino from processing.. and if yes then in which format? Refering to the slider example.. that my exact application.

Answers

  • Please give a proper title to the question, not your name.

    As to the question, yes we can. Read this tutorial - https://processing.org/tutorials/electronics/

  • Please provide a link to your example.

    Kf

  • @Kf.. will post it soon..

  • edited April 2017

    Welcome to the forum, @ashwini. You can change the title on your post to something more specific (like "dynamic data to Arduino from Processing") by editing / selecting the gear icon in the upper-right corner.

  • And you can add the code directly to the question by doing that.

  • //--------------------------------------ARDUINO CODE-----------------------------------/

    char val;

    int firstSensor = 0;    // first analog sensor

    int inByte = 0;         // incoming serial byte

    void setup()

    {

      // put your setup code here, to run once:

      pinMode(A0,INPUT);

      Serial.begin(9600);

      eshtablishContact();

    }

     

    void loop()

    {

      if(Serial.available()>0)

        {

          val= Serial.read();

         int T = val;

        Serial.print("val"); Serial.println(val);

    //    int tempC = analogRead(A0); //read the value from the sensor

    //    tempC = (5.0 * tempC * 100.0)/1024.0; //convert the analog data to temperature in Celcius

    //    Serial.println(tempC);

        }

        else

        {   Serial.println("Hello World");

           delay(50);

        }    

    }

         void eshtablishContact()

    {

      while(Serial.available()<=0)

      {

        Serial.println("A");

        delay(300);

      }

    }

     

         

  • Processing Code:

    import processing.serial.*;

    Serial myPort;

    String val;

    boolean firstContact=false;

    int previous_SP;

    int setpt;

    String SP;

     

    // Need G4P library

    import g4p_controls.*;

    public void setup(){

      size(480, 320, JAVA2D);

      createGUI();

      customGUI();

      String portName= Serial.list()[0];

      myPort= new Serial(this,portName,9600);

      myPort.bufferUntil('\n');

      // Place your setup code here

      

    }

    public void draw(){

     

     //background(230);

     // fill(34,56,89);

     // text("Current Temp",100,235);

     // text(val,175,235);

       int setpt= sldr.getValueI();

       String SP =str(setpt);

       println("Setpt:",setpt);

       println("Set_point that is transmitted==",SP);

    }

     

    void serialEvent(Serial myPort) {

    //put the incoming data into a String -

    //the '\n' is our end delimiter indicating the end of a complete packet

    val = myPort.readStringUntil('\n');

    //make sure our data isn't empty before continuing

    if (val != null) {

      //trim whitespace and formatting characters (like carriage return)

      val = trim(val);

      println(val);

    if (firstContact == false) {

        if (val.equals("A")) {

          myPort.clear();

          firstContact = true;

          myPort.write("A");

          println("contact");

        }

      }

       else { //if we've already established contact, keep getting and parsing data

        println(val);

     if (mousePressed == true)

        {   

          int setpt= sldr.getValueI();

          int previous_SP=setpt;

          String SP =str(setpt);

          println("Setpt:",setpt);

          println("Set_point that is transmitted==",SP);

       

        }

        else{

           myPort.write(previous_SP);

        }

      }

    }

     

    GUI:

     

    /* =========================================================

     * ====                   WARNING                        ===

     * =========================================================

     * The code in this tab has been generated from the GUI form

     * designer and care should be taken when editing this file.

     * Only add/edit code inside the event handlers i.e. only

     * use lines between the matching comment tags. e.g.

     

     void myBtnEvents(GButton button) { //CODE:button1:12356:

         // It is safe to enter your event code here  

     } //CODE:button1:12356:

     

     * Do not rename this tab!

     * =========================================================

     */

     

    public void sldr(GCustomSlider source, GEvent event) { //CODE:sldr:869469:

      //println("sldr - GCustomSlider >> GEvent." + event + " @ " + millis());

      int setpt= sldr.getValueI();

    } //CODE:sldr:869469:

     

     

     

    // Create all the GUI controls.

    // autogenerated do not edit

    public void createGUI(){

      G4P.messagesEnabled(false);

      G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);

      G4P.setCursor(ARROW);

      surface.setTitle("Sketch Window");

      label1 = new GLabel(this, 99, 12, 223, 60);

      label1.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);

      label1.setText("ENVIRONMENTAL CHAMBER");

      label1.setTextBold();

      label1.setLocalColorScheme(GCScheme.PURPLE_SCHEME);

      label1.setOpaque(false);

      sldr = new GCustomSlider(this, 106, 97, 318, 61, "grey_blue");

      sldr.setShowValue(true);

      sldr.setShowLimits(true);

      sldr.setLimits(0.0, 0.0, 100.0);

      sldr.setNbrTicks(100);

      sldr.setStickToTicks(true);

      sldr.setShowTicks(true);

      sldr.setEasing(4.0);

      sldr.setNumberFormat(G4P.DECIMAL, 1);

      sldr.setOpaque(true);

      sldr.addEventHandler(this, "custom_slider1_change1");

      label2 = new GLabel(this, 8, 117, 80, 20);

      label2.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);

      label2.setText("Temperature");

      label2.setTextBold();

      label2.setOpaque(false);

    }

     

    // Variable declarations

    // autogenerated do not edit

    GLabel label1;

    GCustomSlider sldr;

    GLabel label2;

     

  • Can you help?

  • Please edit your post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code.

    Kf

  • Press the gear icon to edit your post, and follow kfrajer's instructions.
    We can only help you once we understand your code.

Sign In or Register to comment.