Processing interface stops after 2-3 minutes

edited May 2017 in Arduino

Hello,

I'm running a Processing interface which uses the Serial XY position data (when moving a sensor) from Arduino to move a circle in a Processing interface in the same trajectory as I move the sensor. However, everything works fine for 2-3 minutes, then the Interface suddenly stops (the circle doesn't move anymore). I have to close and start again to continue. Is there any way to fix this problem?

Here is my Processing code:

// import libraries
import java.awt.Frame;
import java.awt.BorderLayout;
import processing.serial.*;

// Serial port to connect to
String serialPortName = "COM3";
float xf;
float yf;
/* SETTINGS END */

Serial serialPort; // Serial port object

void setup() {
  size(900,900);
  background(51);
  noStroke();
  //frameRate(100);
  serialPort = new Serial(this, serialPortName, 9600); 
}


void draw() {

  if (serialPort.available() > 0) {
    byte[] inBuffer = new byte[30]; // holds serial message
        serialPort.readBytesUntil(ENTER,inBuffer);
    if(inBuffer==null) {
      return;
    }

    String myString = new String(inBuffer);
    String[] nums = split(myString, ' ');

        if (nums.length==2) {
            xf = float(nums[0]);    //Position X
            yf = float(nums[1]);    //Position Y
        }


    background(51);
    float x_m = map(xf,-0.4,0.4,0,800);
    float y_m = map(yf,-0.4,0.4,0,800);
    ellipse(x_m,y_m,50,50);
  }
  }
Sign In or Register to comment.