I'm taking 3 analog inputs with the Arduino and using a XBee w/Shield to send the inputs to an XBee connected to my laptop. I've increased the Baud Rate to 115200 (which I believe is the max). However, I'm only able to receive the data on my laptop at 700Hz. I use Hyperterminal to read the serial input for 10 seconds and then count the number of data points I get. I thought that I can read the data at least 5,000 Hz. The math I used to get that is:
XBee Max Throughput/(size of data) = sampling rate. 250,000(bits/sec)/(16bits*3samples)=5,208 Hz
Am I doing something inefficient with my code/communication methodology, or is this something inherently limited by the XBee or Arduino? My code is shown as follows:
The math I used to get that is:
XBee Max Throughput/(size of data) = sampling rate.
250,000(bits/sec)/(16bits*3samples)=5,208 Hz
Where did the 250,000 come from? At 115200, with a start bit and a stop bit, you can send 11,520 bytes per second. If each value is 2 bytes, and there are 3 bytes per packet, that's 1920 packets per second assuming that NOTHING else gets sent. Which, of course, is not a valid assumption, since the XBees have to acknowledge packets. Since one XBee has to tell another that it got a packet, it has to know which XBee it got it from, so there is overhead involved, which cuts down on your packet rate (since the packets are larger than 6 bytes).
The assumption that there are 6 bytes per packet is also wrong, since you are sending the data as ASCII text, not binary data.
You have NO way of making sense of the data in the packets you are sending, because there are no delimiters between the values in the packet and no delimiters between the packets.
Finally, the XBees need time to acknowledge the packets. You are not allowing for that, by ramming data out as fast as possible. You'll actually get much better throughput if you give the XBees breathing room.