|
1 | 1 | # ArduinoControl |
2 | 2 |
|
3 | | -Controlling arduino with the serial port. |
| 3 | +[](https://github.com/MartinKondor/ArduinoControl/) |
| 4 | +[](https://github.com/MartinKondor/ArduinoControl/issues) |
| 5 | + |
| 6 | +[](https://opensource.org/licenses/MIT) |
| 7 | + |
| 8 | +A library for controlling arduino from the serial port, working with any programing language that can open serial connection. |
| 9 | + |
| 10 | +## Getting Started |
| 11 | + |
| 12 | +### Prerequisites |
| 13 | + |
| 14 | +* Arduino |
| 15 | +* Arduino IDE (optional) |
| 16 | + |
| 17 | +## Deployment |
| 18 | + |
| 19 | +Let's suppose that you want to control an Arduino from Python program. |
| 20 | + |
| 21 | +First create an empty Arduino IDE project called `testac`: |
| 22 | + |
| 23 | +``` |
| 24 | +void setup() {} |
| 25 | +void loop() {} |
| 26 | +``` |
| 27 | + |
| 28 | +After this, copy the content of the `source` library (which is in this repository) to the `testac` project's folder, and the directory will look like this: |
| 29 | + |
| 30 | +``` |
| 31 | +testac/ |
| 32 | + testac.ino |
| 33 | + arduino_control.ino |
| 34 | +``` |
| 35 | + |
| 36 | +As a last step, go back to your `testac.ino` file and change it: |
| 37 | + |
| 38 | +``` |
| 39 | +void setup() { |
| 40 | + Serial.begin(9600); |
| 41 | + ac_listen(9600); |
| 42 | +} |
| 43 | +void loop() {} |
| 44 | +``` |
| 45 | + |
| 46 | +The Serial port must be opened for ArduinoControl and the same baudrate is needed. It is advised to do: |
| 47 | + |
| 48 | +``` |
| 49 | +#define BAUD_RATE 9600 |
| 50 | +
|
| 51 | +void setup() { |
| 52 | + Serial.begin(BAUD_RATE); |
| 53 | + ac_listen(BAUD_RATE); |
| 54 | +} |
| 55 | +void loop() {} |
| 56 | +``` |
| 57 | + |
| 58 | +Now this project is ready to be uploaded to an Arduino and be used with the commands. |
| 59 | + |
| 60 | +After the upload go to this project's directory and check the `examples/blink.py` for the python example. |
| 61 | + |
| 62 | +## Commands |
| 63 | + |
| 64 | +A message looks like: |
| 65 | + |
| 66 | +``` |
| 67 | +[START][CONTENT][STOP] |
| 68 | +``` |
| 69 | + |
| 70 | +Where in this library the start is an `S`: |
| 71 | + |
| 72 | +``` |
| 73 | +S[CONTENT][STOP] |
| 74 | +``` |
| 75 | + |
| 76 | +The stop is a `.`: |
| 77 | + |
| 78 | +``` |
| 79 | +S[CONTENT]. |
| 80 | +``` |
| 81 | + |
| 82 | +The contents first part is the `AC_ID` (see the arduino_control file and change the ID for a number you want, |
| 83 | +but the number must be > 0), this can be 0 but the 0 means that every arduino with any `AC_ID` will do as the `contents` say: |
| 84 | + |
| 85 | +``` |
| 86 | +S[AC_ID][CONTENT]. |
| 87 | +``` |
| 88 | + |
| 89 | +The content is consisting of commands which are separated by a | and the commands can be upper or lower case but it is advised to use lowercase. |
| 90 | + |
| 91 | +So an abstract message looks like this: |
| 92 | + |
| 93 | +``` |
| 94 | +S[AC_ID]| ... |[COMMAND]| ... |[COMMAND]| ... |. |
| 95 | +``` |
| 96 | + |
| 97 | +Where the `...` are denoting more commands. |
| 98 | + |
| 99 | +### Parts of a message |
| 100 | + |
| 101 | +* S~ - Pass away, do nothing |
| 102 | +* S - Start of message |
| 103 | +* . - End of message |
| 104 | +* in - Set the nth port to INPUT |
| 105 | +* in - Set the nth port to INPUT_PULLUP |
| 106 | +* on - Set the nth port to OUTPUT |
| 107 | +* hn - Turns the nth output to HIGH |
| 108 | +* ln - Turns the nth output to LOW |
| 109 | +* If you whish to use an analog pin write an a before the command like: "ah1", will turn the 1st analog output to HIGH |
| 110 | + |
| 111 | +### Examples |
| 112 | + |
| 113 | + * `"S0|o7|h7|."` - For all arduino (0), set 7 to OUPUT (o7), and turn it on (h7) |
| 114 | + * `"S2|ao1|ah1|."` - For the arduino numbered with (2), set Analog 1 to OUPUT (ao1), and turn it on (ah1) |
| 115 | + * `"S1|o1|h1|o2|l2|."` - For the arduino numbered with 1 (1), set 1 to OUPUT (o1), and turn it on (h1), then set 2 to OUTPUT (o2), and turn it off (l2) |
4 | 116 |
|
5 | 117 | ## Tested boards |
6 | 118 |
|
7 | 119 | This software can be used with any programable arduino board, but we only tested these: |
8 | 120 |
|
9 | 121 | * [Arduino Uno](https://store.arduino.cc/arduino-uno-rev3) |
10 | 122 | * [Arduino Mega 2560](https://store.arduino.cc/mega-2560-r3) |
| 123 | + |
| 124 | + |
| 125 | +## Contributing |
| 126 | + |
| 127 | +This project is open for any kind of contribution from anyone. |
| 128 | + |
| 129 | +### Steps |
| 130 | + |
| 131 | +1. Fork this repository |
| 132 | +2. Create a new branch (optional) |
| 133 | +3. Clone it |
| 134 | +4. Make your changes |
| 135 | +5. Upload them |
| 136 | +6. Make a pull request here |
| 137 | +7. Profit. |
| 138 | + |
| 139 | +## Authors |
| 140 | + |
| 141 | +* **[Martin Kondor](https://github.com/MartinKondor)** |
| 142 | + |
| 143 | +## License |
| 144 | + |
| 145 | +This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details |
0 commit comments