Código para Latch físico: Stepper_open.py1. #!/usr/bin/env python
# Import required libraries
import time
import RPi.GPIO as GPIO
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Define GPIO signals to use
# As input IN1,IN2,IN3,IN4
# As Coils A A B B
StepPins = [22, 23, 24, 25]
# NUM PIN Color
# 1 A Black/NEGRO----| COIL A
# 2 A Brawn/MARRON---/
# 3 B Orang/NARANJA--
# 4 B Yello/AMARILLO-| COIL B
# Set all pins as output
def SetPins():
for pin in StepPins:
print "Setup GPIO%i as output" %(pin)
GPIO.setup(pin,GPIO.OUT)
# Set all pins as output
def PinsOff():
for pin in StepPins:
GPIO.output(pin, False)
# ----------------------------
SetPins()
PinsOff()
# Define simple sequence
SeqFull = []
SeqFull = range(4)
# A A B B
SeqFull[0] = [ 1, 0, 1, 0 ]
SeqFull[1] = [ 0, 1, 1, 0 ]
SeqFull[2] = [ 0, 1, 0, 1 ]
SeqFull[3] = [ 1, 0, 0, 1 ]
# Define advanced sequence
# as shown in manufacturers datasheet
SeqHalf = []
SeqHalf = range(8)
# A A B B
SeqHalf[0] = [ 1, 0, 1, 0 ]
SeqHalf[1] = [ 0, 0, 1, 0 ]
SeqHalf[2] = [ 0, 1, 1, 0 ]
SeqHalf[3] = [ 0, 1, 0, 0 ]
SeqHalf[4] = [ 0, 1, 0, 1 ]
SeqHalf[5] = [ 0, 0, 0, 1 ]
SeqHalf[6] = [ 1, 0, 0, 1 ]
SeqHalf[7] = [ 1, 0, 0, 0 ]
# Define some settings
StepCounter = 0
WaitTime = 0.025
2. # Choose a sequence to use
Seq = SeqFull
StepCount = len(Seq)
def NextStep(Count,Step,Dir):
Next=int(Step)+int(Dir)
if Next==Count:
Next=0
elif Next==-1:
Next=Count-1
return Next
# Start main loop
StepPerRev=24*(StepCount/4)
GoSteps = StepPerRev+4
CurrentSetp = 0
Dir = 1
Step = 0
while GoSteps != CurrentSetp:
try:
CurrentSetp = CurrentSetp + 1
Step=NextStep(StepCount,Step,Dir)
# Set 4 pin status
for pin in range(4):
if Seq[Step][pin]!=0:
GPIO.output(StepPins[pin], True)
else:
GPIO.output(StepPins[pin], False)
# Wait a sleep time
time.sleep(WaitTime)
except KeyboardInterrupt:
print " break!"
PinsOff()
exit(1)
#
PinsOff()
exit(0)