paveliche
Posts: 2
Joined: Sat May 16, 2015 10:21 pm

GPIO doesn't work with nohup

Wed Dec 02, 2015 5:05 am

Hi, All!

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()

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: GPIO doesn't work with nohup

Wed Dec 02, 2015 9:55 am

the function looks OK (though it'll barf if angle == 0)
what does the rest of the program look like?
missing sudo on the comandline somewhere?

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO doesn't work with nohup

Wed Dec 02, 2015 10:01 am

GPIO do work with nohup.

Why not tell us the command you issue and the system's response?

Return to “Python”