Welcome to Pico Robot Car repository
3.8 Servo control
3.8 Servo control
1. Learning objectives
- Learn the servo interface and PWM servo of the Raspberry Pi Pico 2/Pico mainboard and the car expansion board to conduct experiments.
- Understand the use of PWM servos.
2. Hardware use
This course uses the servo interface and PWM servo of the Pico 2/Pico mainboard and the car expansion board. When connecting the PWM servo, pay attention to the corresponding color of the connecting wire and the color of the pin header.

The basic control principle of the PWM servo is to use the PWM signal to generate a signal with a period of 20ms and a duty cycle of 0.5~2.5ms, thereby controlling the servo angle.
3. Program Analysis
Code path: Code -> 1.Basic course -> 8. Servo control.py
xfrom pico_car import pico_carServo = pico_car()#180 servo S1 angle 0#the parameters are (steering gear number, steering gear angle)Servo.servo180(1,0)#270 servoServo.servo270(2,90)#360 servoServo.servo360(3,360)
from pico_car import pico_car
Use pico_car of pico_car, which encapsulates the servo driver library.
Servo = pico_car()
Initialize the servo.
Servo.servo180(1,0)
Set the angle of 180-degree PWM servo S1 to 0 degrees.
Servo.servo270(2,90)
Set the angle of 270-degree PWM servo S2 to 90 degrees.
Servo.servo360(3,360)
Set the angle of 360-degree PWM servo S3 to 360 degrees.
4. Experimental Phenomenon
After the program is downloaded, we can see that the 180-degree servo, 270-degree servo, and 360-degree servo inserted in S1-S3 are at the positions of 0 degrees, 90 degrees, and 360 degrees respectively.