I'm trying to run script which moving stepper motor. Everything is ok, when I run script via ssh terminal.
But when I run script with "sudo nohup script.py" or by adding to /etc/rc.local nothing happens.
Could you help me? My function:
Code: Select all
def motor_run(angle):
GPIO.setmode(GPIO.BCM)
for pin in pin_Motor:
print ("Setting GPIO pin:" + str(pin))
GPIO.setup(pin,GPIO.OUT)
GPIO.output(pin, False)
# Calculate direction
motor_direction = angle/abs(angle)
# Motor sequence from datasheet
motor_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]]
motor_stepcount = len(motor_sequence)
motor_count = 0
# Loop for entered angle
for i in range(0, int( abs(angle)*2*6.4) ):
a = i
print i
# Loop for each pin
for pin in range (0, 4):
#print pin
current_pin = pin_Motor[pin]
#print ("Output pin: " + str(current_pin))
if motor_sequence[motor_count][pin]!=0:
GPIO.output(current_pin, True)
else:
GPIO.output(current_pin, False)
motor_count += motor_direction
if (motor_count >= motor_stepcount):
motor_count = 0
if (motor_count < 0):
motor_count = motor_stepcount + motor_direction
sleep(motor_pause)
GPIO.cleanup()