Welcome to Raspbot repository
5.3 Drive servo
1. Learning target
In this course, we will learn how to drive servo of car.
2. Principle
On the drive board of the Raspbot car, we have integrated 4 servo pin interfaces, which are located in the places as shown below(S1~S4).
The driver chip TB6612 of the servo is not directly connected to the Raspberry Pi pins.
The Raspberry Pi communicates with the STM8 MCU through the IIC, and the STM8 MCU drives the TB6612 chip to drive the servo.
Wiring of the servo:
The brown wire of the servo needs to be connected to the pin marked "-" on the expansion board.
The red wire of the servo needs to be connected to the pin marked "+" on the expansion board.
The orange wire of the servo needs to be connected to the pin marked "IO" on the expansion board.
Raspbot car camera platform possess two servos, which are connected to the S1 and S2 ports respectively.
3. Coding method
STM8 is connected to SDA.1, SCL.1 on the Raspberry Pi board.
The pin comparison table of Raspberry Pi as shown below.
In this course, we use BOARD coding method.
We have provided a library text dedicated to driving motors and servos --YB_Pcb_Car.py.
It is located in the same directory as the motor driver.
4. About code
Path: /home/pi/Yahboom_project/Raspbot/2.Hardware Control course/2.Drive servo
1) Import time and YB_Pcb_Car library
2) Control the two servos to move to the middle position.(90°).
3) Control the two servos to move to the middle position.(0°).
4) Control the two servos to move to the middle position.(180°).
5) After using, we need to release the car object, otherwise, when the next program needs to use the object, it will be unusable due to it is occupied.
5. Running code
Click the button shown in the figure below to run the program on the Jupyter Lab interface
6. Experimental phenomena
Two servo will rotate to 90°--> 0°--> 180°.