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 › Speed (not baud rate) of Serial.write command
Page Index Toggle Pages: 1
Speed (not baud rate) of Serial.write command (Read 1791 times)
Speed (not baud rate) of Serial.write command
Mar 19th, 2008, 4:59am
 
I'm using an application that needs to send out lots of data over the Serial port very frequently. I noticed that data seemed to be taking a lot longer than it should at the transfer speeds I'm using (115200 baud), so I put a single-byte serial write command inside a loop to figure out the average amount of time it's taking to execute; it turns out that it's taking about 1ms/byte! That is several orders of magnitude slower than it should be. The actual transfer rate is working fine, because the receiving end picks it up at 115200; it seems the command itself is what's taking so long. Is there any way to fix this?

I'm running 0135 on Mac OS 10.5.2, 2.33GHz Core 2 Duo, in case that's relavant. Thanks!

Jonathan
Re: Speed (not baud rate) of Serial.write command
Reply #1 - Apr 16th, 2008, 7:50pm
 
I just logged in to post this same problem!
I am sending bytes to an LCD display, one pixel at a time. 131 x 131 = 17161 pixels. 17 seconds to refresh! I added a timer (compare the millis() before and after and it was consistently between 17190 and 17300 milliseconds.

I stripped down my program and from what I found, I believe Processing is putting a 1 millisecond delay into each Serial.write().
is this true?can this be altered?
-jeff
ps. I have similar computer stats as you.
Re: Speed (not baud rate) of Serial.write command
Reply #2 - Apr 16th, 2008, 8:06pm
 
feesta,

I'm afraid the only solution I came up with was to rewrite my program in Python! Good luck!
Re: Speed (not baud rate) of Serial.write command
Reply #3 - Apr 17th, 2008, 11:42pm
 
I have had this problem too. I thought I had delays of 5ms with every try to write to the serial port. My solution was to just call the serial.write() function once and send an array (in my case it was a byte[]) which contains the data, to the serial port. This way Processing will send the data much faster. So: not for every value one serial.write call, but one call for all values (or at least in parts).

Don't know why Processing adds that delay.

Greetings,

Jeroen
Re: Speed (not baud rate) of Serial.write command
Reply #4 - Jun 15th, 2008, 5:34am
 
I just read this the other day (maybe pertinent):

Quoted from: http://www.arduino.cc/playground/Interfacing/Firmata

//Start Quote

latency and jitter concerns

   * Pduino jitter discussion (http://lists.puredata.info/pipermail/pd-list/2007-01/045926.html)
   * more Pduino jitter discussion (http://lists.puredata.info/pipermail/pd-list/2007-01/045938.html)

It turns out that the USB-serial drivers are optimized for fast bulk data transfer, and those optimizations actually wreak havoc with the timing of the messages over the USB-serial. This forum thread covers the topic:

   * fast serial sendin (http://www.arduino.cc/cgi-bin/yabb2/num_1170939903.html#11)

//End Quote

I'm using firmata to read 6 analog inputs (10bits resolution each) and 13 digital inputs (1 bit ea) at 60fps using firmata and this script:

http://processing.org/discourse/yabb_beta/YaBB.cgi?num=1213500039

and it seems to be pretty snappy - by my math, that's at least 547 bytes/second
Page Index Toggle Pages: 1