Friday, January 7, 2011

Serial data transmission and problem with it being SLOW !!!

A while ago I was facing a problem reading some inputs from Serial Communication(USB port) in Arduino. The Arduino would work perfect(read all the inputs from Serial Communication Window as planned) if I was having my debug print outs but not if I would remove them(they also could be substituted by Delays) !!! I later tried to find out about them and here was the answer :
"Serial data transmission is slow. The Serial.print statement takes time, which allows time for more data to arrive. You have two choices. Add a delay statement to the while loop, and hope all the data arrives in time is the first choice. The longer you waste time waiting for data, the better your chances of it all arriving in time.
The second choice is to add an end-of-packet marker, and keep appending to temp until that end of packet marker arrives. Only use the data in temp when the end of packet marker has arrived.

The delay masks the issue of not being able to read a complete packet in one pass. If the delay is too small, the whole packet will not arrive before the delay(s) expire. If the delay is too large, you are just wasting time.

The better approach is to add an end of packet marker to the packer, wo you can read the packet as quickly as possible.."
Source : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294185714/1#1

No comments:

Post a Comment