Pages: [1]   Go Down
Author Topic: Processing serial.write command slow; any ideas?  (Read 2009 times)
0 Members and 1 Guest are viewing this topic.
Toronto
Offline Offline
Jr. Member
**
Karma: 0
Posts: 70
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I need to send data to the Arduino quickly, and my messages weren't getting processed as fast as I expected. I assumed the problem was in my Arduino firmware, but, after much debugging, I realized that the problem was on the sending end. It turns out that Processing takes a full millisecond in between serial write commands, regardless of baud (at least on my Mac 10.5.2 2.33Ghz machine). Since the messages are received correctly, the actual message is being sent at the correct speed; it's just that the overhead of the command seems to be ridiculously high.

Does anyone have any ideas how to fix this? If not, what's a good alternative for my computer-side software? I fear I may need to switch over to C, which will make my life a little more difficult, but I suppose learning to do Serial I/O in C would come in handy eventually.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a similar problem! I need to be able to send data very quickly. I profiled the Serial.write() function and found it takes 600microseconds to return (and thus continue program execution) after sending 4bytes of data. The speed of this function is dependent upon the baud rate, I assumed that the pins1/2 serial connection was handled by a UART and thus should be asynchronous to the program execution.

Does anyone have any ideas to speed this up?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34122
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It turns out that Processing takes a full millisecond in between serial write commands, regardless of baud

It's not processing it is the USB protocol. USB devices are polled every millisecond so that is where the delay is. I am not sure you can do anything about it.
Data transfer from the USB to the serial bridge is always done at the same rate regardless of the actual serial baud rate. If the baud rate is too slow the data just backs up in the buffer in the serial bridge chip.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, as I only sent 4bytes to test the Serial.write function, I was not limited by the transmit buffer and the USB polling... Is there any explanation for my slowness? Is the source code to the Serial object available?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34122
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I was not limited by the transmit buffer and the USB polling
Yes you were the USB device is only contacted every millisecond so no matter how few bytes you have there is always the potential for a 1mS delay.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Mike, appologies I don't think I wa clear in my original post. I did not check the transmission time from the Arduino to the computer. I timed how long the actual Serial.write() function took to execute on the board itself, at 115200 I was getting ~600microseconds at double the baud rate I was getting ~300 microseconds.

AFAIK, the AVR should transmit to the Serial-USB bridge at a constant rate and that should be handled by a hardware UART
Logged

Pages: [1]   Go Up
Jump to: