<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with serialevent() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=serialevent%28%29</link>
      <pubDate>Sun, 08 Aug 2021 14:49:40 +0000</pubDate>
         <description>Tagged with serialevent() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedserialevent%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>no Graph with data from Arduino?</title>
      <link>https://forum.processing.org/two/discussion/14060/no-graph-with-data-from-arduino</link>
      <pubDate>Fri, 18 Dec 2015 12:30:24 +0000</pubDate>
      <dc:creator>hb9bqb</dc:creator>
      <guid isPermaLink="false">14060@/two/discussions</guid>
      <description><![CDATA[<p>tried a simple example to draw a Graph from arduino data. No graph visible? Running on Windows 10</p>

<p>import processing.serial.*;</p>

<p>Serial myPort;        // The serial port
 int xPos = 0;         // horizontal position of the graph</p>

<p>void setup () {
 // set the window size:
 size(400, 600);</p>

<p>// List all the available serial ports
 println(Serial.list());</p>

<p>// open Serial.list()[0].
 // Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[1], 9600);
// myPort = new Serial(this, "COM8", 9600);</p>

<p>// don't generate a serialEvent() unless you get a newline character:
 myPort.bufferUntil('\n');
 // set inital background:
 //background(0);  schwarzer Hintergrund
 background (100,100,255);
 }
 void draw () {
 // everything happens in the serialEvent()
 }</p>

<p>void serialEvent (Serial myPort) {
 // get the ASCII string:
 String inString = myPort.readStringUntil('\n');</p>

<p>if (inString != null) {
 // trim off any whitespace:
 inString = trim(inString);
 // convert to an int and map to the screen height:
 float inByte = float(inString);</p>

<p>inByte = map(inByte, 0, 1023, 0, height);
println(inString);  // to see if datas are incoming</p>

<p>// draw the line:
 stroke(0,0,0);
 line(xPos, height, xPos, height - inByte);</p>

<p>// at the edge of the screen, go back to the beginning:
 if (xPos &gt;= width) {
 xPos = 0;
 background(0); 
//background (216,225,165);
 } 
 else {
 // increment the horizontal position:
 xPos++;
 }
 }
 }</p>
]]></description>
   </item>
   <item>
      <title>Error, disabling serialEvent()</title>
      <link>https://forum.processing.org/two/discussion/28124/error-disabling-serialevent</link>
      <pubDate>Sat, 22 Sep 2018 19:34:23 +0000</pubDate>
      <dc:creator>laptophead</dc:creator>
      <guid isPermaLink="false">28124@/two/discussions</guid>
      <description><![CDATA[<p>The full message I am getting is: Error, disabling serialEvent() for /dev/cu.usbmodem2574541
null</p>

<p>The sketch will get the data one time than it hangs on this message.</p>

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

<p>Thanks</p>

<p>import processing.serial.*;
Serial port;
int BaseEncGlobal;
int ElbowEncGlobal;
int ShoEncGlobal;
int VertRotEnc;
int HorRotEnc;
int GripEncGlobal;</p>

<p>double X_axis;
double Y_axis;
double Z_axis;
double GripAngle;</p>

<p>String data;
boolean newData = false;</p>

<p>PFont font;</p>

<p>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);
}</p>

<p>void draw()</p>

<p>{ if (newData == true) {</p>

<p>int spaceDown = 55;
  background(0,0,0);
  fill(46, 209, 2);
  text(BaseEncGlobal, 70, spaceDown);
  fill(0, 102, 153);
  text(ShoEncGlobal, 70, spaceDown<em>2);
  fill(0, 102, 153);
 text(ElbowEncGlobal, 70, spaceDown</em>3);
  fill(0, 102, 153);
 text(VertRotEnc, 70, spaceDown<em>4);
  fill(0, 102, 153);
text(HorRotEnc, 70, spaceDown</em>5);
  fill(0, 102, 153);
  text( GripEncGlobal, 70, spaceDown*6);</p>

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

<p>}</p>

<p>void serialEvent (Serial port)
{</p>

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

<p>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));</p>

<p>println(data);</p>

<p>newData = true;
 }</p>

<p>}</p>

<p>/*</p>

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

<p>// 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());</p>

<pre><code>ElbowEncGlobal =  getValue(data, ',', 2);
</code></pre>

<p>}
*/</p>
]]></description>
   </item>
   <item>
      <title>Processing (image display) via Arduino ultrasonic sensor</title>
      <link>https://forum.processing.org/two/discussion/28055/processing-image-display-via-arduino-ultrasonic-sensor</link>
      <pubDate>Thu, 14 Jun 2018 12:33:26 +0000</pubDate>
      <dc:creator>komats</dc:creator>
      <guid isPermaLink="false">28055@/two/discussions</guid>
      <description><![CDATA[<p>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 <strong>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.</strong>
This is a sketch of what I am thinking about:<img src="https://forum.processing.org/two/uploads/imageupload/088/QJY2PU3L5TTS.jpg" alt="example" title="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:
<strong>for Arduino:</strong></p>

<pre><code>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); 
}
</code></pre>

<p><strong>And for Processing:</strong></p>

<pre><code>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');

}
</code></pre>

<p>And this distance reading works perfect!</p>

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

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

<p>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?</p>

<p>Would be great if someone could suggest any examples or codes for this.</p>

<p>Hoping for advise,
komats!!</p>
]]></description>
   </item>
   <item>
      <title>Collision detection between 2 objects with an ultrasonic sensor (Arduino)</title>
      <link>https://forum.processing.org/two/discussion/27682/collision-detection-between-2-objects-with-an-ultrasonic-sensor-arduino</link>
      <pubDate>Tue, 03 Apr 2018 15:35:25 +0000</pubDate>
      <dc:creator>120898</dc:creator>
      <guid isPermaLink="false">27682@/two/discussions</guid>
      <description><![CDATA[<p>So I'm working from the code in Step 6 (I will attach below) of this tutorial: <a href="http://www.instructables.com/id/How-to-control-a-simple-Processing-game-with-Ardui/" target="_blank" rel="nofollow">http://www.instructables.com/id/How-to-control-a-simple-Processing-game-with-Ardui/</a></p>

<p>I am using an HR-SR04 ultrasonic sensor to control the plane, moving it up and down via hand movements.</p>

<p>What I am trying to do is implement an obstacle feature to the game, by having the score decrease by 1 when the plane hits a cloud. However I can't get the collision detection working for when the plane hits a cloud. The original author has managed to get this working perfectly for when the plane hits the bird but I'm not sure how to get it working between the plane and clouds, I've tried everything I can think of but I'm stuck.</p>

<p>Any help would be appreciated.</p>

<p>Below is the code that I'm working from:</p>

<pre><code>`//Ultrasound plane, a game with a plane and an ultrsound sensor (but

//by Yoruk for Instructables

//send commments or questions to Yoruk16_72 AT yahoo DOT fr


//19 07 14 : initial code
//20 07 14 : it works with arduino !!
//07 07 15 : picture for the plane and for the grass
//06 12 15 : score system with the bird


int i, j; 

int Score ;
float DistancePlaneBird;


float Hauteur; //en Y
float Angle;
int DistanceUltra;
int IncomingDistance;
//float Pas; //pour deplacements X

float BirdX;
float BirdY;

float GrassX ;  //for X position




String DataIn; //incoming data on the serial port

//5 a 32 cm


float [] CloudX = new float[6];
float [] CloudY = new float[6];

//vitesse constante hein


PImage Cloud;
PImage Bird;
PImage Plane;
PImage Grass;



// serial port config
import processing.serial.*; 
Serial myPort;    



//preparation
void setup() 
{

    myPort = new Serial(this, "/dev/cu.usbmodem1411", 9600); 

    myPort.bufferUntil(10);   //end the reception as it detects a carriage return

    frameRate(30); 

    size(800, 600);
    rectMode(CORNERS) ; //we give the corners coordinates 
    noCursor(); //why not ?
    textSize(16);

    Hauteur = 300; //initial plane value


    Cloud = loadImage("cloud.png");  //load a picture
    Bird = loadImage("bird.png");  
    Plane = loadImage("plane.png");  //the new plane picture

        Grass = loadImage("grass.png");  //some grass


    //int clouds position
    for  (int i = 1; i &lt;= 5; i = i+1) {
        CloudX[i]=random(1000);
        CloudY[i]=random(400);
    }


    Score = 0;
}


//incoming data event on the serial port


void serialEvent(Serial p) { 
    DataIn = p.readString(); 
    // println(DataIn);

    IncomingDistance = int(trim(DataIn)); //conversion from string to integer

    println(IncomingDistance); //checks....

    if (IncomingDistance&gt;1  &amp;&amp; IncomingDistance&lt;100 ) {
        DistanceUltra = IncomingDistance; //save the value only if its in the range 1 to 100     }
    }
}


//main drawing loop
void draw() 
{
    background(0, 0, 0);
    Ciel(); //draw the sky
    fill(5, 72, 0);



    //rect(0, 580, 800, 600); //some grass

    //new grass : 

    for  (int i = -2; i &lt;= 4; i = i+1) {  //a loop to display the grass picture 6 times

        image(Grass, 224*i  + GrassX, 550, 224, 58);  // 224 58 : picture size
    }

    //calculates the X grass translation. Same formulae than the bird
    GrassX = GrassX  -  cos(radians(Angle))*10;

    if (GrassX &lt; -224) {  //why 224 ? to have a perfect loop
        GrassX=224;
    }


    text(Angle, 10, 30); //debug things...
    text(Hauteur, 10, 60); 


    //new part : check the distance between the plane and bird and increase the score
    DistancePlaneBird = sqrt(pow((400-BirdX), 2) + pow((Hauteur-BirdY), 2)) ;

    if (DistancePlaneBird &lt; 40) {
        //we hit the bird   
        Score = Score+ 1;

        //reset the bird position
        BirdX = 900;
        BirdY = random(600);
    }

    //here we draw the score
    text("Score :", 200, 30); 
    text( Score, 260, 30); 



    //Angle = mouseY-300; //uncomment this line and comment the next one if you want to play with the mouse
    Angle = (18- DistanceUltra)*4;  // you can increase the 4 value...



    Hauteur = Hauteur + sin(radians(Angle))*10; //calculates the vertical position of the plane

    //check the height range to keep the plane on the screen 
    if (Hauteur &lt; 0) {
        Hauteur=0;
    }

    if (Hauteur &gt; 600) {
        Hauteur=600;
    }

    TraceAvion(Hauteur, Angle);

    BirdX = BirdX - cos(radians(Angle))*10;

    if (BirdX &lt; -30) {
        BirdX=900;
        BirdY = random(600);
    }

    //draw and move the clouds
    for  (int i = 1; i &lt;= 5; i = i+1) {
        CloudX[i] = CloudX[i] - cos(radians(Angle))*(10+2*i);

        image(Cloud, CloudX[i], CloudY[i], 300, 200);

        if (CloudX[i] &lt; -300) {
            CloudX[i]=1000;
            CloudY[i] = random(400);
        }
    }

    image(Bird, BirdX, BirdY, 59, 38); //displays the useless bird. 59 and 38 are the size in pixels of the picture
}


void Ciel() {
    //draw the sky

    noStroke();
    rectMode(CORNERS);

    for  (int i = 1; i &lt; 600; i = i+10) {
        fill( 49    +i*0.165, 118   +i*0.118, 181  + i*0.075   );
        rect(0, i, 800, i+10);
    }
}


void TraceAvion(float Y, float AngleInclinaison) {
    //draw the plane at given position and angle

    noStroke();
    pushMatrix();
    translate(400, Y);
    rotate(radians(AngleInclinaison)); //in degres  ! 


    /*
    Drawing concept :  ;-)

     |\___o__
     ________&gt;     

     */

    scale(0.5);  //0.2 pas mal

    //unless drawing the plane "by hands", just display the stored picture instead. Note that the parameters 2 and 3 are half the picture size, to make sure that the plane rotates in his center.
    image(Plane, -111, -55, 223, 110); // 223 110 : picture size



    popMatrix(); //end of the rotation matrix
}

//file end`
</code></pre>
]]></description>
   </item>
   <item>
      <title>two arduinos changing coloured circles on processing</title>
      <link>https://forum.processing.org/two/discussion/27397/two-arduinos-changing-coloured-circles-on-processing</link>
      <pubDate>Tue, 27 Mar 2018 11:51:25 +0000</pubDate>
      <dc:creator>jgid</dc:creator>
      <guid isPermaLink="false">27397@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm a student new to coding and am trying to get two arduinos, (connected via serial port) to change the colour of two different ellipses on processing. Both arduinos have a simple push button.</p>

<p>One ellipse changes colour when one arduino button is pressed (this part is fine)
But when I start to introduce the second arduino the coloured ellipses just flash quickly between the colours.</p>

<p>Is there a way to connect the two arduinos successfully? My code is posted below.</p>

<p>Thank you,
Jade ![](&gt; &gt; )</p>

<p>import processing.serial.*;</p>

<p>import processing.serial.*;
Serial port;
Serial portss;
PImage[] img = new PImage[1];
int val = 0;</p>

<p>void setup () {
  size (1000, 707);</p>

<p>img [0] = loadImage ("nocolouredblobs.jpg");
  background(img [0]);</p>

<p>fill(#459839);<br />
  ellipse(931,68,75,75);</p>

<p>port = new Serial(this, Serial.list()[3], 9600);
}</p>

<p>void draw() {
  if (port.available() &gt; 0) {
     val = port.read(); }</p>

<p>if (val == 2) {
    fill (#EDB137);
    ellipse (833, 68, 75, 75); 
    fill (#FFDE9B);
    ellipse (931,68,75,75); }
  else { 
    fill (#459839);
    ellipse (833, 68, 75, 75); 
    fill (#459839);
    ellipse (931,68,75,75); }</p>

<p>}</p>
]]></description>
   </item>
   <item>
      <title>Android Mode - Serial Communication - Andruino</title>
      <link>https://forum.processing.org/two/discussion/26750/android-mode-serial-communication-andruino</link>
      <pubDate>Sat, 10 Mar 2018 06:42:09 +0000</pubDate>
      <dc:creator>Gwak</dc:creator>
      <guid isPermaLink="false">26750@/two/discussions</guid>
      <description><![CDATA[<p>Hi, nice to meet you.</p>

<h1>I want  (Arduino) ------- (Smartphone)   Serial connection.</h1>

<blockquote class="Quote">
  <p>Processing 3.2.1.
  Android Mode 3.0.1</p>
</blockquote>

<h1> &gt; API 6.0</h1>

<p>======================================================================</p>

<pre><code>import io.inventit.processing.android.serial.*; //ANDROID

Serial myPort;      
String inString=""; 

void setup() {

  myPort = new Serial(this, Serial.list(this)[0], 38400); 
  myPort.bufferUntil(10);
}

//===========INCOMING DATA FROM THERMOSTAT=============
void serialEvent(Serial myPort) { 


  try {
    inString = myPort.readString();

  }
  catch(RuntimeException e) {

  }


}
</code></pre>

<p>======================================================================
**Error msg : **</p>

<h1>Processing - Android USB Serial Error.</h1>

<p><img src="https://forum.processing.org/two/uploads/imageupload/269/0N2C6IJ7564V.jpg" alt="Q" title="Q" /></p>
]]></description>
   </item>
   <item>
      <title>Print output from serial device connected on COM port using serial module</title>
      <link>https://forum.processing.org/two/discussion/26150/print-output-from-serial-device-connected-on-com-port-using-serial-module</link>
      <pubDate>Sun, 28 Jan 2018 08:43:59 +0000</pubDate>
      <dc:creator>SVK_212</dc:creator>
      <guid isPermaLink="false">26150@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to use the following modules in p3</p>

<p>controlP5 (for GUI)<br />
serial (to communicate with a device on COM port)</p>

<p>...
the device is a GSM SIM900 module that can understand AT commands.
when I create a session in PUTTY for COM port, for every AT command I type and press ENTER,
I get an acknowledgement.
For e.g.</p>

<p>AT<br />
OK</p>

<p>where AT was the command I typed and OK was the acknowledgement I got.</p>

<p>In p3, I made a GUI that contains 2 textboxes and a button.</p>

<p>I also created a serial handle,</p>

<p><code>mpo = new Serial(this,Serial.list()[0],9600);</code></p>

<p>mpo is global object of class Serial</p>

<p>On clicking the button, the content in the textboxes is processed and if a condition is met, then some functions in serial module are called.</p>

<pre><code>mpo.clear();  
mpo.write("AT\n");
</code></pre>

<p>...
I also have this function,</p>

<pre><code>void serialEvent(Serial mp){  
ins = mp.readString();  
print(ins);  
}  
</code></pre>

<p>where ins is a global String object. This function, I suppose, is called whenever I send commands to module and not when the module acknowledges.
 So, it prints AT, but doesn't print OK...
Is there any way this problem can be solved?</p>
]]></description>
   </item>
   <item>
      <title>table values Arduino</title>
      <link>https://forum.processing.org/two/discussion/26136/table-values-arduino</link>
      <pubDate>Sat, 27 Jan 2018 08:47:28 +0000</pubDate>
      <dc:creator>brugola</dc:creator>
      <guid isPermaLink="false">26136@/two/discussions</guid>
      <description><![CDATA[<p>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!</p>

<pre><code>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 &lt; 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) &gt; 2500) {

  }

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

  fill(0);
   text ("val"+val,200,480);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>how to perform a conditional check in processing on a value from serial read from arduino</title>
      <link>https://forum.processing.org/two/discussion/26127/how-to-perform-a-conditional-check-in-processing-on-a-value-from-serial-read-from-arduino</link>
      <pubDate>Fri, 26 Jan 2018 14:14:34 +0000</pubDate>
      <dc:creator>heaversm</dc:creator>
      <guid isPermaLink="false">26127@/two/discussions</guid>
      <description><![CDATA[<p>I have a simple push button connected to pin 2 on my arduino. I can read this value and print it to the serial monitor without any trouble:</p>

<p>```
int pushButton = 2;</p>

<pre><code>void setup() {
  Serial.begin(9600);
  pinMode(pushButton, INPUT);
}

void loop() {
  int buttonState = digitalRead(pushButton);
  Serial.println(buttonState);
  delay(1);        // delay in between reads for stability
}
</code></pre>

<p>```</p>

<p>This prints a value of 0 when the button is not pressed, and 1 if it is.</p>

<p>In processing I want to check if the value is zero or one, and perform some conditional logic. But I can't get the equality right:</p>

<p>```
    Serial myPort;
    String resultString;</p>

<pre><code>void setup(){
  size(640,480);
  printArray(Serial.list());
  String portName = Serial.list()[2];
  myPort = new Serial(this,portName,9600);
  myPort.bufferUntil(10);
}

void draw(){
  //
}

void serialEvent(Serial myPort){
  String inputString = myPort.readStringUntil(10); //until newline or ("\n");
  inputString = trim(inputString);
  println(inputString);
  if (inputString == "1"){ //this doesn't work, even though println will render ("1") plus the newline if button is pushed.
    println("on");
  } else {
    println("off");
  }
}
</code></pre>

<p>```</p>

<p>How do I set up this conditional to do one thing if the button is pushed, and another if it is not?</p>

<p>I've tried converting the string to an int using</p>

<p><code>inputInt = Integer.parseInt(inputString);</code></p>

<p>and then performing the check, but it didn't work.</p>
]]></description>
   </item>
   <item>
      <title>Sound gets distorted when runned in processing</title>
      <link>https://forum.processing.org/two/discussion/25905/sound-gets-distorted-when-runned-in-processing</link>
      <pubDate>Wed, 10 Jan 2018 21:02:54 +0000</pubDate>
      <dc:creator>Faffie</dc:creator>
      <guid isPermaLink="false">25905@/two/discussions</guid>
      <description><![CDATA[<p>Hello World, I have written a processing code and have implemented a sound file. When I play it on a common player, a cleat woman voice comes out. If I run my code processing is distorting her voice into a slow man version... I am runnin processing on a MacBook Pro with the latest Java version.</p>

<pre><code>import processing.serial.*;
import processing.sound.*;


int S1_WAITING_FOR_PEOPLE  = 1;
int S2_PEOPLE_ENTERED      = 2;
int S3_LIGHT_FADE_OUT      = 3;
int S4_DARK                = 4;
int S5_MUSIC               = 5;
int S6_LIGHT_FADE_IN       = 6;
// make sure this is the last!!!!
int TERMINATE              = 7;

int mode = S1_WAITING_FOR_PEOPLE;




int no_one_when_distance_greater_then = 160; // cm
int time_before_dim = 5000; // ms

SoundFile file;
boolean is_playing = false;

Serial myPort;  

int dist;

boolean someone_present = false;
int someone_present_since_time;


int music_playing_since;
int music_duration;

int in_mode_since_ms;

void setup() {
  size(640, 360);

  printArray(Serial.list()); // "/dev/cu.usbmodem1411" cu.usb!!!

  myPort = new Serial(this, Serial.list()[1], 9600);
  //myPort.readStringUntil('\n');
  myPort.bufferUntil('\n');

  // Load a soundfile from the data folder of the sketch and play it back in a loop
  file = new SoundFile(this, "03.mp3");
  //file.loop();
  music_duration = (int) file.duration() * 1000;
  music_duration += 2000;

}      

void draw() {
  background(0);
  fill(255);
  text("frameCount: "+frameCount, 50, 25);
  text("dist: "+dist, 50, 50);
  text("mode: "+mode, 50, 75);


  if (frameCount == 180) {
    turn_on();
  } else if (frameCount &gt; 180) {

    if ( mode == S1_WAITING_FOR_PEOPLE) {

      if (someone_present == false) {
        if (dist &lt; no_one_when_distance_greater_then) {
          someone_present = true;
          someone_present_since_time = millis();
          change_mode(mode + 1);
        }
      }
    } else if (mode == S2_PEOPLE_ENTERED) {
      text("millis: "+millis(), 50, 100);
      text("someone_present_since_time: "+someone_present_since_time, 50, 125);
      text("time_before_dim: "+time_before_dim, 50, 150);
      if (millis() - someone_present_since_time &gt; time_before_dim) {
        change_mode(mode + 1);
      }
    } else if (mode == S3_LIGHT_FADE_OUT) {
      turn_off();
      change_mode(mode + 1);
    } else if (mode == S4_DARK) 
    {
      change_mode(mode + 1);
    } else if (mode == S5_MUSIC) 
    {
      if (is_playing == false) {
        file.play();
        is_playing = true;
        music_playing_since = millis();
      }
      if (millis() - music_playing_since &gt; music_duration) {
        is_playing = false;
        file.stop();
        change_mode(mode + 1);
      }
    } else if (mode == S6_LIGHT_FADE_IN) 
    {
      // todo
      if (millis() - in_mode_since_ms &gt; 1000) {
        change_mode(mode + 1);
      }

    } else if (mode == TERMINATE) 
    {
      change_mode(S1_WAITING_FOR_PEOPLE);
      someone_present = false; // reset
      println("turn_on();");
      turn_on();
    }
  }
}


void change_mode(int m) {
  mode = m;
  in_mode_since_ms = millis();
}



void serialEvent(Serial p) { 
  String s = p.readString();
  if (s != null) {
    s = s.replace("\r\n", "");
    if (s.contains("Distance Measured")) {
      String[] tokens = split(s, "=");
      dist = int(tokens[1]);
    }
  }
} 


void turn_on() {
  myPort.write("on");
}

void turn_off() {
  myPort.write("off");
}

void keyPressed() {
  if (key == 'a') {
    turn_on();
  }
  if (key == 's') {
    turn_off();
  }
}
</code></pre>

<p>Thanks for your help!</p>
]]></description>
   </item>
   <item>
      <title>communicate between two macs in processing</title>
      <link>https://forum.processing.org/two/discussion/25841/communicate-between-two-macs-in-processing</link>
      <pubDate>Fri, 05 Jan 2018 20:53:36 +0000</pubDate>
      <dc:creator>Faffie</dc:creator>
      <guid isPermaLink="false">25841@/two/discussions</guid>
      <description><![CDATA[<p>Hello world,
I would like to know if it is possible to communicate between two macs in processing. What I mean:</p>

<p><em>Mac1 sends a signal to mac2 -&gt; mac2 plays an audio file -&gt; mac 2 waits for another signal sent by mac1 (loop)</em></p>

<p>In the code I have written I would love to send a signal to the second mac (mac2) at "int S5_MUSIC = 5;". So that there will be two sounds played at the same time. I need the second mac for a second pair of boxes, to create a surround sound....</p>

<p><strong>This is my processing code:</strong></p>

<pre><code>import processing.serial.*;
import processing.sound.*;


int S1_WAITING_FOR_PEOPLE  = 1;
int S2_PEOPLE_ENTERED      = 2;
int S3_LIGHT_FADE_OUT      = 3;
int S4_DARK                = 4;
int S5_MUSIC               = 5;
int S6_LIGHT_FADE_IN       = 6;
// make sure this is the last!!!!
int TERMINATE              = 7;

int mode = S1_WAITING_FOR_PEOPLE;




int no_one_when_distance_greater_then = 160; // cm
int time_before_dim = 5000; // ms

SoundFile file;
boolean is_playing = false;

Serial myPort;  

int dist;

boolean someone_present = false;
int someone_present_since_time;


int music_playing_since;
int music_duration;

int in_mode_since_ms;

void setup() {
  size(640, 360);

  printArray(Serial.list()); // "/dev/cu.usbmodem1411" cu.usb!!!

  myPort = new Serial(this, Serial.list()[1], 9600);
  //myPort.readStringUntil('\n');
  myPort.bufferUntil('\n');

  // Load a soundfile from the data folder of the sketch and play it back in a loop
  file = new SoundFile(this, "Ex.wav");
  //file.loop();
  music_duration = (int) file.duration() * 1000;
  music_duration += 2000;

}      

void draw() {
  background(0);
  fill(255);
  text("frameCount: "+frameCount, 50, 25);
  text("dist: "+dist, 50, 50);
  text("mode: "+mode, 50, 75);


  if (frameCount == 180) {
    turn_on();
  } else if (frameCount &gt; 180) {

    if ( mode == S1_WAITING_FOR_PEOPLE) {

      if (someone_present == false) {
        if (dist &lt; no_one_when_distance_greater_then) {
          someone_present = true;
          someone_present_since_time = millis();
          change_mode(mode + 1);
        }
      }
    } else if (mode == S2_PEOPLE_ENTERED) {
      text("millis: "+millis(), 50, 100);
      text("someone_present_since_time: "+someone_present_since_time, 50, 125);
      text("time_before_dim: "+time_before_dim, 50, 150);
      if (millis() - someone_present_since_time &gt; time_before_dim) {
        change_mode(mode + 1);
      }
    } else if (mode == S3_LIGHT_FADE_OUT) {
      turn_off();
      change_mode(mode + 1);
    } else if (mode == S4_DARK) 
    {
      change_mode(mode + 1);
    } else if (mode == S5_MUSIC) 
    {
      if (is_playing == false) {
        file.play();
        is_playing = true;
        music_playing_since = millis();
      }
      if (millis() - music_playing_since &gt; music_duration) {
        is_playing = false;
        file.stop();
        change_mode(mode + 1);
      }
    } else if (mode == S6_LIGHT_FADE_IN) 
    {
      // todo
      if (millis() - in_mode_since_ms &gt; 1000) {
        change_mode(mode + 1);
      }

    } else if (mode == TERMINATE) 
    {
      change_mode(S1_WAITING_FOR_PEOPLE);
      someone_present = false; // reset
      println("turn_on();");
      turn_on();
    }
  }
}


void change_mode(int m) {
  mode = m;
  in_mode_since_ms = millis();
}



void serialEvent(Serial p) { 
  String s = p.readString();
  if (s != null) {
    s = s.replace("\r\n", "");
    if (s.contains("Distance Measured")) {
      String[] tokens = split(s, "=");
      dist = int(tokens[1]);
    }
  }
} 


void turn_on() {
  myPort.write("on");
}

void turn_off() {
  myPort.write("off");
}

void keyPressed() {
  if (key == 'a') {
    turn_on();
  }
  if (key == 's') {
    turn_off();
  }
}
</code></pre>

<p>Thanks for your effort.
Faffie</p>
]]></description>
   </item>
   <item>
      <title>Unknown issue with drawing graph with data send by arduino to Raspberry Pi</title>
      <link>https://forum.processing.org/two/discussion/24749/unknown-issue-with-drawing-graph-with-data-send-by-arduino-to-raspberry-pi</link>
      <pubDate>Thu, 26 Oct 2017 11:51:12 +0000</pubDate>
      <dc:creator>maxim221</dc:creator>
      <guid isPermaLink="false">24749@/two/discussions</guid>
      <description><![CDATA[<p>Hello!</p>

<p>I'm using arduino as ADC, which sends data through UART to Raspberry Pi model B, which draws a graph on 7'display, connected via HDMI.</p>

<p>So I've got a strange problem. 
<img src="https://forum.processing.org/two/uploads/imageupload/419/7UPQJMK8SSJH.PNG" alt="pic1" title="pic1" />
Randomly straight lines appear from current measuring point to top of the screen.</p>

<p>I was thinking about mistakes or zero values or Nan values of something like that. But it is not-)</p>

<p>Lines drawn like that:</p>

<p><code>line(xPos-1, height-lastfValue, xPos, height - fValue);</code></p>

<p>I was trying to filter it out by using such a construction:</p>

<pre><code>if(fValue &lt;= 0 || (height - fValue) &gt; height || ((fValue - lastfValue)*(fValue - lastfValue)/2) &gt; lastfValue + 5 ){
    fValue = lastfValue;
    }
</code></pre>

<p>It helped a little, but did't became a solution for my problem. So I tried to figure out a problem and added pdf export of what I see on the screen and logging values of "fValue" to console and find out:</p>

<p>The values:</p>

<pre><code>145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
146.04106
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
</code></pre>

<p>and the graph:</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/787/SFMDC2MDA7NK.jpg" alt="-DLm7tClrdw" title="-DLm7tClrdw" /></p>

<p>As you can see there only one different value and two peaks on the graph.</p>

<p>Does anyone know how to deal with it and get a correct graph?</p>

<p>This code works the same way on my notebook..</p>

<p>Here is the code I use for processing on raspberry Pi:</p>

<pre><code>import processing.serial.*;
import processing.pdf.*;

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph

float fValue;
float lastfValue;
boolean newVal = false;

void setup () {
  size(1000, 300);
 // fullScreen();

  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 115200);
  myPort.bufferUntil('\n');
  background(28,28,28);
  beginRecord(PDF, "rawData.pdf");
}

void draw () {
//  if (newVal) {
    stroke(255, 16, 0);
   // size(100, 100, P3D);
   // noSmooth();
    //ellipse(xPos, height - fValue, 1, 1);
    line(xPos-1, height-lastfValue, xPos, height - fValue);
    println(fValue);
    lastfValue = fValue;
    //fValue = (fValue - 3);
    //stroke(28, 28, 28);
    //point(xPos, height - fValue);
    if (++xPos &gt;= width) {
      xPos = 0;
      background(28,28,28);
//    }
//    newVal = false;
  }
}

void serialEvent (Serial myPort) {
  String inString = myPort.readStringUntil('\n');
  if (inString != null) {
    inString = trim(inString);
    fValue = float(inString);
    fValue = map(fValue, 0, 1023, 0, height);
    //if(fValue &lt;= 0 || (height - fValue) &gt; height || ((fValue - lastfValue)*(fValue - lastfValue)/2) &gt; lastfValue + 5 ){
    //fValue = lastfValue;
    //}
  }
//  newVal = true;
}
  void keyPressed() {
  if (key == ' ') {
    endRecord();
    exit();
  }
}
</code></pre>

<p>Here is the code for arduino Uno that I use as ADC:</p>

<pre><code>// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>android serial usb arduino hiccups?</title>
      <link>https://forum.processing.org/two/discussion/24989/android-serial-usb-arduino-hiccups</link>
      <pubDate>Mon, 13 Nov 2017 16:54:07 +0000</pubDate>
      <dc:creator>vagos21</dc:creator>
      <guid isPermaLink="false">24989@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone, i've been working with processing and the android mode for a few days now, and i decided to do this little sensors report when i plug in my android phone to my arduino. i set up the manifest with the vendor IDs and everything and it all works fine but...</p>

<p>even though the arduino Tx lights up continuously (sends data all the time) the processing software looks like it's getting data for a couple of seconds, then looks completely idle for 10 seconds, then takes data again, then no comminucation again... i know the app is not freezing because i'm doing a sliding graph, which happily slides along. any idea what could be causing this hiccup? a buffer overrun?</p>

<p>to be honest i'm trying to make something like a semi-fast DMM, and right now the arduino sends 2 values every 100ms, <a href="/two/profile/38400">@38400</a> baud. is this too fast for the app to handle?</p>

<p>forgive me for the following, but i can't find a code format button...? :D</p>

<p>this is the arduino code:</p>

<pre><code> void setup() {
   Serial.begin(38400);
   pinMode(A0,INPUT);
   pinMode(A1,INPUT);
}

void loop() {
  Serial.print(analogRead(A0));
  Serial.print(";");
  Serial.println(analogRead(A1));
  delay(150);
}
</code></pre>

<p>and the android side:</p>

<pre><code>import io.inventit.processing.android.serial.*; //ANDROID

//SERIAL PORT
Serial myPort;      //thermostat serial port
String inString=""; //input string from serial port

//FONTS
PFont dateFont;           //date font

//REALTIME DATA
float v1 = 0.0;  //voltage1
float v2 = 0.0;  //voltage2

//COLORS
color activeText = color(182, 230, 244);
color inactiveText = color(60, 60, 60);

//BUTTONS
transButton resetBtn = new transButton( width/2, height-50, 200, 50, "Reset");


void setup() {
  fullScreen();
  orientation(LANDSCAPE);
  frameRate(200);

  //init fonts
  dateFont = createFont("WalkwayBold.ttf", 60);

  //init USB serial port
  myPort = new Serial(this, Serial.list(this)[0], 38400); //ANDROID
  myPort.bufferUntil(10);
}

//===========INCOMING DATA FROM THERMOSTAT=============
void serialEvent(Serial myPort) { 
  try {
    inString = myPort.readString();
    String[] list = split(inString, ';');
    v1 = float(list[0])/1024.0;
    v2 = float(list[1])/1024.0;
  }
  catch(RuntimeException e) {
    e.printStackTrace();
  }
}

//===============MAIN LOOP===================
void draw() {
  //timeNow = millis();
  drawMainScreen();
}


//===============DRAWING LOOP===================
void drawMainScreen() {
  background(36,93,142);

  //voltage 1
  fill(255);
  textFont(dateFont);
  textAlign(LEFT, CENTER);
  text("v1: " + v1 + "V", 50, 20);

  //voltage 2
  fill(255);
  textFont(dateFont);
  textAlign(LEFT, CENTER);
  text("v2: " + v2 + "V", 50, 80);

  //raw serial input
  fill(255);
  textFont(dateFont);
  textAlign(CENTER, TOP);
  text("raw: " + inString, 700, 20);
</code></pre>
]]></description>
   </item>
   <item>
      <title>Play video using Processing, Arduino and PIR Sensor</title>
      <link>https://forum.processing.org/two/discussion/25365/play-video-using-processing-arduino-and-pir-sensor</link>
      <pubDate>Sun, 03 Dec 2017 22:41:30 +0000</pubDate>
      <dc:creator>m4rdones</dc:creator>
      <guid isPermaLink="false">25365@/two/discussions</guid>
      <description><![CDATA[<p>Hi. A friend and I are in the middle of a video installation tests. I'm using an Arduino PIR Sensor and an Arduino Uno board.</p>

<p>I need to stop a video when the PIR is "On" (Detects motion) and to play that video if the PIR is "Off".</p>

<p>Checking the Processing and Arduino websites, examples and references I couldn't figured out what I'm doing wrong.
Please let me know if something is missing or left.
Thanks in advance for any help!</p>

<p>This is the Arduino Code (copied from Arduino and Processing communication tutorials found on the web):</p>

<pre><code>/*
   PIR sensor tester
*/

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input

  Serial.begin(9600);
}

void loop() {
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH) {
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}
</code></pre>

<p>And here is the Processing code:</p>

<pre><code>import processing.serial.*;
import processing.video.*; 

Serial myPort;
String val;    

Movie video;

void setup() {
  size(640,480);
  video = new Movie(this,"sujeto1.mp4");
  video.loop();
  String portName = Serial.list()[0];
  myPort = new  Serial(this, portName, 9600);
  myPort.bufferUntil('\n');
}

void serialEvent (Serial myPort) {
  if (myPort.available() &gt; 0) {
    val=myPort.readStringUntil('\n');
  }
  if (val=="Motion detected!") {
    video.stop();
  } else {
    video.loop();
  }
  println(val);

}
void draw() {
  background(0);
  image(video,0,0);

} 

void movieEvent(Movie video) {
  video.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Serial not working</title>
      <link>https://forum.processing.org/two/discussion/24898/serial-not-working</link>
      <pubDate>Tue, 07 Nov 2017 16:47:11 +0000</pubDate>
      <dc:creator>plux</dc:creator>
      <guid isPermaLink="false">24898@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I've been writing this code since yesterday and it was fine until now. I don't know what happened but the SerialEvent() is never triggered. Context:
win10 x64, using a bluetooth HC-06 module with arduino. Tested with Bluetooth serial terminal application and all working. In processing, the COM port selected is correct (doesn't throw any error) but the SerialEvent() is <strong>never</strong> triggered therefore no values are received by processing. This was working perfectly an hour ago and I have no idea why it does not work anymore. Basically the BT module is always blinking (which means it's not connected). It used to stop blinking when I run the application (and data was received)</p>

<p>This is extract of my code. None of the print statement inside serialEvent() are actually ever exectued. Again, I receive the values correctly if I run the <a rel="nofollow" href="https://www.microsoft.com/en-us/store/p/bluetooth-serial-terminal/9wzdncrdfst8">Bluetooth Serial Terminal application</a></p>

<pre><code>void setup(){
    size(800, 800, P3D);
    //fullScreen(P3D, 1);

    // OSC stuff
    oscP5 = new OscP5(this, 10000);
    destination = new NetAddress("127.0.0.1", oscPort);

    //Serial stuff
    String portName = Serial.list()[1];
    my_port = new Serial(this, portName, 9600);
    my_port.bufferUntil('\n');

    background(0);
}

void serialEvent(Serial my_port){
  println("MESS");
  if(my_port != null){
    String str = my_port.readStringUntil('\n');

    if(str.charAt(0) == '#'){
      str = trim(str.substring(1));

      int gyro[] = int(split(str,','));

      for(int i = 0; i &lt; gyro.length;i++){
          gyroVals[i] = (int) map(gyro[i], 0, 360, -180, 180);
          print(i + ": " + gyroVals[i] + " // "); 
      }  
        println();
    }
  } 
} //serialEvent
</code></pre>
]]></description>
   </item>
   <item>
      <title>Two buttons cueing two audio files with Minim</title>
      <link>https://forum.processing.org/two/discussion/25039/two-buttons-cueing-two-audio-files-with-minim</link>
      <pubDate>Thu, 16 Nov 2017 01:55:34 +0000</pubDate>
      <dc:creator>lasleys</dc:creator>
      <guid isPermaLink="false">25039@/two/discussions</guid>
      <description><![CDATA[<p>I'm a noob trying to get two switch buttons on an Arduino to be able to repeatedly cue two audio samples in Processing. I can get the audio files to play once each, and I imagine I need to reload the player after it finishes playing, but when I try to add <code>player = minim.loadFile("pool splashing.mp3");</code>  to the end of the if statement that plays the file, it makes the audio terribly distorted and slow. Something is definitely wrong in my code. Strangely, when I add <code>player2 = minim.loadFile("nature sounds.mp3");</code> to the second if statement that plays it, the button no longer works. What am I missing? Thanks in advance.</p>

<p>Arduino code:</p>

<pre><code>int switchPin1 = 4;                      
int switchPin2 = 2;
int buttonState = 0;  

void setup() {

  pinMode(switchPin1, INPUT_PULLUP);             
  pinMode(switchPin2, INPUT_PULLUP);             
  Serial.begin(9600);                   
}

void loop() {

  if (digitalRead(switchPin1) == LOW) {  
    Serial.println("1");              
  }

  if (digitalRead(switchPin2) == LOW) { 
    Serial.println("2");            

  delay(100);                           
}
</code></pre>

<p>and my Processing code:</p>

<pre><code>import processing.serial.*;
import ddf.minim.*;

Serial myPort; 
Minim minim;
AudioPlayer player;
AudioPlayer player2;
String val;     // data received from the serial port


void setup(){
  size(500,500);
  myPort = new Serial(this, "/dev/cu.usbmodem1411", 9600);
  myPort.buffer(1);
  minim = new Minim(this);
  player = minim.loadFile("pool splashing.mp3");
  player2 = minim.loadFile("nature sounds.mp3");

}

void draw(){

}

void serialEvent (Serial myPort){
println(val);
if ( myPort.available() &gt; 0)
 {  // if data is available,
  val = myPort.readString();         // read it and store it in val
  }
  println(val); //print it out in the console

    if(val.equals("1")){
      player.play();
      println("song1");

    }

    if(val.equals("2")){
      player2.play();
      println("song2");
    }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>"Error, disabling serialEvent() for COM6 null"</title>
      <link>https://forum.processing.org/two/discussion/25083/error-disabling-serialevent-for-com6-null</link>
      <pubDate>Sat, 18 Nov 2017 22:16:02 +0000</pubDate>
      <dc:creator>hbara</dc:creator>
      <guid isPermaLink="false">25083@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I have a program that was working fine in processing 2.x.x but wont work with 3.x.x. None of the text or tracings show up. While initializing, it looks like it hits a roadblock and throws the error "Error, disabling serialEvent() for COM6
null" in the console. Any ideas on how to troubleshoot?</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Read Potentiometer/Serial from Arduino on processing</title>
      <link>https://forum.processing.org/two/discussion/24915/read-potentiometer-serial-from-arduino-on-processing</link>
      <pubDate>Wed, 08 Nov 2017 16:46:40 +0000</pubDate>
      <dc:creator>DeDaymar</dc:creator>
      <guid isPermaLink="false">24915@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys,</p>

<p>I'm working on a code which if written correctly should be able to print the value of my potentialmeter on processing. And then I dont mean with a flowing colour screen, that I can find on the internet. I want to print on the screen the number of the potentialmeter, and when I turn the wheel it, the number on processing should change.</p>

<p>I think my code does connect to the potentiometer and does print it on processing, but it keeps overwriting, the numbers dont change. It just literally writes over the previous numbers.</p>

<p><strong>My arduino code :</strong></p>

<pre><code>void setup() {
 //initialize the serial communication:
 Serial.begin(9600); } 
void loop() {
 //send the value of analog input 0:
 Serial.println(analogRead(A0));
//wait a bit for the analog-to-digital converter to stabilize after last 
//reading: delay(2); } 
</code></pre>

<p>My processing code</p>

<pre><code> import processing.serial.*;
Serial myPort;
PFont myFont;
float val;
int[] pin_val;
int lf = 10;
boolean received;
float inByte = 0;

void setup() {      

size(325,400);

fill(51,153,255);


rect(10,10,300,150);

myFont = createFont("Arial", 18);

textFont(myFont, 18);

println(Serial.list());

myPort = new Serial (this, Serial.list()[0], 9600);

pin_val = new int[0];

val = 0;

received = false;

}

void draw()

{
textSize(30);

fill(255,0,0);

textAlign(CENTER);

textFont(myFont, 18);

text("received:   "+inByte, 160,50 );                                                             //This is where I believe my fault is.
fill(255,255,255);

ellipse(162.5,260,80,80);
}

void serialEvent (Serial myPort)
 {
String inString = myPort.readStringUntil('\n');

if (inString!= null) {

// trim off any whitespace;

inString = trim(inString);

//convert to an int and map to the screen height:

inbyte = float(inString);

println(inByte);

inByte = map(inByte, 0, 1023, 0, height);

}
}
</code></pre>

<p>I know there is a blue rectangle and a white ellips, but that's part of my homework.</p>
]]></description>
   </item>
   <item>
      <title>Toggling between two videos in array with GLvideo</title>
      <link>https://forum.processing.org/two/discussion/24813/toggling-between-two-videos-in-array-with-glvideo</link>
      <pubDate>Tue, 31 Oct 2017 00:09:46 +0000</pubDate>
      <dc:creator>everyday90</dc:creator>
      <guid isPermaLink="false">24813@/two/discussions</guid>
      <description><![CDATA[<p>need a bit of help with this code. I'm trying to adapt a sketch I made originally for my laptop with the video library. It's pretty simple, I'm reading the values 1 and 0 from the serial port and switching between two synched clips each time there's a change. I'm not having such successful results trying to recreate this with GLVideo however, which I've never used before. hopefully I can fairly easily achieve what I want?</p>

<p>thanks for any help you might have</p>

<pre><code> import processing.serial.*;
 Serial myPort;
 int val=0;
 import gohai.glvideo.*;
 GLMovie[]video = new GLMovie [2];
 int i =0;

 void setup() {
   fullScreen(P2D);
   String portName = Serial.list()[0];
   myPort= new Serial (this, portName,115200);
   video [0] = new GLMovie(this, "low.mp4");
   video [1] = new GLMovie (this, "high.mp4");
   video [i].loop(); 
 }

 void draw() {
  image(video[i],0,0,width,height); 
  if (video[i].available()) {
     video[i].read(); 
   }
 } 
   void serialEvent(Serial p) {
     if (myPort.available()&gt;0) {
       val=myPort.read();
       println(val); 
 }
 if (val==0) {
   i=1;
 }
 else {
   i=0;
 }
   }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Port get busy after a few times running. Is it because of P3D?</title>
      <link>https://forum.processing.org/two/discussion/24569/port-get-busy-after-a-few-times-running-is-it-because-of-p3d</link>
      <pubDate>Sun, 15 Oct 2017 23:56:57 +0000</pubDate>
      <dc:creator>TuangPing</dc:creator>
      <guid isPermaLink="false">24569@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I have come to a problem of having error from using Window 7 with arduino Leonado sending data through Serial port.
I tested a code that getting only the data from both Mac and Window and it works fine. Then I make a video to put on a canvas for Spout to project it out to other program. Note that with syphon everything works fine too. I have ran into a post somewhere that posted long ago that a guy had the same problem of mine and he fixed it by changing to openGL but I also learned that openGL now is the same as P3D from a more recent post here in this forum. ** I didn't run anything at the same time of processing.** First time running usually fine, but for the second or third then the error will say that my port is busy! And I will have no choice but  restart the computer again. !!!! Is this a bug? Is there a solution?</p>

<p>Here is the code that runs fine on both operation</p>

<pre><code>import processing.serial.*;
Serial myPort ;
int value, wheel;
String myString = null;
int weight = 800;
int lf = 10;

void setup() {
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[1], 9600);
  myPort.clear();
  myPort.bufferUntil(lf);
  myString = myPort.readStringUntil(lf);
}
void draw() {
println("in draw once");
 println("fsr: "+ value);
    println("wheel position: "+ wheel);
    println("-----------");
}

void serialEvent(Serial p) {
  //println("access Serial port");
  myString = p.readStringUntil('\n');
  if (myString !=null) {
    //println("get data from Serial port");
    String[] fsr =split(myString, 'r');
    //printArray(fsr);
    value = int(fsr[0]);
    String trim = trim(fsr[1]);
    wheel = int(trim);

  }
}
</code></pre>

<p>And this is a code that has a problem in Window 7 (x64)</p>

<pre><code>import spout.*;// IMPORT THE SPOUT LIBRARY
import processing.serial.*;//Serial to Arduino
import processing.video.*;//play vdo

int nSenders = 5;
PGraphics[] canvas;
Spout[] senders;

int lf=10;
Serial myPort;
int value, wheel;
String myString = null;
Movie myMovie;
int arduinoValue = 800;

int projectorWidth = 1024;
int projectorHeight = 768;
//int scalar = 3;

//-----swtiches------//
Boolean arduinoSwitch = true;
Boolean sensorSwitch = false;
Boolean spoutSwitch = true;
//-----------//

void settings() {
  size(projectorWidth, projectorHeight,P3D);
  // size is doesn't change the size of canvas in term of sending graphic signal out.
}
void setup() {
  canvas = new PGraphics[nSenders];
  for (int i=0; i&lt;nSenders; i++) {
    canvas[i] = createGraphics(projectorWidth, projectorHeight, P3D);
  }
  printArray(Serial.list());

  // Create Spout senders to send frames out.
  if (spoutSwitch) {
    senders = new Spout[nSenders];
    for (int i = 0; i &lt; nSenders; i++) { 
      senders[i] = new Spout(this);
      String sendername = "Test "+i;
      senders[i].createSender(sendername, projectorWidth, projectorHeight);
    }
  }  
  if (arduinoSwitch) {
    myPort = new Serial(this, Serial.list()[1], 9600);
    myPort.clear();
    myPort.bufferUntil(lf);
    myString = myPort.readStringUntil(lf);
  }
  myMovie = new Movie (this, "C:/Users/dma/Desktop/tuang/test1.mp4");
}

void draw() {
  canvas[0].beginDraw();
  canvas[0].background(255, 0, 100);
  canvas[0].image(myMovie, 0, 0);
  if (spoutSwitch) {
    for (int i = 0; i &lt; nSenders; i++) {
      senders[i].sendTexture(canvas[i]);    //send all separated spout canvases
    }
  }
  if (arduinoSwitch) {
    println("fsr: "+value);
    println("position wheel: "+wheel);
    if (value &lt; arduinoValue) {
      sensorSwitch=true;
      myMovie.stop();
      canvas[0].background(0);
      println("nothing in the house");
    }
    if (sensorSwitch) {
      if (value&gt;=arduinoValue) {
        println("Force sensor is detacted");
        //newRandom=true;
        //randomMovie();
        myMovie.play();
        sensorSwitch=false;
      }
    }
  }
  canvas[0].endDraw();
  image(canvas[0], 1024/2*(0%2), 768/2*(0/2));
}
void movieEvent(Movie m) {
  m.read();
}

void serialEvent(Serial p) {
  if (arduinoSwitch) {
    myString = p.readStringUntil('\n');
    if (myString != null) {
      String[] fsr = split(myString, 'r');
      //printArray(fsr);
      value = int(fsr[0]);
      String trim = trim(fsr[1]);
      wheel = int(trim);
    }
  } else {
    println("Arduino is off.");
  }
}
//keyboard for testing vdo
void keyPressed() {
  switch (key) {
  case 'a' : 
    myMovie.play();
    break;
  case 'r' :
    myMovie.stop();
    break;
  }
}
</code></pre>

<p>What should I do to stop the port being too busy ! I didn't even run anything but processing.</p>
]]></description>
   </item>
   <item>
      <title>How do I receive multiple values through Processing from the Arduino Serial Monitor</title>
      <link>https://forum.processing.org/two/discussion/24307/how-do-i-receive-multiple-values-through-processing-from-the-arduino-serial-monitor</link>
      <pubDate>Fri, 29 Sep 2017 09:13:36 +0000</pubDate>
      <dc:creator>ash8</dc:creator>
      <guid isPermaLink="false">24307@/two/discussions</guid>
      <description><![CDATA[<p>Hi experts, newbie here,</p>

<p>I am having trouble reading data from the serial monitor sent by my Arduino in processing.
Im not sure how to read multiple values.</p>

<p>Here is my Arduino data being sent to the serial monitor (9600 baud):</p>

<p><code>Serial.print(LeftSensor);
Serial.print(',');
Serial.print(FrontSensor);
Serial.print(',');
Serial.print(RightSensor);</code></p>

<p>Here is my processing serial reading function:</p>

<pre><code>import processing.serial.*;
Serial port;
float center = 0;
float left = 0;
float right = 0;


void setup(){
size(480, 300); // AqT arduino quad test
port = new Serial(this, "/dev/cu.usbmodem1421", 9600);
port.bufferUntil('\n');
}

void serialEvent()
{ 
  int newLine = 13; // new line character in ASCII
  String message;
  do {
    message = port.readStringUntil(newLine); // read from port until new line
    if (message != null) {
      String[] list = split(trim(message), " ");
      if (list.length &gt;= 4 &amp;&amp; list[0].equals("Stuff: ")) {
        //yaw = float(list[1]); // convert to float yaw
        //pitch = float(list[2]); // convert to float pitch
        left = float(list[1]);
        center = float(list[2]);
        right = float(list[3]);
        roll = float(list[4]);
      }
      else{
      rect(20, 20, 20, 20);
      }
    }
  } while (message != null);
}

void draw(){
  serialEvent();  
}
</code></pre>

<p>When I try the code out, Processing reads nothing but the arduino works fine in terms of output.</p>

<p>Please help,</p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>Why can't I get the option pane to show.</title>
      <link>https://forum.processing.org/two/discussion/24430/why-can-t-i-get-the-option-pane-to-show</link>
      <pubDate>Sat, 07 Oct 2017 12:29:01 +0000</pubDate>
      <dc:creator>stumped1</dc:creator>
      <guid isPermaLink="false">24430@/two/discussions</guid>
      <description><![CDATA[<p>A newby and my first time using Processing and I can't see how I can resolve this. I'm trying to set up a CNC drawing setup in arduino uno and the Processing option pane is not displaying correctly. I've attached a screenshot and it appears a fault is shown at line 31. 
Would greatly appreciate any help<img src="https://forum.processing.org/two/uploads/imageupload/412/C67EN4DZYET8.png" alt="Screenshot (5)" title="Screenshot (5)" /></p>
]]></description>
   </item>
   <item>
      <title>loosing or gaining bytes through serial</title>
      <link>https://forum.processing.org/two/discussion/24268/loosing-or-gaining-bytes-through-serial</link>
      <pubDate>Tue, 26 Sep 2017 15:21:54 +0000</pubDate>
      <dc:creator>w4lt3r</dc:creator>
      <guid isPermaLink="false">24268@/two/discussions</guid>
      <description><![CDATA[<p>hello</p>

<p>I have a issue that Processing isn't reading out all(or too much) of the data it gets.</p>

<p>I am sending data from the arduino(in this case just the numbers 1-6) and want to read them out in processing. the Baudrate has some  effect but above and below 9600 it gets worse. I had in the past a delay in the arduino code, it didn't worked out neither.
 the catch(nullPointerException e) is there to catch strings that are 0, happened too in the past.</p>

<p>if i use other tools to read out the data from the serial such as the arduino serial monitor or Tera Term then there are no missing character/bytes.</p>

<p>SerialEvent doesn't trigger at all(with bufferuntil(10) or ('\n').</p>

<p>I hope someone has some ideas where the bug is crawling around.</p>

<p>walter</p>

<p>the processing code;</p>

<p>```
    import processing.serial.*;</p>

<pre><code>Serial myPort;        // The serial port
int xPos = 1;
int i,j,h,ii;         // horizontal position of the graph 
int lastxPos=1;
int lastheight=0;
int xPos1 = 1;         // horizontal position of the graph 
int lastxPos1=1;
int lastheight1=0;

String a="0";
int n=5;
String[] indata={a,a,a,a,a,a,a};//new String[6];
String[] indata2=new String[7];
  String InString;
int[] rawdata=new int[7];
float[] data=new float[7];
PrintWriter output;
//Variables to draw a continuous line.


int lf= 10;



public static final int portIndex=1;

void setup () {
  output= createWriter("output");
  // List all the available serial ports
  println(Serial.list());
  // Check the listed serial ports in your machine
  // and use the correct index number in Serial.list()[].
  println(" Connecting to -&gt; " + Serial.list()[portIndex]);
  myPort = new Serial(this, Serial.list()[portIndex], 9600);  //
  delay(3000);
  myPort.write(65);
  // A serialEvent() is generated when a newline character is received :
  myPort.bufferUntil('\n');
  background(7000);      // set inital background:
//  delay(100);
}

void draw(){

//print(InString);
  InString=myPort.readStringUntil('\n');
  print(InString);

  try{
     indata2=split(trim(InString)," ");
  for(int ii=0;ii&lt;indata2.length;ii++){  _**here the error is created**_
    indata[ii]=indata2[ii];
  }}
    catch(NullPointerException e){println("error invalid array");}
  for(int j=0;j&lt;indata.length;j++){
  rawdata[j]=int(trim(indata[j]));
  }
 //  println(rawdata);
 //  println(interval);
}
</code></pre>

<p>the arduino code:</p>

<pre><code>void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  for(int i=0;i&lt;7;i++){
Serial.print(i);
Serial.print("\r"" ");
  }
  Serial.print('\n');
}
</code></pre>

<p>and a typical output</p>

<p>5 61 2 3 4 5 6</p>

<p>0 1 2 3 4 5 6</p>

<p>0 0 1 2 3 4 5 6
or
0 1 2 3 4 5 6 1 2 3 4 5 6</p>
]]></description>
   </item>
   <item>
      <title>Convert String to float for drawing graph</title>
      <link>https://forum.processing.org/two/discussion/24220/convert-string-to-float-for-drawing-graph</link>
      <pubDate>Fri, 22 Sep 2017 19:39:28 +0000</pubDate>
      <dc:creator>pleink</dc:creator>
      <guid isPermaLink="false">24220@/two/discussions</guid>
      <description><![CDATA[<p>Hay everyone
I'm new here and I hope someone can help me with my little issue.
On my arduino is a sensor attached, that works fine. Also the transmission from the Arduino to the Processing program. The information comes as a String variable "val". To draw the graph I need to convert the variable into a float typ. I tried it with "Float.parseFloat(val)" but that didn't worked.</p>

<pre><code>import processing.serial.*;
Serial myPort;
Table table;

int numReadings = 100; //8640000 = One day
int readingCounter = 0;

String val;

float y = 0;
float t = 20;


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

  myPort = new Serial(this, Serial.list()[0], 9600);
  table = new Table();

  table.addColumn("id");
  table.addColumn("month");
  table.addColumn("day");
  table.addColumn("hour");
  table.addColumn("minute");
  table.addColumn("second");

  table.addColumn("sensor1");

  size(1000, 1000);
  frameRate(10);
}

void draw() {

  if ( val != null) {
    y = Float.parseFloat(val);

  } else {
    y = 0;
  }
  rect(t, y, 5, 5);
  t = t + 5;
}

void serialEvent(Serial myPort) {

  try {
    String val = myPort.readStringUntil('\n');
    if (val!= null) {
      val = trim(val);
      println(val, y);  //Control
      float sensorValue[] = float(split(val, ','));

      TableRow newRow = table.addRow();
      newRow.setInt("id", table.lastRowIndex());

      newRow.setInt("month", month());
      newRow.setInt("day", day());
      newRow.setInt("hour", hour());
      newRow.setInt("minute", minute());
      newRow.setInt("second", second());

      newRow.setFloat("sensor1", sensorValue[0]); 
      println(table.lastRowIndex());

      readingCounter++;

      if (readingCounter == numReadings) {
        saveTable(table, "data/new.csv");
      }
    }
  }
  catch(RuntimeException e) {
    e.printStackTrace();
  }
}
</code></pre>

<p>In the console comes the following:</p>

<pre><code>    177 0.0
    java.lang.NullPointerException
        at Processing_uebertragung.serialEvent(Processing_uebertragung.java:73)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at processing.serial.Serial.serialEvent(Unknown Source)
        at jssc.SerialPort$EventThread.run(SerialPort.java:1112)
    179 0.0
    0
    181 0.0
    1
    183 0.0
    2
    185 0.0
    3
    186 0.0
    4
    188 0.0
    5
    190 0.0
</code></pre>

<p>sorry for my bad english.
 8-|</p>
]]></description>
   </item>
   <item>
      <title>when i play nine mp4s using video library,the nineth mp4 can't play as other eight mp4.</title>
      <link>https://forum.processing.org/two/discussion/24050/when-i-play-nine-mp4s-using-video-library-the-nineth-mp4-can-t-play-as-other-eight-mp4</link>
      <pubDate>Thu, 07 Sep 2017 05:23:47 +0000</pubDate>
      <dc:creator>Ryan</dc:creator>
      <guid isPermaLink="false">24050@/two/discussions</guid>
      <description><![CDATA[<pre><code>import processing.video.*;  
import processing.serial.*; 
Serial myPort;
int[] valr={1021,1021,1021,1021,1021,1021,1021,1021,1021};
Movie[] endmovie = new Movie[9];
void setup(){  
  fullScreen();
  for(int i = 0;i&lt;9;i++){
endmovie[i] = new Movie(this,"b"+i+".mp4");
  }
  myPort = new Serial(this,Serial.list()[0], 9600);
  myPort.bufferUntil('\n');  //buffer until meet '\n', then call the event listener

}  

void draw(){
  image(endmovie[0],0,0,width/3,height/3);
  image(endmovie[1],width/3,0,width/3,height/3);
  image(endmovie[2],width*2/3,0,width/3,height/3);
  image(endmovie[3],0,height/3,width/3,height/3);
  image(endmovie[4],width/3,height/3,width/3,height/3);
  image(endmovie[5],width*2/3,height/3,width/3,height/3);
  image(endmovie[6],0,height*2/3,width/3,height/3);
  image(endmovie[7],width/3,height*2/3,width/3,height/3);
  image(endmovie[8],width*2/3,height*2/3,width/3,height/3);
for(int i = 0;i&lt;9;i++){
  endmovie[i].play();
   if(valr[i]&gt;500){
endmovie[i].speed(1.0);
   }else{
endmovie[i].speed(-1.0);
   }
 }
}

void movieEvent(Movie m){
  m.read();
}  

void serialEvent(Serial p) {  
  String inString = p.readString();  
  print(inString);
  if(inString!=null){
   String[] rec= split(inString, ',');
   for(int i=0;i&lt;9;i++){
 valr[i]=int(rec[i]);
   }  
  }  
}  
</code></pre>
]]></description>
   </item>
   <item>
      <title>Serial parsing from eeg string</title>
      <link>https://forum.processing.org/two/discussion/23983/serial-parsing-from-eeg-string</link>
      <pubDate>Thu, 31 Aug 2017 16:01:57 +0000</pubDate>
      <dc:creator>iiyeo</dc:creator>
      <guid isPermaLink="false">23983@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone, I am doing a brainwave eeg project now and I have already got the raw brainwave values in Arduino. It is a string of 11 values. But when I want to parse the eeg string in processing, I got the error 'disabling serialEvent() for /dev/cu.usbmodem1411 null'. I am quite new to processing and I totally have no idea about that. Is there anyone could help me to see this code? Thanks in advance. Sorry for my English if there is any mistake.</p>

<p>PS: I even didn't get the 11 varying values in the below monitor. I can only get data like this:
    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0</p>

<p>Here is the code:</p>

<pre><code>import processing.serial.*;
Serial serial;

int signal_strength;
int attention; 
int meditation; 
int delta;
int theta;
int low_alpha;
int high_alpha; 
int low_beta;
int high_beta;
int low_gamma; 
int high_gamma;  


void setup() {


  println("Find your Arduino in the list below, note its [index]:\n");

  for (int i = 0; i &lt; Serial.list().length; i++) {
    println("[" + i + "] " + Serial.list()[i]);
  }

  serial = new Serial(this, Serial.list()[3], 9600);
  serial.bufferUntil(10);

}

void draw() {

  println(signal_strength, attention, meditation, delta, theta, low_alpha, high_alpha, low_beta, high_beta, low_gamma, high_gamma);

}

void serialEvent(Serial serial) {

  String incomingString = serial.readString().trim();

  int[] incomingValues = int(split(incomingString, ","));
    signal_strength = incomingValues[0];
    attention = incomingValues[1];
    meditation = incomingValues[2];
    delta = incomingValues[3];
    theta = incomingValues[4];
    low_alpha = incomingValues[5];
    high_alpha = incomingValues[6];
    low_beta = incomingValues[7];
    high_beta = incomingValues[8];
    low_gamma = incomingValues[9];
    high_gamma = incomingValues[10];

  }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Serial library with Processing.py</title>
      <link>https://forum.processing.org/two/discussion/9598/serial-library-with-processing-py</link>
      <pubDate>Fri, 27 Feb 2015 00:27:53 +0000</pubDate>
      <dc:creator>ericksonla</dc:creator>
      <guid isPermaLink="false">9598@/two/discussions</guid>
      <description><![CDATA[<p>Generally, is there library documentation for the libraries with Processing.py?</p>

<p>Specifically, I'm trying to use the Serial library. Guessing the syntax from the Java documentation, I have:</p>

<pre lang="python">
add_library('serial')

def setup():
    #setup the serial port
    print Serial.list()
    portIndex = 4
    LF = 10
    print "Connecting to ", Serial.list()[portIndex]
    myPort = Serial(Serial.list()[portIndex], 9600)   # this seems to need a first argument referring to the sketch object (analagous to "this" argument in Java)
    myPort.bufferUntil(LF)
    
def draw():
    pass
    
def serialEvent(evt):
    inString = evt.readString()
    print inString
</pre>

<p>Anyone have any advice on making this work?</p>

<p>As a side note, it would be nice to add a processing.py as a subcategory in the forums under "Questions and Modes".</p>
]]></description>
   </item>
   <item>
      <title>Working on a code to take input from an Arduino and display the data using Processing.</title>
      <link>https://forum.processing.org/two/discussion/23295/working-on-a-code-to-take-input-from-an-arduino-and-display-the-data-using-processing</link>
      <pubDate>Mon, 03 Jul 2017 11:08:57 +0000</pubDate>
      <dc:creator>bsmyname</dc:creator>
      <guid isPermaLink="false">23295@/two/discussions</guid>
      <description><![CDATA[<p>I have a code written in Arduino that turns the led off and on using if statements.  It displays in the serial monitor the status of the LED and its "input".  It displays 'LED is ON.' 'LED is OFF.' or 'Invalid' depending on what would be the input from the user.  Currently it's automated so I can leave it alone and it scrolls through on off and then invalid every two seconds so I can work on the Processing code.  In Processing, I can bring in the data and display each result once but the code either gets stuck at the end of the loop and draw doesn't seem to run again or there is something wrong with my serial event and my string input from the Arduino doesn't update.  I have attached the Processing code if that will help in understanding what I am trying to do.</p>

<pre><code>   import processing.serial.*;
Serial port;

String serialMonitor = "LED is ON!";       //Determining empty string allows loop to run the first time
String txt = "Unknown!";
String data;
String ledOn = "LED is ON!";
String ledOff = "LED is OFF!";
String invld = "Invalid!";
PFont font;              //Activates font


void setup() {
  size(400, 400);                                          //Determines window size
  port = new Serial(this, "COM4", 9600);                   //
  port.bufferUntil('!');                                   //
  font = loadFont("AmerTypewriterITCbyBT-Medium-48.vlw");     //
  textFont(font, 48);                                     //
  frameRate(60);
}

void draw() {
  background(0);

 if (serialMonitor.equals(ledOn) == true) {
     rectMode(CENTER);
  text(serialMonitor, 200, 200, 300, 50);
  fill(234, 255, 45);                                   //When LED is on
 }

if (serialMonitor.equals(ledOff) == true) {
     rectMode(CENTER);
  text(serialMonitor,200, 200, 300, 50);
  fill(42, 20, 168);                                        //When LED is off  
 }

 if (serialMonitor.equals(invld) == true) {
     rectMode(CENTER);
  text(serialMonitor, 200, 200, 300, 50);
  fill(230, 11, 11);                                  //When input is Invalid
 }

 else {
     rectMode(CENTER);
  text(txt, 200, 200, 300, 50);
  fill(237,233,220);
 }
}

void serialEvent (Serial port) {
serialMonitor = port.readStringUntil('!');        //Reads incoming data string
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to change the stroke of my triangles with serial port data?</title>
      <link>https://forum.processing.org/two/discussion/23218/how-to-change-the-stroke-of-my-triangles-with-serial-port-data</link>
      <pubDate>Mon, 26 Jun 2017 19:02:26 +0000</pubDate>
      <dc:creator>realdapsis</dc:creator>
      <guid isPermaLink="false">23218@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm new to processing and I'm working with this code.. while I accomplished to fade the background I wonder how to change the stroke weight with the same data the background changes. Thanks in advance. This is my code:</p>

<pre><code>import processing.serial.*;
import ddf.minim.*;
import ddf.minim.signals.*;

Minim minim;
AudioPlayer mySound;

Serial port;
float brightness;



void setup() {
size(1000, 500,P3D);


String portName = Serial.list()[2];
port = new Serial(this, "/dev/cu.usbmodem1421", 9600);
port.bufferUntil('\n');
noFill();
strokeWeight(1);

minim = new Minim(this);
mySound = minim.loadFile("bb.mp3");
mySound.play();
mySound.loop();  
}
int n=0;

void draw ()
{
background (brightness, 0, 25);


translate(width/2,height/2);
for(int i = 0; i &lt; mySound.bufferSize() - 1; i++)  {

stroke(random(250),random(250),random(250));

rotateX(n*-PI/6*0.05);
rotateY(n*-PI/6*0.05);
rotateZ(n*-PI/6*0.05);


triangle (i,i,mySound.left.get(i)*50,mySound.left.get(i)*50,i,i);
}
n++;

}

void serialEvent (Serial port)
{
brightness = float (port.readStringUntil ('\n'));



}
</code></pre>
]]></description>
   </item>
   <item>
      <title>error disabling serialEvent ?</title>
      <link>https://forum.processing.org/two/discussion/23123/error-disabling-serialevent</link>
      <pubDate>Sun, 18 Jun 2017 19:18:37 +0000</pubDate>
      <dc:creator>drocobeth</dc:creator>
      <guid isPermaLink="false">23123@/two/discussions</guid>
      <description><![CDATA[<p>i am trying to talk both way round from processing to arduino as well as from arduino to processing. while processing to arduino link is absolutely fine but i guess it shows the error for arduino to processing and it reads somewhat this:
"error disabling serialEvent() for COM3 null". well i have posted my code below please tell me where i am going wrong.the prime idea is to create a GUI for bluetooth controlled bot and to send feeback from arduino to processing regarding the motor encoder to plot the movement graph(closed loop drive).</p>

<pre><code>processing:
        import processing.serial.*;
        Serial port;
             int index=0;
            String lmotor,rmotor,data,status;
            float lm=0,rm=0,xpos=0,ypos=height;
            void settings()
            {
              size(550,600);
            }
            void setup()
            {
               SecondApplet sa= new SecondApplet();
              String[] args = {"MY Sketch"};
              PApplet.runSketch(args, sa);
              port= new Serial(this, "COM3", 9600);
               port.bufferUntil('.');

        }

        void serialEvent (Serial port)
        {
          println(data);
           data=port.readStringUntil('.');
           data=data.substring(0,data.length()-1);
           index=data.indexOf(",");
           lmotor= data.substring(0, index);
           rmotor= data.substring(index+1 , data.length());
           lm=float(lmotor);
           rm=float(rmotor);
           lm=map(lm,0,9999,0,width);
           rm=map(rm,0,9999,0,height);



        }

        void octagon(int x, int y, int radius)
        {
          float angle= TWO_PI/ 8;
          beginShape();
          for(float a=0; a&lt;TWO_PI; a+= angle)
          {
            float sx= x + cos(a) * radius;
            float sy= y + sin(a) * radius;
            vertex(sx,sy);
          }
          endShape(CLOSE);
        }
        void draw() {
          background(245, 255, 245);
          fill(20 , 160, 133);
          stroke(33);
          strokeWeight(3);
          rect(50, 150, 200, 100, 10);
          rect(300, 150, 200, 100, 10);
          fill(255);
          textSize(34);
          text("FORWARD" , 70,205);
          text("BACKWARD", 305, 205);
          textSize(28);
          fill(33);
          text("CURRENT STATUS:", 180, 300);
          //stop button
          fill(176, 28, 46);
          octagon(60,60, 50);
          fill(255);
          rect(30,50,60,17);
          textSize(24);
          fill(33);
          text("STOP", 30,135);
          //left arrow
           ellipseMode(CORNER);
          fill(255,77,0);
          ellipse(35,440,220,120);
          fill(255);
          beginShape();
          {
            vertex(40, 500);
            vertex(100, 450);
            vertex(100, 475 );
            vertex(240,475 );
            vertex(240,525);
            vertex(100, 525);
            vertex(100,550);
          }
          endShape(CLOSE);
           // right arrow
           ellipseMode(CORNER);
           fill(255,77,0);
           ellipse(295,440,220,120);
           fill(255);
           beginShape();
          {
            vertex(510, 500);
            vertex(450, 450);
            vertex(450, 475 );
            vertex(310,475 );
            vertex(310,525);
            vertex(450, 525);
            vertex(450,550);
          }
          endShape(CLOSE);
          if(mousePressed &amp;&amp; mouseX&gt;10 &amp;&amp; mouseX&lt;110 &amp;&amp; mouseY&gt;10 &amp;&amp; mouseY&lt;110)
          {
             port.write('0');
             stroke(255,0,0);
            strokeWeight(2);
            noFill();
            octagon(60,60, 50);
            status="STOP";
          }
          if(mousePressed &amp;&amp; mouseX&gt;50 &amp;&amp; mouseX&lt;250 &amp;&amp; mouseY&gt;150 &amp;&amp; mouseY&lt;250)
          {
            port.write('F');
             stroke(255,0,0);
            strokeWeight(2);
            fill(255);
            rect(50,150,200,100,10);
            status="FORWARD";
            }
           if(mousePressed &amp;&amp; mouseX&gt;300 &amp;&amp; mouseX&lt;500 &amp;&amp; mouseY&gt;150 &amp;&amp; mouseY&lt;250)
          {
             port.write('B');
             stroke(255,0,0);
            strokeWeight(2);
            fill(255);
            rect(300,150,200,100,10);
            status="BACKWARD";
          }
           if(mousePressed &amp;&amp; mouseX&gt;35 &amp;&amp; mouseX&lt;255 &amp;&amp; mouseY&gt;440 &amp;&amp; mouseY&lt;560)
          {
              port.write('L');
             stroke(255,0,0);
            strokeWeight(2); 
           ellipseMode(CORNER);
             fill(255);
          ellipse(35,440,220,120);  
          status="LEFT";
         }
           if(mousePressed &amp;&amp; mouseX&gt;295 &amp;&amp; mouseX&lt;515 &amp;&amp; mouseY&gt;440 &amp;&amp; mouseY&lt;560)
          {
             port.write('R');
             stroke(255,0,0);
            strokeWeight(2); 
           ellipseMode(CORNER);
             fill(255);
         ellipse(295,440,220,120);
         status="RIGHT";
         }
          if(status=="FORWARD")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,140,380);
          }
          if(status=="BACKWARD")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,120,380);
          }
          if(status=="RIGHT")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,200,380);
          }
          if(status=="LEFT")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,230,380);
          }
          if(status=="STOP")
          {
            textSize(70);
          fill(random(0,255),0,random(0,255));
          text(status,210,380);
          }



        }
        public class SecondApplet extends PApplet {




          public void settings() {
            size(550, 600);
          }
          public void setup()
          {
            background(0);
          }
          public void draw()
          {
             stroke(255);
          strokeWeight(5);
           line(xpos,ypos,lm,height-rm);
          xpos=lm;
          ypos=height-rm;
          if(lm&gt;=width-1)
          {
            xpos=0;
            lm=0;
            background(0);
          }
          if(rm&gt;=height-1)
          {
            ypos=0;
            rm=0;
            background(0);
          }



      }
    }
</code></pre>

<p>arduino code:
        #include &lt;avr/io.h&gt;
        #include &lt;util/delay.h&gt;</p>

<pre><code>#define SETBIT(ADDRESS, BIT) (ADDRESS|=(1&lt;&lt;BIT));
#define CLEARBIT(ADDRESS, BIT) (ADDRESS&amp;=~(1&lt;&lt;BIT));
#define CHECKBIT(ADDRESS, BIT) (ADDRESS &amp; (1&lt;&lt;BIT));
char val,c;
int sfl=0,sfr=0,temp,y=0;

void interrupt_init()
{
  cli();
  EIMSK=0x03;
  EICRA=0x0A;
  sei();

}
void encoder_pin_config_init()
{
  DDRD=DDRD &amp; 0xF3;
  //INTERNALPULLUPS
  SETBIT(PORTD, PD3);
  SETBIT(PORTD, PD2);
}
void byte_init (int baud)
{
    UBRR0H = (baud&gt;&gt;8);                      // shift the register right by 8 bits
    UBRR0L = baud;                           // set baud rate
    UCSR0B|= (1&lt;&lt;TXEN0)|(1&lt;&lt;RXEN0);                // enable receiver and transmitter
    UCSR0C|= (1&lt;&lt;UCSZ00)|(1&lt;&lt;UCSZ01);   // 8bit data format
}
void byte_transmit (unsigned char data)
{
    while (!( UCSR0A &amp; (1&lt;&lt;UDRE0)));                // wait while register is free
    UDR0 = data;                                   // load data in the register
}
unsigned char byte_receive (void)
{
    while(!(UCSR0A) &amp; (1&lt;&lt;RXC0));                   // wait while data is being received
    return UDR0;                                   // return 8-bit data
}


int main(void)
{
  byte_init(103);
  interrupt_init();
  encoder_pin_config_init();
  DDRB = (1&lt;&lt;PB1) | (1&lt;&lt;PB2); // PWM pins &amp;&amp; Enable pins
DDRD = (1&lt;&lt;PD4) | (1&lt;&lt;PD5) | (1&lt;&lt;PD6) | (1&lt;&lt;PD7) ; //Motor Pins

SETBIT(PORTB, PB1);
SETBIT(PORTB,PB2);
while(1)
{
val=byte_receive();
if(val=='0')
{
  Stop();
}
if(val=='F')
{
  Forward();
}
if(val=='B')
{
  Backward();
}
if(val=='R')
{
  right();
} 
if(val=='L')
{
  left();
}
temp=sfl;
while(temp&gt;0)
{
  y=temp%10;
  c=y+'0';
  byte_transmit(c);
  temp=temp/10;

}
temp=sfr;
while(temp&gt;0)
{
  y=temp%10;
  c=y+'0';
  byte_transmit(c);
  temp=temp/10;
}
byte_transmit('.');
if(sfl==9999)
{
  sfl=0;
}
if(sfr==9999)
{
  sfr=0;
}
}

}
void Stop()
{
  CLEARBIT(PORTD,PD4);
  CLEARBIT(PORTD, PD5);
  CLEARBIT(PORTD, PD6);
  CLEARBIT(PORTD, PD7);
}
void Forward()
{
  SETBIT(PORTD, PD4);
  CLEARBIT(PORTD, PD5);
  SETBIT(PORTD, PD6);
  CLEARBIT(PORTD, PD7);
}
void Backward()
{
  SETBIT(PORTD, PD5);
  CLEARBIT(PORTD, PD4);
  SETBIT(PORTD, PD7);
  CLEARBIT(PORTD, PD6);
}
void left()
{
  CLEARBIT(PORTD, PD4);
  CLEARBIT(PORTD, PD5);
  SETBIT(PORTD, PD7);
  CLEARBIT(PORTD, PD6);
}

    void right()
    {
  SETBIT(PORTD, PD6);
  CLEARBIT(PORTD, PD6);
  CLEARBIT(PORTD, PD4);
  CLEARBIT(PORTD, PD5);
}

ISR(INT0_vect)
{
  sfl++;
}
ISR(INT1_vect)
{
  sfr++;
}`
</code></pre>
]]></description>
   </item>
   </channel>
</rss>