I have written a script to open/close my roller shutter using two buttons and a relay. One button to open, one button to close.
Here is my script :
import RPi.GPIO as GPIO import time relay_pin = 18 down_button_pin = 17 up_button_pin = 27 GPIO.setmode(GPIO.BCM) GPIO.setup(relay_pin, GPIO.OUT) GPIO.setup(down_button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(up_button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) def main(): while True: # Get the state of each button (pressed or not) down_input_state = GPIO.input(down_button_pin) up_input_state = GPIO.input(up_button_pin) # Button is pressed if down_input_state == False: print('Button Down Pressed') GPIO.output(relay_pin, GPIO.LOW) time.sleep(5) if up_input_state == False: print('Button Up Pressed') GPIO.output(relay_pin, GPIO.HIGH) time.sleep(5) try: main() except KeyboardInterrupt: GPIO.cleanup() finally: GPIO.cleanup()
When I run the script, everything is working as expected :
$ python button_relay.py
But when I try to run it in the background :
$ python button_relay.py &  29690
the script does not work anymore.
What am I missing here ?
Raspberry Pi 3 Model B
General advises about my script are also welcome.