I'm busy creating my own custom serial protocol to read and write to pins (PWM and Analog read). I have a basic structure that I want to use, but just battling to get the correct method to strip out the binary values.
Will the following approach work? Or will it demand too much processing resulting in delays?
I will appreciate any suggestions and help.
I've divided the serial string as follow:
|S|FFF|FF|FF|FF|FF|FF|FF|FF|FF|FF|FF|FF|FF|FF|FF|X| |1| 2 | 3 |---------4------- -| 5|----------6--------|7|
Field 1 = an "S" will indicated the start of the received string, after that I will substring everything.
Field 2 = FFF in hex will give 12 bits "000000000000". This represents pins 2 - 13 on the Arduino. "0" = pin is an Output "1" = pin is an Input
Field 3 = This field will indicated whether PWM is enabled or not. (Arduino Pin 3,5,6,9,10,11) 6 pins in total. Therefor the FF in hex is sufficient to give 8 bits (the first 6 bits will be used). "0" = PWM Disabled "1" = PWM Enabled
Field 4 = This is the aread for the 6 PWM pins (pins 3,5,6,9,10,11). A value of 0-255 can be written to each and then on the receiving end it can be scaled to 0-1023 for a better resolution. if PWM is enabled, the value will range from 0-255 and Will be represented in HEX i.e FF. If PWM is disabled, The value will either be FF for ON, or 00 for OFF. (This can be used as an Input or Output, depending on the definition is Field 2)
Field 5 = This represents Hex value FF, which will be converted to binary 11111111. These bits indicates the states for all the remaining Digital IO pins ie. 2,4,7,8,12,13. "1" = "ON" "0" = "OFF" (This can be used as an Input or Output, depending on the definition is Field 2)
Field 6 = This is the field for Analog Inputs. Each Analog pin will have its own area of Hex FF which will give a value between 0-255. (Can be scaled to 0-1023 in code).
Field 7 = This field indicated the End of the serial string. "X"
It is alot of information and I hope it makes sense. Any [u]Sample code[/u], comments,insight and suggestions on methods to use will be appreciated.
I am a bit new to serial comms and hex-bin conversions on arduino and still trying to figure out things.
If this protocol works, I'm sure it will be able to help alot of people (If there isn't something else out there providing complete control) If there is, please let me know.