|
| 1 | +# ZAF 2.0 ControlBox |
| 2 | + |
| 3 | +This is the Arduino code for ZAF's 2.0 'ControlBox' |
| 4 | +The control box centralises control to the valves, pumps, |
| 5 | +and servo and more |
| 6 | + |
| 7 | +## How to install/update on the arduino: |
| 8 | + |
| 9 | +The main sketch (controlbox) must be uploaded to _both_ arduino megas. |
| 10 | +Nothing else needs to be done. |
| 11 | + |
| 12 | +## Connections: |
| 13 | + |
| 14 | +The ControlBox firmware supports a nearly unlimited of chained arduinos, |
| 15 | +making the design infinitely scalable. We use serial connections via USB |
| 16 | +and UART at a speed of at 500'000 bps. |
| 17 | + |
| 18 | +The first arduino in the chain receives messages per USB, messages are forwarded |
| 19 | +on the Serial1 port. Corresponding (Serial1) TX and RX lines must be connected |
| 20 | +to the RX and TX lines of the next arduino's Serial2. For the next arduinos in |
| 21 | +the chain the pattren is repeated: Serial1 to send to the next arduino, |
| 22 | +Serial2 to receive from the previous arduino. USB is operational for all arduinos |
| 23 | +in the chain but it is recommended to only inject messages at the beginning of |
| 24 | +the chain... |
| 25 | + |
| 26 | +Pins 38 to 53 are reserved for valves. Pins 2 to 12 are reserved for PWM, |
| 27 | +with pin 7 reserved for 1 servo per arduino. |
| 28 | + |
| 29 | +NOTE: arduino pins are _not_ the same than the PWM and Valve indexes! |
| 30 | + |
| 31 | +## Protocol: |
| 32 | + |
| 33 | +The ControlBox protocol is very simple and human-writable. |
| 34 | +The commands are received by the first arduino in the chain |
| 35 | +and if needed are forwarded recursively to the next arduinos. |
| 36 | + |
| 37 | +### valve and PWM channels: |
| 38 | + |
| 39 | +Each Arduino has 15 relay/valve channels, the 16th channel is |
| 40 | +used for the buzzer, and 10 PWM channels, of which channel 5 is |
| 41 | +reserved for servos. Valve channel of index 15 is therefore the 1st |
| 42 | +(index=0) valve channel of the second arduino. Each Arduino added |
| 43 | +inceases the number of available valve and PWM channels. The |
| 44 | +indexing starts at the first arduino and is incremented to span |
| 45 | +across all Arduinos ths offering a unified indexing. |
| 46 | + |
| 47 | +### Command structure: |
| 48 | + |
| 49 | +Commands always start with the character: '#' and end with '\n'. |
| 50 | +A successfully parsed command causes a return message of 'done!\n'. |
| 51 | +Integer numbers must be surrounded by some whitespace for delimitation |
| 52 | +(quite flexible n the type and number of whitespaces). |
| 53 | + |
| 54 | +### Command list: |
| 55 | + |
| 56 | + '#?\n' |
| 57 | + Returns the current state of the ControlBox. |
| 58 | + For example,for two arduinos chained, the result is: |
| 59 | + |
| 60 | + |c|o|c|c|c|c|c|c|c|c|c|c|c|c|c||0|0|0|0|255|0|0|0|0|0|done! |
| 61 | + |o|c|c|c|c|c|c|c|c|c|c|c|c|c|c||0|0|0|0|0|0|0|0|0|0|done! |
| 62 | + |
| 63 | + Where we can see that (second) valve 1 of the first arduino (first line) |
| 64 | + is open, and the (first) valve 0 of the second arduino (second line) is |
| 65 | + open. Also, the 5th PWM channel (index=4) of the first arduino is set at |
| 66 | + the max value of 255. |
| 67 | + |
| 68 | + '#!\n' |
| 69 | + Shutsdown all valves and all PWMs and brings back all servos to position |
| 70 | + (angle) 0. This is called recursively on all arduinos in the chain. |
| 71 | + |
| 72 | + '#dX\n' |
| 73 | + Turns on or off debugging messages: 'd0' --> off, 'd1' --> on. |
| 74 | + |
| 75 | + '#b P D \n' |
| 76 | + Makes noise using the unnused relay (index=15). |
| 77 | + P is the periode in milliseconds, D is the duration in number of periods. |
| 78 | + |
| 79 | + '#tT R I \n' |
| 80 | + Runs a test. There is two kinds of tests: 'v'alve and 'p'wm. |
| 81 | + Therefore T is either 'v' or 'p'. R is an integer that indicates |
| 82 | + how many times to repreat the test sequence. |
| 83 | + I is optional and only needed for the 'p' test, it indicates which PWM channel |
| 84 | + to use for the PWM test sequence. |
| 85 | + |
| 86 | + '#vS I \n' |
| 87 | + Opens (S='o') or closes (S='c') valve at index I. |
| 88 | + |
| 89 | + '#p I S \n' |
| 90 | + Sets the PWM value (or servo angle) of PWM channel I to value S. |
| 91 | + |
| 92 | + Unrecognised commands are ignored (in debug mode a notification is sent.). |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
0 commit comments