Development Process for Controlling Bus Servo Rotation with an STM32 Microcontroller and TTL Debugging Board
Preparation
Wiring Instructions
The hardware used in this example includes a Hiwonder serial bus servo, a Hiwonder TTL / USB Debugging Board, and an STM32F103C8T6 minimum system board. After the serial bus servo and the debug board are connected successfully, refer to the wiring diagram below.
For instructions on using the debug board and serial bus servo, refer to the Servo Debug Board User Manual in the following directory: 3 Servo Manual & Diagram \02 Bus Servo Debug Board Manual\Servo Debug Board User Manual.
After wiring the board as shown above, the microcontroller does not need a separate power supply.
Case Development
Case 1: Control the Rotation of a Single Servo
In this case, the microcontroller sends serial commands to the debug board. The debug board then controls the serial bus servo. The serial port protocol between the microcontroller and the debug board follows the Bus Servo Communication Protocol in the following directory: 3 Servo Manual & Diagram\01 Bus Servo Communication Protocol\Bus Servo Communication Protocol_V2.0.
Brief Analysis of the Example Program
The STM32F103C8T6 minimum system board has multiple serial port pins. Select the pins and configure the serial port program according to the actual hardware setup.
- Microcontroller serial port pin configuration
- Serial port data sending function
- Servo rotation control function
- Main function
This main function first initializes the USART serial port used for servo communication, then enters an infinite loop. In the loop, the servo with ID 1 first rotates from its current position to the 900-degree position with a movement duration of 1000 ms. After a delay of 2000 ms, it rotates from 900 degrees to the 200-degree position with a movement duration of 1000 ms. After another delay of 2000 ms, the loop repeats. This makes servo 1 move back and forth periodically between 200 degrees and 900 degrees.