Development Workflow for Controlling Bus Servo Control Board with STM32 Microcontroller
1. Preparation
1.1 Wiring Instructions
The hardware utilized in this example includes a Hiwonder bus servo, a bus servo control board, and an STM32F103C8T6 minimum system board. With the bus servos properly connected and powered on, refer to the wiring diagram below for the connection between the bus servo controller and the STM32 microcontroller. For details on using the bus servo controller and bus servos, refer to the Bus Servo Controller User Manual, located in the tutorial under the path: Bus Servo Controller\1. Tutorials\1. Bus Servo Controller User Manual\01 Bus Servo Controller User Manual.pdf.
Image 1 Wiring diagram for the bus servo control board and the STM32F103C8T6 minimum system board.
2. Project Development
2.1 Case 1: Controlling Multiple Servos
In this example, the microcontroller sends serial commands to the bus servo controller via UART, and the controller then drives the bus servos accordingly. The serial communication protocol between the microcontroller and the bus servo controller follows the Bus Servo Controller Communication Protocol provided by Hiwonder, located at: Bus Servo Controller\1. Tutorials\2. Bus Servo Controller Secondary Development\01 Servo Controller Communication Protocol\Bus Servo Controller Communication Protocol.pdf.
2.2 Brief Analysis of the Example Program
Because the STM32F103C8T6 minimum system board features multiple UART pins, the pin selection and serial program configuration can be modified to suit specific application requirements.
- Microcontroller UART Pin Configuration
-
Serial Data Transmission Function
-
Servo Rotation Control Function
-
Main Function Implementation
This main function first initializes the USART serial port for communication with the servos. It then enters an infinite loop, where it controls servos with ID 1 and 2. The servos first move from their current position to position 0 within a 100 ms motion duration, followed by a 1000 ms delay. Then they move from position 0 to position 1000 within a 500 ms motion duration, followed by another 1000 ms delay. This process repeats continuously, enabling servos 1 and 2 to perform periodic back-and-forth motion between position 0 and 1000.
3. Other Functions
-
Retrieving Control Board Voltage and Reading Current Angular Positions of Multiple Servos
These two functions primarily transmit read commands to the bus servo controller via the TX pin. Upon receiving the command, the bus servo controller returns the requested data to the microcontroller RX pin. The returned data is formatted as a hexadecimal array. Detailed format parsing instructions are available within the Bus Servo Controller Communication Protocol document.
-
Controlling Servos to Execute Action Groups