Simple packetization based on best practices. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Packet delimiter is 0x00. Packets are encoded using COBS: https://www.embeddedrelated.com/showarticle/113.php http://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing http://conferences.sigcomm.org/sigcomm/1997/papers/p062.pdf Message integrity is protected by the fletcher16 checksum: uint16_t Fletcher16( uint8_t *data, int count ) { uint16_t sum1 = 0; uint16_t sum2 = 0; int index; for( index = 0; index < count; ++index ) { sum1 = (sum1 + data[index]) % 255; sum2 = (sum2 + sum1) % 255; } return (sum2 << 8) | sum1; } Implementations may limit the packet size (to be able to use smaller buffers and to have a simpler COBS implementation) PC is master and arduino is slave. The protcol is synchonous, this means that the master must wait for a reply from the slave, before it can send a new command. If no reply is received (because either the request didn't come through or the reply didn't come through) the original request must be sent again. Slave MUST: - preform the command, if it didn't get it earlier and send a response - resend the response if it already processed the command earlier. Current and next request can be distinguished by EVEN/ODD marker at start of all packets except RESET. After a RESET, the slave MUST send a RESET back and expect the first command to be even (and reply RESET to ODD commands until it has processed an EVEN command). EVEN = AA ODD = 55 EVEN/ODD is denoted by 'EO' All packets start with an even/odd marker, except RESET. RESET from m -> s and s -> m ~~~~~ Packet (zero length) 0000: Note: a RESET only resets the communication state, not the whole arduino PING from m -> s and PONG from s -> m ~~~~ Packet (length = 1) 0000: EO other packets (free form, length > 1) m -> s, s -> m ~~~~~~~~~~~~~ 0000: EO xx yy zz Version 1 commands ~~~~~~~~~~~~~~~~~~ 00: read blower value 01 XX: set blower to XX 02 XX YY ZZ: set RGB color leds to XX YY ZZ 03: read last IR command 04 XX: write releas pin 05 XX: write visjeslicht pin 06: read releas pin 07: read visjes pin 08: read RGB color leds