-
Notifications
You must be signed in to change notification settings - Fork 0
/
feeder.py
81 lines (64 loc) · 2 KB
/
feeder.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/python3
import RPi.GPIO as GPIO
import time
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--step-count", help="Input step count", type=int, default=4096)
args = parser.parse_args()
in1 = 17
in2 = 22
in3 = 23
in4 = 24
# careful lowering this, at some point you run into the mechanical limitation of how quick your motor can move
step_sleep = 0.002
# args.step_count = 4096 # 5.625*(1/64) per step, 4096 steps is 360
direction = False # True for clockwise, False for counter-clockwise
# defining stepper motor sequence (found in documentation http://www.4tronix.co.uk/arduino/Stepper-Motors.php)
step_sequence = [[1,0,0,1],
[1,0,0,0],
[1,1,0,0],
[0,1,0,0],
[0,1,1,0],
[0,0,1,0],
[0,0,1,1],
[0,0,0,1]]
# setting up
GPIO.setmode( GPIO.BCM )
GPIO.setup( in1, GPIO.OUT )
GPIO.setup( in2, GPIO.OUT )
GPIO.setup( in3, GPIO.OUT )
GPIO.setup( in4, GPIO.OUT )
# initializing
GPIO.output( in1, GPIO.LOW )
GPIO.output( in2, GPIO.LOW )
GPIO.output( in3, GPIO.LOW )
GPIO.output( in4, GPIO.LOW )
motor_pins = [in1,in2,in3,in4]
motor_step_counter = 0 ;
def cleanup():
GPIO.output( in1, GPIO.LOW )
GPIO.output( in2, GPIO.LOW )
GPIO.output( in3, GPIO.LOW )
GPIO.output( in4, GPIO.LOW )
GPIO.cleanup()
# the meat
try:
i = 0
for i in range(args.step_count):
for pin in range(0, len(motor_pins)):
GPIO.output( motor_pins[pin], step_sequence[motor_step_counter][pin] )
if direction==True:
motor_step_counter = (motor_step_counter - 1) % 8
elif direction==False:
motor_step_counter = (motor_step_counter + 1) % 8
else: # defensive programming
print( "uh oh... direction should *always* be either True or False" )
cleanup()
exit( 1 )
time.sleep( step_sleep )
except KeyboardInterrupt:
cleanup()
exit( 1 )
cleanup()
exit( 0 )