-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib_stepper.py
More file actions
63 lines (51 loc) · 1.67 KB
/
lib_stepper.py
File metadata and controls
63 lines (51 loc) · 1.67 KB
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
import RPi.GPIO as GPIO
import time
#
# 1 1 1 1 1 1 2 2 2 2 3 3 3 3 3 4
# 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | | | | | | | | | | | | | | | | | | | | |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | | | | | | | | | | | | | | | |A|B|C|D| |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
# 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9
#
# A : GPIO-06 : Pin 31 : Line 1 : Blue
# B : GPIO-13 : Pin 33 : Line 2 : Pink
# C : GPIO-19 : Pin 35 : Line 3 : Yellow
# D : GPIO-26 : Pin 37 : Line 4 : Orange
#
# https://tutorials-raspberrypi.com/how-to-control-a-stepper-motor-with-raspberry-pi-and-l293d-uln2003a/
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# The correct mapping should be: Pink, Orange, Blue, Yellow
gpioPins = [13, 26, 6, 19]
# The sequence of pin energisation for a single step:
pinSequence = [[0,1,0,0], [0,1,0,1], [0,0,0,1], [1,0,0,1], [1,0,0,0], [1,0,1,0], [0,0,1,0], [0,1,1,0]]
for pin in gpioPins:
GPIO.setup(pin, GPIO.OUT)
def setStep(step):
GPIO.output(gpioPins[0], step[0])
GPIO.output(gpioPins[1], step[1])
GPIO.output(gpioPins[2], step[2])
GPIO.output(gpioPins[3], step[3])
return
def setNone():
for i in range(4):
GPIO.output(gpioPins[i], 0);
return
def backwards(delay, steps):
for i in range(steps):
for j in range(len(pinSequence)):
setStep(pinSequence[j])
time.sleep(delay)
setNone()
return
def forwards(delay, steps):
for i in range(steps):
for j in reversed(range(len(pinSequence))):
setStep(pinSequence[j])
time.sleep(delay)
setNone()
return