Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #-----------------------------------
  2. # Name: Stepper Motor
  3. #
  4. # Author: matt.hawkins
  5. #
  6. # Created: 11/07/2012
  7. # Copyright: (c) matt.hawkins 2012
  8. #-----------------------------------
  9. #!/usr/bin/env python
  10.  
  11. # Import required libraries
  12. import time
  13. import RPi.GPIO as GPIO
  14. import sys
  15.  
  16.  
  17. # Use BCM GPIO references
  18. # instead of physical pin numbers
  19. GPIO.setmode(GPIO.BCM)
  20.  
  21. # Define GPIO signals to use
  22. # Pins 18,22,24,26
  23. # GPIO24,GPIO25,GPIO8,GPIO7
  24. StepPins = [17,22,23,24]
  25. #StepPins = [17,18,21,22]
  26.  
  27. # Set all pins as output
  28. for pin in StepPins:
  29. print "Setup pins"
  30. GPIO.setup(pin,GPIO.OUT)
  31. GPIO.output(pin, False)
  32.  
  33. # Define some settings
  34. StepCounter = 0
  35. WaitTime = 0.004
  36.  
  37.  
  38. # Define simple sequence
  39. StepCount1 = 4
  40. Seq1 = []
  41. Seq1 = range(0, StepCount1)
  42. Seq1[0] = [1,0,0,0]
  43. Seq1[1] = [0,1,0,0]
  44. Seq1[2] = [0,0,1,0]
  45. Seq1[3] = [0,0,0,1]
  46.  
  47. # Define advanced sequence
  48. # as shown in manufacturers datasheet
  49. StepCount2 = 8
  50. Seq2 = []
  51. Seq2 = range(0, StepCount2)
  52. Seq2[0] = [1,0,0,0]
  53. Seq2[1] = [1,1,0,0]
  54. Seq2[2] = [0,1,0,0]
  55. Seq2[3] = [0,1,1,0]
  56. Seq2[4] = [0,0,1,0]
  57. Seq2[5] = [0,0,1,1]
  58. Seq2[6] = [0,0,0,1]
  59. Seq2[7] = [1,0,0,1]
  60.  
  61. # Choose a sequence to use
  62. Seq = Seq1
  63. StepCount = StepCount1
  64.  
  65.  
  66. delete_TO = 0.0083
  67.  
  68. time_start = time.time()
  69. seconds = 0
  70.  
  71. # Start main loop
  72. while True:
  73. for pin in range(0, 4):
  74. xpin = StepPins[pin]
  75. if Seq[StepCounter][pin]!=0:
  76. print " Step %i Enable %i" %(StepCounter,xpin)
  77. GPIO.output(xpin, True)
  78. else:
  79. GPIO.output(xpin, False)
  80.  
  81. StepCounter += 1
  82.  
  83. # If we reach the end of the sequence
  84. # start again
  85. if (StepCounter==StepCount):
  86. StepCounter = 0
  87. if (StepCounter<0):
  88. StepCounter = StepCount
  89.  
  90. # Wait before moving on
  91. time.sleep(WaitTime)
  92.  
  93. seconds = int(time.time() - time_start)
  94. print seconds
  95. if seconds > 10:
  96. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement