-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpi_Stepper_Motor_Control_2.py
59 lines (49 loc) · 1.84 KB
/
pi_Stepper_Motor_Control_2.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
57
58
59
# python 3
# by Chris Martin 12/6/2020
# Modified for Raspberry Pi by Tom Watts
# Uses a TMC2209 v3.0
# Enable TMC2209(pin 1) to RPi GPIO24 (pin 18), Direction TMC2209(pin8) to RPi GPIO23 (pin 16)
# M1 TMC2209(pin 2) to RPi GPIO7 (pin 26), M2 TMC2209(pin 3) to RPi GPIO25 (pin 22),M3 (8825 only) pin 4 to RPi GPIO 22 (pin 15)
# step TMC2209(pin 7) to RPi GPIO18 (pin 12)
# Import Modules
import time
import subprocess
import RPi.GPIO as GPIO
# motorcontrol class
class motorcontrol(object):
# intitialize
def __init__(self,
enable=24,
direct=23,
M1_port=7,
M2_port=25,
step=18):
self.enable = enable
self.direct = direct
self.M1_port = M1_port
self.M2_port = M2_port
self.step = step
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(step, GPIO.OUT)
self.pwm = GPIO.PWM(step, 100)
GPIO.setup(direct, GPIO.OUT) #direction
GPIO.setup(enable, GPIO.OUT) #enable
GPIO.setup(M1_port, GPIO.OUT) #M1
GPIO.setup(M2_port, GPIO.OUT) #M2
GPIO.setup(step, GPIO.OUT) #stepper
print ("Stepper Motor initialised")
# destructor
def cutpower(self):
self.pwm.stop()
GPIO.output(self.enable,1) #set to one to disable
GPIO.cleanup()
def zaxis(self,direction,active,frequency,m1,m2,duty,runtime):
if active==1:
GPIO.output(self.direct,direction) #direction
GPIO.output(self.enable,0) #enable
GPIO.output(self.M1_port,m1) #M1
GPIO.output(self.M2_port,m2) #M2
self.pwm.start(duty) #run for time
time.sleep(runtime)
self.pwm.stop()