Serial protocol

Developer
Jan 21, 2010 at 5:48 AM

I think that the current serial protocol is hard to implement both on the driver and microprocessor side.

Although it uses ASCII encoding, it is fixed length so you need to be very careful to fit the data fields in proper places of the message. Unfortunatelly Arduino has very little support for text formatting - especially for numeric values.

For example, current message for temp/humidity sensor should look like this: 2170724282 where the first byte is the sensor identifier the second and third bytes contain packet length and the remaining bytes contain temperature in degrees farenheit followed by the relative humidity. ("0724" is 72.4 degrees F and "282" is 28.2 relative humidity).

One option would be to switch to more human readable format, that would also allow variable length messages (by using field delimiters), and null-values. For example if we use format similar to NMEA protocol used by GPS applications it should be easy to adopt an existing C++ parser implementations.

For above reading the packet could look like this: $GSR,2,72.4,28.3 (ending with new line char \n)

(where GSR stands for Generic Sensor Reading :-)