-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDRV8825.py
57 lines (41 loc) · 1.51 KB
/
DRV8825.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import RPi.GPIO as GPIO
import time
#this class is for configuring and cotrolling the stepper motors
MotorDir = [
'forward',
'backward',
]
class DRV8825():
def __init__(self, dir_pin, step_pin, enable_pin, mode_pins):
self.dir_pin = dir_pin
self.step_pin = step_pin
self.enable_pin = enable_pin
self.mode_pins = mode_pins
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(self.dir_pin, GPIO.OUT)
GPIO.setup(self.step_pin, GPIO.OUT)
GPIO.setup(self.enable_pin, GPIO.OUT)
GPIO.setup(self.mode_pins, GPIO.OUT)
def digital_write(self, pin, value):
GPIO.output(pin, value)
def Stop(self):
self.digital_write(self.enable_pin, 1)
def TurnStep(self, Dir, steps, stepdelay=0.005):
if (Dir == MotorDir[0]):
self.digital_write(self.enable_pin, 0)
self.digital_write(self.dir_pin, 0)
elif (Dir == MotorDir[1]):
self.digital_write(self.enable_pin, 0)
self.digital_write(self.dir_pin, 1)
else:
print ("the dir must be : 'forward' or 'backward'")
self.digital_write(self.enable_pin, 1)
return
if (steps == 0):
return
for i in range(steps):
self.digital_write(self.step_pin, True)
time.sleep(stepdelay)
self.digital_write(self.step_pin, False)
time.sleep(stepdelay)