Guest User

NEMAStepper.py

a guest
Jan 25th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. import time
  2. import RPi.GPIO as GPIO
  3.  
  4. GPIO.setmode(GPIO.BOARD)
  5. GPIO.setwarnings(FALSE)
  6.  
  7. A=7
  8. B=11
  9. C=13
  10. D=15
  11.  
  12. sleep_time = 0.01
  13.  
  14. def GPIO_SETUP(a, b, c, d):
  15.     GPIO.output(A, a)
  16.     GPIO.output(B, b)
  17.     GPIO.output(C, c)
  18.     GPIO.output(D, d)
  19.     time.sleep(sleep_time)
  20.  
  21. def RIGHT_TURN(deg, step):
  22.  
  23.     GPIO_SETUP(0, 0, 0, 0)
  24.  
  25.     if step == "full":
  26.         print"Fullstepping", deg, "Degrees"
  27.  
  28.     if step == "half":
  29.         print"Halfstepping", deg, "Degrees"
  30.  
  31.     while deg > 0.0:
  32.         if step == "half":
  33.             GPIO_SETUP(1,0,0,1)
  34.             GPIO_SETUP(1,0,0,0)
  35.             GPIO_SETUP(1,1,0,0)
  36.             GPIO_SETUP(0,1,0,0)
  37.             GPIO_SETUP(0,1,1,0)
  38.             GPIO_SETUP(0,0,1,0)
  39.             GPIO_SETUP(0,0,1,1)
  40.             GPIO_SETUP(0,0,0,1)
  41.             print "Degree left", deg
  42.             deg = deg -1.0
  43.  
  44.         if step == "full":
  45.             GPIO_SETUP(1,0,0,0)
  46.             GPIO_SETUP(0,1,0,0)
  47.             GPIO_SETUP(0,0,1,0)
  48.             GPIO_SETUP(0,0,0,1)
  49.             print "Degree left", deg
  50.             deg = deg -1.0
  51.  
  52. RIGHT_TURN(90, "full")
  53.  
  54. GPIO.cleanup()
Add Comment
Please, Sign In to add comment