We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpElectronics,  Serial Library › Extremely slow serial input response
Page Index Toggle Pages: 1
Extremely slow serial input response (Read 1367 times)
Extremely slow serial input response
Jul 9th, 2009, 7:39pm
 
Hey all, I am trying to read integers out of the serial port (which re being written by an arduino).  Essentially, there is a lag time of nearly ten seconds between when the arduino writes to the serial port and the Processing serial library reads and the data and it is displayed.  My code for reading the port is as follows:

Code:

/**
* Get the x and y values recorded by the serial port
*/
private void receiveData() {
// read the value from the serial port
xValue = 0;
yValue = 0;

if(port.available() > 0) {
bufferedValue = port.read();

while(bufferedValue != SEPARATOR) {
// converts the Serial input, which is a stream of ascii characters, to integers
// Shift the the current digits left one place
xValue*= 10;
// add the next value in the stream
xValue += (bufferedValue - 48);


bufferedValue = port.read();
}

bufferedValue = port.read();

while(bufferedValue != SEPARATOR) {
// converts the Serial input, which is a stream of ascii characters, to integers
// Shift the the current digits left one place
yValue*= 10;
// add the next value in the stream
yValue += (bufferedValue - 48);

bufferedValue = port.read();
}
}
}

}


The recieve data method reads the numerical characters and converts them to integers.  I simply cannot figure out why this is so slow.  Would running the receiveData() method in its on thread improve the situation at all.

p.s. I am using the processing Libraries in eclipse.

Thanks,
Andy
Re: Extremely slow serial input response
Reply #1 - Jul 10th, 2009, 8:31am
 
Update: So I rewrote some of the code in the scetchpad and ran it and it ran in realtime... initially.  After a bit of writing, recompiling, and running the app, everything began to slow down again!
Re: Extremely slow serial input response
Reply #2 - Jul 12th, 2009, 12:01am
 
One thought that may not cause a delay but read values incorrectly is the number of calls to read().
But then, I am guessing.

I'm not sure when or how often receiveData() is called.
And if you changed your code... Wink

Is it possible to get a runnable example?
Both Processing and Arduino?
Page Index Toggle Pages: 1