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 › Sending Serial slows processing down
Page Index Toggle Pages: 1
Sending Serial slows processing down (Read 1179 times)
Sending Serial slows processing down
Oct 23rd, 2006, 2:57am
 
Hi all,

I hooked up my Arduino board which controls 3 PWM pins to Processing. My processing sketch is running some fluid-like simulation (framerate is fine). This simulation returns 3 values, with which I want to control the 3 PWM values.
I am sending 6 bytes every loop on 115200baud to the Serial port. These 6 bytes alone already slow my processing sketch down severely. As I said, without the serial output, it runs smoothly.
Has this occured to others? Am I doing something wrong, or does the serial port have some kind of latency?
I am running processing on a PC and the Arduino board through USB.
Thanks for your help
Re: Sending Serial slows processing down
Reply #1 - Oct 23rd, 2006, 3:24am
 
(own-reply)

I think I already solved the problem.
the code looked like this:
Code:
for (int i=0;i<3;i++) {
myPort.write(index[i]);
myPort.write(value[i]);
}

Now instead of writing (int)egers I thought I'd give it a try in writing an array of bytes at one time
Code:
byte[] message = new byte[6]
for (int i=0;i<3;i++) {
message[i*2]=(byte)index[i];
message[i*2+1]=(byte)value[i];
}
write(message)

And now it works perfectly!
It looks like everytime you call a 'write' it first has to open the port or something like that...

Anyhow, I thought I'd share this, since some others might stumble upon the same problem.
Page Index Toggle Pages: 1