Processing interface stops after playing for 2-3 minutes

edited May 2017 in Arduino

Hello,

I'm running a Processing interface which receives the X and Y position data (when moving a sensor) from Arduino DUE through serial communication to move a circle in a Processing interface. 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. It is annoying, 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);
  }
}

Answers

  • Hi thanhvu94, Please add this as the first line of draw: print(serialPort.available() + " "); What do you get on the console when he prog is working/not?

    You haven't said what rate the messages are arriving, = loop rate in Arduino. Please try setting frameRate the same or slightly slower. I think it will work for longer, but the movement may lag.

Sign In or Register to comment.