Need support? support.freenove.com
Chapter 3 Module test (necessary)
Servo
Enter the following commands in the terminal to test servos.
If the terminal displays the directory as below (where test.py is located), you can directly execute the test.py
command.
1. If not, execute the cd command:
cd ~/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server
2. Execute test.py command:
sudo python test.py Servo
Result:
The servo 0 repeats rotating from left to right and then from right to left. The servo 1 repeats rotating from
bottom to top and then from top to bottom. You can press “Ctrl + C” to end the program.
The code is as below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from servo import *
pwm=Servo()
def test_Servo():
try:
while True:
for i in range(50,110,1):
pwm.setServoPwm('0',i)
time.sleep(0.01)
for i in range(110,50,-1):
pwm.setServoPwm('0',i)
time.sleep(0.01)
for i in range(80,150,1):
pwm.setServoPwm('1',i)
time.sleep(0.01)
for i in range(150,80,-1):
pwm.setServoPwm('1',i)
time.sleep(0.01)
except KeyboardInterrupt: