Hello.
I am new to Arduino world, and I have just recently purchased an Arduino Bano v3.0 board with pins for protoboard experiments. I am, however, familiar with programming in C/C++, so the arduino IDE and the language quickly became familiar to me. I am looking forward to becoming an arduino guru. I can see it is possible to automate a lot of things with this nifty little gadget! Okay, here's the deal. I am thinking about implementing a binary serial protocol for communication between an arduino board and the PC. I'll be using this to command & control the device(s). It will be a packet-based design sort of like TCP or UDP. I do have a few newbie questions to ask before I get my hands dirty.
-
I've read in the reference docs that the arduino only has 128 bytes of buffer for storing the incoming traffic from the PC (via a USB cable). I can live with that since most packets aren't going to be nearly as big. I am, however, concerned about the transmission. Suppose the PC transmits data to the arduino board faster than the arduino can process it. What happens when the RX buffer is full? Does arduino simply drop any incoming traffic until there is room in the buffer or does the buffer get overwritten?
-
Assuming the serial is a streaming protocol, I'll likely have to address some more issues. Suppose the PC sends an array of binary data (lets say 80 bytes) to the arduino board. The arduino is programmed to read all the bytes in a packet at once (actually byte by byte until all 80 bytes have been read) - this means the full binary array that was sent by the PC. Is it possible that the arduino will attempt to read the buffer before it has been fully filled with data i.e. only 40 bytes have been transmitted when the arduino executed the Serial.read() loop?
-
The arduino language reference shows that the Serial library has the Serial.read() and Serial.write() calls. The write() call has multiple prototypes, one of which lets you specify a source buffer and a length of data to be read and transmitted. Unfortunately the read() call only reads one byte at a time. Is there a way to read an arbitrary length of data from the RX buffer with one call i.e. Serial.read(my_buffer, 10)?
-
Lastly I'd ask a few questions about the serial protocol. Since my protocol will be packet-oriented, I will likely need to assure data integrity. All packets will always be at least two bytes in length - the first byte being full packet length, and the second the packet type/id. After that there is data. Packets will be of variable length. Do I have to include a byte for checksum and verify the transmitted data manually, or does the serial protocol already have a mechanism to ensure the transmitted data is correct?
Thanks in advance.