Lesson 6 How To Control DC Motor
Lesson 6 How To Control DC Motor
Raspberry Pi 1
Robot HAT 1
DC Motor 1
Support email:
2
2. Enter the command and press Enter to enter the folder where the program is located:
cd adeept_picarpro/server/
Support email:
3
ls
5. After running the program successfully, you will observe that the Motor will rotate for about 1
second and then stop, and the program will also stop. If you need the motor to rotate again, you need
to run the program again.
1. import time
2. import RPi.GPIO as GPIO
3.
4. Motor_A_EN =4
5. Motor_A_Pin1 = 26
6. Motor_A_Pin2 = 21
Import the dependent library, where Motor_EN = 4, Motor_Pin1 = 26, Motor_Pin2 = 21 are the
parameters of the corresponding interface motorA.
Support email:
4
6. GPIO.setup(Motor_A_Pin1, GPIO.OUT)
7. GPIO.setup(Motor_A_Pin2, GPIO.OUT)
8.
9. motorStop()
10. try:
11. pwm_A = GPIO.PWM(Motor_A_EN, 1000)
12. except:
13. pass
1. def destroy():
2. motorStop()
3. GPIO.cleanup() # Release resource
4.
Set the motor stop function.
1. try:
2. speed_set = 60
3. setup()
4. move(speed_set, 'forward', 'no', 0.8)
5. time.sleep(1.3)
6. motorStop()
7. destroy()
8. except KeyboardInterrupt:
Support email:
5
9. destroy()
Support email: