# 3. LSC-32 Controller Secondary Development-Arduino Development ## 3.1 Getting Ready
### 3.1.1 Wiring Instruction This section employs Arduino UNO and 32-channel servo controller for development, powered by a 7.4V 2200mAh lithium battery. Connect the serial port on the 32-channel servo controller to the serial port on the Arduino UNO. (1) Connect the battery cable to the power interface on the servo controller, and connect the lithium battery. :::{Note} Connect the red wire to "**+**", and the black wire to "**-**". The positive and negative poles must be matched correctly. :::
(2) Use female-to-female DuPont wires to connect the Arduino UNO to the controller.
:::{Note}
Connect the `TX` and `RX` interfaces in reverse, `GND` to `GND`, and `3.3V` to `3.3V`.
:::
① Connect the servo to the interface 1 on the controller.
:::{Note}
* When using our lithium battery, connect the lithium battery interface wire with red to positive (+) and black to negative (-) to the DC port.
* If the interface wire is not connected to the lithium battery, do not directly connect it to the battery interface wire to avoid a short circuit between positive and negative poles, which may cause a short circuit.
* When connecting the serial ports, make sure to connect `RX` and `TX` correctly. Please refer to the images above.
* Before powering on, ensure that no metal objects come into contact with the controller. Otherwise, it may cause a short circuit and damage the controller due to its bottom pins.
:::
### 3.1.2 Environment Configuration
Install Arduino on PC. The software package is stored in [Appendix->Arduino Installation Package](Appendix.md).
### 3.1.3 Add Library File
(1) Open Arduino IDE. Click **"Sketch -> Include Library -> Add .ZIP Library"** in the menu bar.
(2) Locate and open the library file in [Arduino Development/Library File (import before the first use)](../_static/source_code/Arduino_Development.zip).
(3) Return to the IDE. When the prompt shown in the following image appears, the library file is successfully added.
## 3.2 Development Case
### 3.2.1 Case 1 PWM Servo Rotation Control
In this case, commands are sent to the 32-channel servo controller to control the servo rotation via the serial port.
* **Run Program**
(1) Open the program **LobotServoController.ino** stored in [Arduino Development/Case 1 PWM Servo Rotation Control](../_static/source_code/Arduino_Development.zip).
(2) After opening the program, add the library file based on [3.1.3 Add Library File](#anchor_3_1_3).
:::{Note}
You must add the library file when running the program for the first time. Otherwise, the program will report an error.
:::
(3) Connect Arduino UNO to your computer with a USB cable. Select the board type as **"Arduino UNO"** and the corresponding port.
:::{Note}
The port may not be unique. Arduino IDE will add the Arduino model after the corresponding port number.
:::
:::{Note}
When downloading the program, the serial ports of the Arduino UNO and the servo controller should be disconnected. Otherwise, the program will fail to be downloaded.
:::
(4) After Arduino UNO is connected, click
to download the program. After the download is complete, follow [3.1.1 Wiring Instruction](#anchor_3_1_1) to connect the servo controller to the Arduino UNO. Then, switch the servo controller on. The servo 1 will start to rotate.
* **Program Outcome**
After running the program, the servo will continuously rotate between the positions of 500 and 2500, with an interval of 1.5 seconds.
* **Program Analysis**
[Source Code](../_static/source_code/Arduino_Development.zip)
(1) Import the Required Function Package
The function package mainly encapsulates various function modules for the 32-channel servo controller communication. The variables and functions defined in it can be used to control the servos.
{lineno-start=1}
```c++
#include
:::{Note}
When downloading the program, the serial ports of the Arduino UNO and the servo controller should be disconnected. Otherwise, the program will fail to be downloaded.
:::
(4) After Arduino UNO is connected, click
to download the program. After the download is complete, follow [3.1.1 Wiring Instruction](#anchor_3_1_1) to connect the servo controller to the Arduino UNO. Then, switch the servo controller on. The servo 1 will start to rotate.
* **Program Outcome**
After running the program, the servo will rotate from position 500 to 2500 at a speed of 800ms. Then it will move back to position 500 at a speed of 1200ms.
* **Program Analysis**
[Source Code](../_static/source_code/Arduino_Development.zip)
(1) Import the Required Function Package
The function package mainly encapsulates various function modules for the 32-channel servo controller communication. The variables and functions defined in it can be used to control the servos.
{lineno-start=1}
```c++
#include
:::{Note}
When downloading the program, the serial ports of the Arduino UNO and the servo controller should be disconnected. Otherwise, the program will fail to be downloaded.
:::
(4) After Arduino UNO is connected, click
to download the program. After the download is complete, follow [3.1.1 Wiring Instruction](#anchor_3_1_1) to connect the servo controller to the Arduino UNO. Then, switch the servo controller on. The servo 1 will start to rotate.
* **Program Outcome**
After running the program, servos 1 and 2 will continuously rotate between positions 500 and 2500, at an interval of 1.5 seconds. The number of manageable servos depends on the interfaces on the controller. Let's demonstrate how to control two servos. If you want to control more servos, modify the code accordingly.
* **Program Analysis**
[Source Code](../_static/source_code/Arduino_Development.zip)
(1) Import the Required Function Package
The function package mainly encapsulates various function modules for the 32-channel servo controller communication. The variables and functions defined in it can be used to control the servos.
{lineno-start=1}
```c++
#include
:::{Note}
When downloading the program, the serial ports of the Arduino UNO and the servo controller should be disconnected. Otherwise, the program will fail to be downloaded.
:::
(4) After Arduino UNO is connected, click
to download the program. After the download is complete, follow [3.1.1 Wiring Instruction](#anchor_3_1_1) to connect the servo controller to the Arduino UNO. Then, switch the servo controller on. The servo 1 will start to rotate.
* **Program Outcome**
The servo returns to the neutral position. After a short delay, it rotates to the deviation angle and maintains that position.
* **Program Analysis**
[Source Code](../_static/source_code/Arduino_Development.zip)
(1) Import the Required Function Package
The function package mainly encapsulates various function modules for the 32-channel servo controller communication. The variables and functions defined in it can be used to control the servos.
{lineno-start=1}
```c++
#include