Skip to content

Instantly share code, notes, and snippets.

@jaskiratsingh2000
Created March 24, 2022 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaskiratsingh2000/0eede22f8e2c6e5e87bd8eba0e7e5fb8 to your computer and use it in GitHub Desktop.
Save jaskiratsingh2000/0eede22f8e2c6e5e87bd8eba0e7e5fb8 to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
import time
#GPIO Mode (BOARD / BCM)
GPIO.setmode(GPIO.BCM)
#Setting GPIO Pins for the Motor A
DirMotorA = 27
PwmMotorA = 22
#Setting GPIO pins for the Motor B
DirMotorB = 23
PwmMotorB = 24
# setting up GPIO Pins direction for the Motor A
GPIO.setup(DirMotorA, GPIO.OUT)
GPIO.setup(PwmMotorA, GPIO.OUT)
# setting up GPIO Pins direction for the Motor B
GPIO.setup(DirMotorB, GPIO.OUT)
GPIO.setup(PwmMotorB, GPIO.OUT)
# Driving the motor Clockwise that is FORWARD
#MAX Frequency is 20 Hz
leftMotorAPWM = GPIO.PWM(PwmMotorA, 20)
leftMotorAPWM.start(0)
leftMotorAPWM.ChangeDutyCycle(0)
righttMotorAPWM = GPIO.PWM(PwmMotorA, 20)
rightMotorAPWM.start(0)
rightMotorAPWM.ChangeDutyCycle(0)
# Driving the motor Clockwise that is FORWARD
GPIO.output(DirMotorA, HIGH)
GPIO.output(DirMotorB, LOW)
time.sleep(1)
# Driving the motor Anti-Clockwise that is BACKWARD
GPIO.output(DirMotorA, LOW)
GPIO.output(DirMotorB, HIGH)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment