# 9. Serial Communication Operation Course ## 9.1 Master-Slave Communication Principle This section provides a detailed introduction to the **master-slave communication mechanism** used by the LeArm AI robotic arm when interfacing with various external devices (such as a PC, Arduino, Raspberry Pi, etc.). For clarity, this section uses communication between a **PC and LeArm AI** as the primary example. Throughout this chapter, **LeArm AI functions as a slave device**, communicating with external systems via a **UART serial interface**. :::{Note} Communication between LeArm AI and external host devices follows the "**LeArm PC & App Communication Protocol**." ::: The parsing of command frames and how LeArm AI executes the corresponding actions have been covered in the chapter [Basic Development Course -> Host Control](5.Basic_Development_Course.md#pc-software-control) and will not be repeated here. ### 9.1.1 Master-Slave Relationship * **LeArm AI's Role as a Slave Device** (1) Receiving and parsing commands from the master: LeArm AI continuously listens for serial data. When data is received via the UART interface, it parses the data according to the communication protocol and triggers the corresponding functions based on the command content. (2) Executing functions based on received commands: Once a valid command is parsed, LeArm AI executes the corresponding function. This could include playing an action group, controlling one or multiple servos, or other device-specific operations. (3) Data packaging and feedback: When a read command is received, LeArm AI invokes the appropriate read function, then packages the retrieved data according to the protocol and sends it back to the master device. * **External Devices as the Master** (1) Command packaging and transmission: The master device must package control commands and data into data frames according to the defined communication protocol, then transmit them to the slave device. (2) Control coordination: The master is responsible for managing the coordination of the entire system, ensuring smooth communication and conflict-free operation between LeArm AI and other devices, thereby maintaining system stability. (3) Data reception: When querying the robot's status, the master device should send a read command and then receive the response data from LeArm AI. It must ensure the integrity and accuracy of the received data, parse the response packet, and extract the relevant information. ### 9.1.2 Hardware Connection Before downloading the program, please ensure that the **serial port driver is properly installed**. Connect the computer's USB port to the USB-to-serial port on the mainboard using a USB download cable. ### 9.1.3 Data Transmission Format The default UART serial communication settings for LeArm AI are as follows: | Baud Rate | 9600 | |:---------:|:----:| | Data Bits | 8 | | Parity | None | | Stop Bits | 1 | ### 9.1.4 Communication Protocol For details, refer to the document [LeArm PC & App Communication Protocol](../_static/source_code/LeArm_PC_APP_Communication_Protocol.zip) located in the same directory.