-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicStepperGPIO.py
67 lines (57 loc) · 1.79 KB
/
BasicStepperGPIO.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
60
61
62
63
64
65
66
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
# Define the GPIO pins for the L298N motor driver
OUT1 = 12
OUT2 = 11
OUT3 = 13
OUT4 = 15
# Set the GPIO pins as output
GPIO.setup(OUT1, GPIO.OUT)
GPIO.setup(OUT2, GPIO.OUT)
GPIO.setup(OUT3, GPIO.OUT)
GPIO.setup(OUT4, GPIO.OUT)
GPIO.output(OUT1,GPIO.LOW)
GPIO.output(OUT2,GPIO.LOW)
GPIO.output(OUT3,GPIO.LOW)
GPIO.output(OUT4,GPIO.LOW)
num_steps = 200
step_delay = 0.03
try:
while True:
current_step = 0
for x in range(num_steps):
if current_step == 0:
GPIO.output(OUT1,GPIO.HIGH)
GPIO.output(OUT2,GPIO.LOW)
GPIO.output(OUT3,GPIO.HIGH)
GPIO.output(OUT4,GPIO.LOW)
time.sleep(step_delay)
#print("step 0")
elif current_step == 1:
GPIO.output(OUT1,GPIO.LOW)
GPIO.output(OUT2,GPIO.HIGH)
GPIO.output(OUT3,GPIO.HIGH)
GPIO.output(OUT4,GPIO.LOW)
time.sleep(step_delay)
#print("step 1")
elif current_step == 2:
GPIO.output(OUT1,GPIO.LOW)
GPIO.output(OUT2,GPIO.HIGH)
GPIO.output(OUT3,GPIO.LOW)
GPIO.output(OUT4,GPIO.HIGH)
time.sleep(step_delay)
elif current_step == 3:
GPIO.output(OUT1,GPIO.HIGH)
GPIO.output(OUT2,GPIO.LOW)
GPIO.output(OUT3,GPIO.LOW)
GPIO.output(OUT4,GPIO.HIGH)
time.sleep(step_delay)
if current_step == 3:
current_step = 0
continue
current_step = current_step + 1
GPIO.cleanup()
break
except KeyboardInterrupt:
GPIO.cleanup()