We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I'm writing a Processing program that collects the data from Arduino (from a sensor), calculate the data to reconstruct X Y position and then makes a circle move according to the XY position. However, the problem is that I send 2 float data (with 3 floating digits) and when I open the Processing Interface, the circle can move according to how I move my sensor but it is very slow in comparison with the speed I move (and there are some delays).
I use Arduino DUE; Baud Rate 128000.
Is there any way to solve this problem? I publish my Processing code below:
// import libraries
import java.awt.Frame;
import java.awt.BorderLayout;
import processing.serial.*;
// Serial port to connect to
String serialPortName = "COM3";
float[] x= new float[2];
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, 115200);
}
void draw() {
if (serialPort.available() > 0) {
byte[] inBuffer = new byte[30]; // holds serial message
try {
serialPort.readBytesUntil('\r',inBuffer);
}
catch (Exception e) {
}
String myString = new String(inBuffer);
String[] nums = split(myString,' ');
try {
x[0] = float(nums[0]);
x[1] = float(nums[1]);
}
catch (Exception e) {
}
//Calculate x and y position based on data sent by Arduino
xf = 1.508*tan((3.14/180)*(121*x[0]+61*(x[0]*x[0])+35*x[1]-171*(x[1]*x[1])+1.7));
yf = 1.508*tan((3.14/180)*(-290*x[1]-799*(x[1]*x[1])+20*x[0]+39.2*(x[0]*x[0])-7.1));
background(51);
//Draw data
float x_m = map(xf,-0.4,0.4,0,900);
float y_m = map(yf,-0.4,0.4,0,900);
ellipse(x_m,y_m,50,50)
}
}
Answers
This is the same progam as https://forum.processing.org/two/discussion/22602/processing-interface-stops-after-playing-for-2-3-minutes#latest that's later so probably ignore this.