Guest User

Untitled

a guest
Jan 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #!user/bin/python
  2.  
  3. import time
  4. import RPi.GPIO as GPIO
  5.  
  6. #Declare the GPIO settings
  7. #print "Set GPIO Board numbers"
  8. # to use Raspberry pi board pin numbers
  9. GPIO.setmode(GPIO.BOARD)
  10.  
  11. # set up GPIO pins
  12. GPIO.setup(7, GPIO.OUT) #Connected to PWMA
  13. GPIO.setup(11, GPIO.OUT) #Connected to AIN2
  14. GPIO.setup(12, GPIO.OUT) #Connected to AIN1
  15. GPIO.setup(13, GPIO.OUT) #Connected to STBY
  16. GPIO.setup(15, GPIO.OUT) #Connected to BIN1
  17. GPIO.setup(16, GPIO.OUT) #Connected to BIN2
  18. GPIO.setup(18, GPIO.OUT) #Connected to PWMB
  19.  
  20. #Specify the direct to turn the motor
  21. #Clockwise AIN1/BIN1 = HIGH and AIN2/BIN2 = LOW
  22. #Counter-Clockwise: AIN1/BIN1 = LOW and AIN2/BIN2 = HIGH
  23.  
  24. #First we will drive everything clockwise
  25. #Set the direction of Motor A
  26. GPIO.output(12, GPIO.HIGH) #Set AIN1
  27. GPIO.output(11, GPIO.LOW) #Set AIN2
  28. #Set the Speed / PWM for A
  29. GPIO.output(7, GPIO.HIGH) #Set PWMA
  30.  
  31. #Set the direction of Motor B
  32. GPIO.output(15, GPIO.HIGH) #Set BIN1
  33. GPIO.output(16, GPIO.LOW) #Set BIN2
  34. #Set the Speed / PWM for B
  35. GPIO.output(18, GPIO.HIGH) #Set PWMA
  36.  
  37. #Make sure STBY is disabled - Set it to HIGH
  38. GPIO.output(13, GPIO.HIGH)
  39.  
  40. time.sleep(5)
  41.  
  42. #Now drive the motor in the other direction (Counter Clockwise)
  43. #Set the direction of Motor A
  44. GPIO.output(12, GPIO.LOW) #Set AIN1
  45. GPIO.output(11, GPIO.HIGH) #Set AIN2
  46. #Set the Speed / PWM for A
  47. GPIO.output(7, GPIO.HIGH) #Set PWMA
  48.  
  49. #Set the direction of Motor B
  50. GPIO.output(15, GPIO.LOW) #Set BIN1
  51. GPIO.output(16, GPIO.HIGH) #Set BIN2
  52. #Set the Speed / PWM for B
  53. GPIO.output(18, GPIO.HIGH) #Set PWMA
  54.  
  55. #Make sure STBY is disabled - Set it to HIGH
  56. GPIO.output(13, GPIO.HIGH)
  57.  
  58. time.sleep(5)
  59.  
  60. #Now set everything to low (Switch everything Off)
  61. GPIO.output(12, GPIO.LOW) #Set AIN1
  62. GPIO.output(11, GPIO.LOW) #Set AIN2
  63. GPIO.output(7, GPIO.LOW) #Set PWMA
  64. GPIO.output(15, GPIO.LOW) #Set BIN1
  65. GPIO.output(16, GPIO.LOW) #Set BIN2
  66. GPIO.output(18, GPIO.LOW) #Set PWMA
  67. GPIO.output(13, GPIO.LOW) #Set STBY
Add Comment
Please, Sign In to add comment