Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

  • sending multiple values from processing to arduino

    I have managed to send one value from processing to arduino. (which maps mouseX and lights the respective LED on an LED strip of Neopixels) I went through a lot of forums and tried to send MOuse Position(2 values ) from processing to arduino .. By trying to seperate the numbers using substring and toInt ... But then the programm doesn't seem to be working.
    can anyone share an simple example that sends and recieves X and Y values

  • Error, disabling serialEvent()

    The full message I am getting is: Error, disabling serialEvent() for /dev/cu.usbmodem2574541 null

    The sketch will get the data one time than it hangs on this message.

    Here is my code; I am getting the data from an arduino teensy 3.5 Please help.

    Thanks

    import processing.serial.*; Serial port; int BaseEncGlobal; int ElbowEncGlobal; int ShoEncGlobal; int VertRotEnc; int HorRotEnc; int GripEncGlobal;

    double X_axis; double Y_axis; double Z_axis; double GripAngle;

    String data; boolean newData = false;

    PFont font;

    void setup() { size(1280,800); //port = new Serial(this, "/dev/cu.usbserial-A50285BI", 115200); port = new Serial(this, "/dev/cu.usbmodem2574541", 115200); port.bufferUntil('\n'); font = loadFont("AgencyFB-Bold-200.vlw"); textFont(font, 40); }

    void draw()

    { if (newData == true) {

    int spaceDown = 55; background(0,0,0); fill(46, 209, 2); text(BaseEncGlobal, 70, spaceDown); fill(0, 102, 153); text(ShoEncGlobal, 70, spaceDown2); fill(0, 102, 153); text(ElbowEncGlobal, 70, spaceDown3); fill(0, 102, 153); text(VertRotEnc, 70, spaceDown4); fill(0, 102, 153); text(HorRotEnc, 70, spaceDown5); fill(0, 102, 153); text( GripEncGlobal, 70, spaceDown*6);

    text(Double.toString(X_axis/10), 270, spaceDown ); newData =false; }

    }

    void serialEvent (Serial port) {

    data = port.readStringUntil('\n'); if (data != null) { data = trim(data);

    int[] nums = int(split(data, ',')); BaseEncGlobal = nums [1]; ShoEncGlobal = nums [2]; ElbowEncGlobal = nums [3]; VertRotEnc = nums [4]; HorRotEnc = nums [5]; GripEncGlobal = nums [6]; X_axis = nums [7]; Y_axis = nums [8]; Z_axis = nums [9]; GripAngle = nums [10]; //println(Double.toString(X_axis/10));

    println(data);

    newData = true; }

    }

    /*

    void serialEvent (Serial port) { data = port.readStringUntil('.'); data = data.substring(0, data.length() - 1);

    // look for the comma between Celcius and Farenheit index = data.indexOf(","); // fetch the C Temp temp_c = data.substring(0, index); // fetch the F Temp //temp_f = data.substring(index+1, index); temp_f = data.substring(1, data.length());

    ElbowEncGlobal =  getValue(data, ',', 2);
    

    } */

  • Reliably send images over net

    @GoToLoop, certainly, "Java's datatype byte is problematic", but it is the only 8-bit datatype that Java has. Communication methods need to use that datatype. I have had some problems trying to send data between sketches, and also trying to send data between Arduino and Processing. You came to help, I'm sorry if I was a bit harsh in my response. I probably should have pointed out your error in a private message, but I guess we both learned something from this. Again, thanks for your help.

  • how to show multiple data from 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

  • Processing (image display) via Arduino ultrasonic sensor

    Hi, I am just starting to explore posibilities to make something work in processing via arduino (sensors). On school exhibition I want to make a picture display that shows one image at the time on the wall (with a projector), depending how close or far person is located from distance sensor. This is a sketch of what I am thinking about:example To see if it really works, I explored some tutorials that explains how to connect Arduino input with Processing. Currently, I have these codes in both programs: for Arduino:

    const int anPin1 = 0;
    long distance1;
    
    void setup() {
      Serial.begin(9600);  // sets the serial port to 9600
    }
    
    void read_sensors(){
      /*
      Scale factor is (Vcc/512) per inch. A 5V supply yields ~9.8mV/in
      Arduino analog pin goes from 0 to 1024, so the value has to be divided by 2 to get the actual inches
      */
      distance1 = analogRead(anPin1)/2;
    }
    
    void print_all(){
      /*
      Serial.print("S1");
      Serial.print("inches");
      */
      Serial.print(" ");
      Serial.print(distance1);
      Serial.println();
    }
    
    void loop() {
      read_sensors();
      print_all();
      delay(50); 
    }
    

    And for Processing:

    import processing.serial.*;  
    Serial myPort;  
    String data="" ;
    PFont  myFont;  
    int distance;
    
    void setup(){
      size(1366,900); // size of processing window
      //background(0);// setting background color to black
    
      myPort = new Serial(this, "/dev/cu.usbmodemfd111", 9600);
      myPort.bufferUntil('\n');
    }
    
    void draw(){
    
      background(0);
      textAlign(CENTER);
      fill(255);
      text(data,820,400);
      textSize(100);
      fill(#4B5DCE);
      text("              Distance :        cm",450,400);
      noFill();
      stroke(#4B5DCE);
    
    }
    
    void serialEvent(Serial myPort){
    
      data=myPort.readStringUntil('\n');
    
    }
    

    And this distance reading works perfect!

    Unfortunately didn’t found any specific example for what i am looking for. So the question is, how can I get, for example, 3 pictures working this way:

    if(distance>60){
    image(photo1, 0, 0); //display first photograpgy
    }
    else if (40<distance<60) {
    image(photo2, 0, 0);
    }
    else if (distance<40) {
    image(photo3, 0, 0);
    }
    

    Do I have to write something like that in draw ()? And how can I get income distance value as number from which depends displayed image? And should I upload any specific library for this? Do i have to write something also again in Arduino code?

    Would be great if someone could suggest any examples or codes for this.

    Hoping for advise, komats!!

  • Arduino, Processing, P5js - Project help

    Hi there, Looking for someone with knowledge in Arduino, Processing, P5js who can work with me closely in developing a project. Interested people please get in touch with me for further details. Thank you.

  • Processing and Arduino Jobs

    Do you know where I could apply freelance jobs wherein processing or arduino coding are involved?

  • When will Processing IDE shift to Java 8

    Processing as a "programming language", rather than an actual library, caters more for the artistic folks. :D

    And Processing's already got the 3 most important languages for them covered, and even beyond: $-)

    1. Java as Java & Android Modes: Still the world's most used programming language. C-style syntax. ~O)
    2. JavaScript as both Pjs & p5.js flavors: Literally the Java's syntax deployed to the web! Where most artists wanna show up their works! :bz
    3. Python as both Python Mode & p5py flavors: Earned its place in academics introductory programming courses, due to its clean (no curly brackets) & easier syntax. O:-)

    Of course there are also R as R Mode, Clojure as Quill and Ruby as Ruby-Processing. Maybe more. <:-P
    And similar to Processing we've even got C/C++ as Arduino & openFrameworks. \m/

  • [Argument / Android mode] Processing Android Mode How to succeed

    @SnailPropulsionLabs===

    sorry, i have not seen any examples (from your link) related to wifi, blueTooh or nfc; tell me if i am wrong.

    @Gwak===

  • Stacktrace Question - StringIndexOutOfBoundsException

    Thanks Chrisir. I've already figured that out. Unfortunately it isn't realistic to post my code. I have thousands of lines and multiple threads. I'm also using several libraries and I'm interacting with an Arduino over serial and hundreds of text files. Nobody would be able to duplicate the error with just the code. I've been injecting println commands into the code to try to figure out where the problem is happening but as of yet I haven't been able to pinpoint it. What I was trying to figure out with this question is how to decipher some of the stack trace codes. Specifically, what does 1967 refer to?

  • Serial

    Is it possible to use the serial p5.serialcontrol and a local server to broadcast the data acquired by an Arduino?

  • out of memory error on loadImage() in Draw loop

    Great, thank you for sharing your solution. May I ask why you were calling stop()? I have done arduino and serial stuff before and I didn't call this at all before. Where you following some reference that was advising you to do this?

    Kf

  • save and load Array list

    Can you read data from arduino now...?

  • save and load Array list
      PVector prev = new PVector(-1, -1); 
      int y=50; 
      for (PVector pv : points2) {
    
        if (showText) {
          fill(0, 255, 2); // GREEN 
          // show data
         // text(pv.x, 210, y); 
           text(pv.x, 1080-50, y+410);
           text(pv.y, 1080, y+410);
        }
    
        fill(0, 2, 2); 
        stroke(0, 255, 2); // GREEN 
        float yvalue = map( pv.y, 0,1, 700, 180); // dimensione grafico GREEN
        if (prev.x!=-1) {
          line(80 + pv.x*55, yvalue, // linea grafico verde
            prev.x, prev.y);
    
        }
        noStroke(); 
        ellipse (80 + pv.x*55, yvalue, 4, 4);
        prev = new PVector(80 + pv.x*55, yvalue);
    
        y+=20; //next line
      }//for
    
      if (showText) {
      //  // middle line 
        stroke(0, 255, 2); // GREEN 
        line( 1275-220, 440, 1275-220, 720);// linea divisoria
    
      }
      ////
    }
    
    void showData3() {
      //
      // show data 3
    
      color col3 = color(0, 2, 255); // BLUE 
    
      if (activeArrayListHasNumber==2) {
        // activeArrayListHasNumber is FALSE, right side is active
        stroke(col3); // 
        line (1120, 405, 
          1210, 405);
         line (870, 320, 1330, 320);
        line (870, 340, 1330, 340);
         ellipse (865, 330, 6, 6);
      }
    
      PVector prev = new PVector(-1, -1); 
      int y=50; 
      for (PVector pv : points3) {
    
        fill(col3); // Blue 
    
        if (showText) {
          // show data
          text(pv.x, 1190-50, y+410); 
          text(pv.y, 1190, y+410);// 
        }
    
        fill(0, 2, 2); 
        stroke(col3); // blue 
        //float yvalue = map( pv.y, 0, height, 300, 355); 
        //if (prev.x!=-1) {
        //  line(10 + pv.x*3, yvalue, 
        //    prev.x, prev.y);
             float yvalue = map( pv.y, 0,1, 700, 180); // dimensione grafico GREEN
        if (prev.x!=-1) {
          line(80 + pv.x*55, yvalue, // linea grafico verde
            prev.x, prev.y);
        }
        noStroke(); 
    
      ellipse (80 + pv.x*55, yvalue, 4, 4);
        prev = new PVector(80 + pv.x*55, yvalue);
        y+=20; //next line
      }//for
    
      if (showText) {
     //   // middle line 
       stroke(col3); // blue 
        line( 1275-110,440,1275-110,720);
    
      }
      //
    }
    
    void showData4() {
      //
      // show data 4 
    
      color col4 = color(#FF00E6); 
    
      if (activeArrayListHasNumber==3) {
        // activeArrayListHasNumber is FALSE, right side is active
        stroke(col4); // 
        line (1230,405,1320,405);
        line (870, 350, 1330, 350);
        line (870, 370, 1330, 370);
         ellipse (865, 360, 6, 6);
      }
    
      PVector prev = new PVector(-1, -1); 
      int y=50; 
      for (PVector pv : points4) {
    
        fill(col4); //  
    
        if (showText) {
          // show data
          text(pv.x, 1300-50, y+410); 
          text(pv.y, 1300, y+410);
        }
    
        fill(0, 2, 2); 
        stroke(col4); //  
        //float yvalue = map( pv.y, 0, height, 300, 355); 
        //if (prev.x!=-1) {
        //  line(10 + pv.x*3, yvalue, 
        //    prev.x, prev.y);
         float yvalue = map( pv.y, 0,1, 700, 180); // dimensione grafico viola
        if (prev.x!=-1) {
          line(80 + pv.x*55, yvalue, // linea grafico viola
            prev.x, prev.y);
        }
        noStroke(); 
        ////   ellipse (10 + pv.x*3, yvalue, 4, 4);
        //prev = new PVector(10 + pv.x*3, yvalue);
         ellipse (80 + pv.x*55, yvalue, 4, 4);
        prev = new PVector(80 + pv.x*55, yvalue);
    
        y+=20; //next line
      }//for
    
      if (showText) {
        // middle line 
        stroke(col4); //  
        line( 1275, 440, 1275, 720);
      }
       { stroke(0); // BLACK 
    
        line( 1220, 400, 1220, 720); 
        line( 1220-110, 400, 1220-110, 720); 
        line( 1220-220, 400, 1220-220, 720); 
    
       }
    }
    
    // ---------------------------------------------------------------
     void serialEvent(Serial p) { 
      while (myPort.available() > 0) {
      inString = p.readString(); 
      char primo=inString.charAt(0);  // primo carattere
      String cifra=inString.substring(1);  // da secondo carattere in poi
      float val=parseFloat(cifra);          // valore da 0-255 o 0-1023, non sò cosa spedisce arduino
      print("primo=");  println(primo); //debug
    
      print("cifra=");  println(cifra); //debug
      print("val=");    println(val);
     // print(nf(val,0,2));
      switch(primo) { 
        case ('A'): MasA=(val);
         break;
    
        case ('B'): PCil=(val);
         break;  
    
        case ('C'): PAtm=(val);
          break;
    
       // case ('D'): Temp=(val);
         // break;
      } 
    }
    }
    
    void goBackToMainState() {
    
      // from help screen back to main screen
    
      // buttons ON 
     //MasA.setVisible(true); 
     // PCil.setVisible(true); 
     // PAtm.setVisible(true); 
     // myKnob4.setVisible(true); 
    
      //go back to main screen 
      state=normal;
    
      // kill Esc so we stay in the program 
      key=0;
    }
    
    void  backspaceOnActiveList() {
    
      // for the key BACKSPACE 
    
      switch (activeArrayListHasNumber) {
    
      case 0:
        if (points1.size()>0)
          points1.remove(points1.size()-1);
        break; 
    
      case 1:
        if (points2.size()>0)
          points2.remove(points2.size()-1);
        break;
    
      case 2:
        if (points3.size()>0)
          points3.remove(points3.size()-1);
        break;
    
      case 3:
        if (points4.size()>0)
          points4.remove(points4.size()-1);
        break;
      }//switch
      //
    }//func 
    
    // ------------------------------------------------
    // tools
    
    String nameFromPath(String fileName1) {
    
      File file = new File(fileName1);
      String result = file.getName();
      return result;
    } //func 
    //
    
  • How ro record audio?

    You should do everything in minim, instead of accessing audio using processing.sound. I will start with these :

    http://code.compartmental.net/minim/audioplayer_method_play.html
    http://code.compartmental.net/minim/minim_method_createrecorder.html

    You can also skip the arduino part. Instead, you can map senVal to the mouse position in the screen to simulate the arduino part:

    quick.rate(map(mouseX, width,0, 1, 0.25));

    Kf

  • How ro record audio?

    I am trying to use the minim library to record a mp3 that is manipulated with a motion sensor. However, the recordings I am making are coming up empty. Here is my code:

    import processing.serial.*;
    import cc.arduino.*;
    import org.firmata.*;
    import processing.sound.*;
    import ddf.minim.*;
    import ddf.minim.ugens.*;
    
    Arduino ardy;
    
    SoundFile quick;
    int senVal;
    Minim         minim;
    AudioOutput   out;
    AudioRecorder recorder;
    
    void setup() {
      fullScreen(P3D);
      noCursor();
      background(0);
    
      //Getting Arduino Data
      println(Arduino.list());
      ardy = new Arduino(this, "COM3", 57600); 
      ardy.pinMode(0, Arduino.INPUT);
    
      //sound
      quick = new SoundFile(this, "QUICKENING.mp3");
      quick.loop();
    
      //record sound
      minim = new Minim(this);
      out = minim.getLineOut();
      recorder = minim.createRecorder(out, "quickening_live.wav");
    
      frameRate(25);
    }
    
    void draw() {
      //Sensor Data
      senVal = ardy.analogRead(0);
      println(senVal);
      quick.rate(map(senVal, 70, 10, 1, 0.25)); 
    }
    
    void keyReleased(){
      if ( key == 'r' ) {
        if ( recorder.isRecording() ) {
          recorder.endRecord();
        } else {
          recorder.beginRecord();
        }
      }
    
      if ( key == 's' ){
        recorder.save();
        println("Done saving.");
      }
    }
    
  • bluetooth on android mode

    @robotman2412, @kfrajer=== i have tested the code i have put: it works for bluetooth; i cannot say for the arduino part.

  • Using Serial Library

    We are currently using the arduino ide to interact with our fpga. Now I want my Gui to interact with my fpga using serial communication.

  • bluetooth on android mode

    @robotman2412====

    see here: https://forum.processing.org/two/discussion/20881/processing-android-mode-android-device-bluetooth-arduino/p1

    my code is somewhere in the middle of the posts; code posted at the beginning by the guy who asked is not for P5 3XXX or 4 but for 2

  • Using Serial Library

    Is this related to Arduino? Or are you interacting with some other hardware? Provide some sample code showing what you have tried so far.

    Kf