Guest User

Untitled

a guest
Jan 13th, 2022
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import RPi.GPIO as gpio
  5. import time, sys
  6.  
  7.  
  8. class easydriver(object):
  9. def __init__(self,pin_step=0,delay=0.0001,pin_direction=0,pin_ms1=0,pin_ms2>
  10. self.pin_step = 8
  11. self.delay = delay / 3000
  12. self.pin_direction = 7
  13. self.pin_microstep_1 = pin_ms1
  14. self.pin_microstep_2 = pin_ms2
  15. self.pin_microstep_3 = pin_ms3
  16. self.pin_sleep = pin_sleep
  17. self.pin_enable = pin_enable
  18. self.pin_reset = pin_reset
  19. self.name = name
  20.  
  21. gpio.setmode(gpio.BCM)
  22. gpio.setwarnings(False)
  23.  
  24. if self.pin_step > 0:
  25. gpio.setup(self.pin_step, gpio.OUT)
  26. if self.pin_direction > 0:
  27. gpio.setup(self.pin_direction, gpio.OUT)
  28. gpio.output(self.pin_direction, True)
  29. if self.pin_microstep_1 > 0:
  30. gpio.setup(self.pin_microstep_1, gpio.OUT)
  31. gpio.output(self.pin_microstep_1, False)
  32. if self.pin_microstep_2 > 0:
  33. gpio.setup(self.pin_microstep_2, gpio.OUT)
  34. gpio.output(self.pin_microstep_2, False)
  35. if self.pin_microstep_3 > 0:
  36. gpio.setup(self.pin_microstep_3, gpio.OUT)
  37. gpio.output(self.pin_microstep_3, False)
  38. if self.pin_sleep > 0:
  39. gpio.setup(self.pin_sleep, gpio.OUT)
  40. gpio.output(self.pin_sleep,True)
  41. if self.pin_enable > 0:
  42. gpio.setup(self.pin_enable, gpio.OUT)
  43. gpio.output(self.pin_enable,False)
  44. if self.pin_reset > 0:
  45. gpio.setup(self.pin_reset, gpio.OUT)
  46. gpio.output(self.pin_reset,True)
  47.  
  48.  
  49. def step(self):
  50. gpio.output(self.pin_step,True)
  51. time.sleep(self.delay)
  52. gpio.output(self.pin_step,False)
  53. time.sleep(self.delay)
  54.  
  55. def set_direction(self,direction):
  56. gpio.output(self.pin_direction,direction)
  57.  
  58. def set_full_step(self):
  59. gpio.output(self.pin_microstep_1,False)
  60. gpio.output(self.pin_microstep_2,False)
  61. gpio.output(self.pin_microstep_3,False)
  62.  
  63. def set_half_step(self):
  64. gpio.output(self.pin_microstep_1,True)
  65. gpio.output(self.pin_microstep_2,False)
  66. gpio.output(self.pin_microstep_3,False)
  67.  
  68. def set_quarter_step(self):
  69. gpio.output(self.pin_microstep_1,False)
  70. gpio.output(self.pin_microstep_2,True)
  71. gpio.output(self.pin_microstep_3,False)
  72.  
  73. def set_eighth_step(self):
  74. gpio.output(self.pin_microstep_1,True)
  75. gpio.output(self.pin_microstep_2,True)
  76. gpio.output(self.pin_microstep_3,False)
  77.  
  78. def set_sixteenth_step(self):
  79. gpio.output(self.pin_microstep_1,True)
  80. gpio.output(self.pin_microstep_2,True)
  81. gpio.output(self.pin_microstep_3,True)
  82.  
  83. def sleep(self):
  84. gpio.output(self.pin_sleep,False)
  85.  
  86. def wake(self):
  87. gpio.output(self.pin_sleep,True)
  88.  
  89. def disable(self):
  90. gpio.output(self.pin_enable,True)
  91.  
  92. def enable(self):
  93. gpio.output(self.pin_enable,False)
  94.  
  95. def reset(self):
  96. gpio.output(self.pin_reset,False)
  97. time.sleep(1)
  98. gpio.output(self.pin_reset,True)
  99.  
  100. def set_delay(self, delay):
  101. self.delay = delay / 200
  102.  
  103. def finish(self):
  104. gpio.cleanup()
  105.  
Advertisement
Add Comment
Please, Sign In to add comment