I'm working on a project in which I have to set a GPIO pin of the Raspberry Pi to high/low in order to signal a transponder which in turn communicates with a lock and opens it when it receives a high signal. For reading and writing to the GPIO, the RPi.GPIO library for Python is used.
All goes well and executes as it should on the first run. However, it appears the output of the pin remains high even after it should have been set to low. So when the script has been executed once after booting the Raspberry Pi, the pin remains high. The script executes without any warnings and/or errors. The continuous high signal confuses the transponder.
import RPi.GPIO as GPIO
import time
class GPIODoor(object):
"""Can be used to open a door at physical/Board pin 5.
In the current revision (2) this is known as GPIO 01"""
def __init__(self):
GPIO.setmode(GPIO.BOARD)
GPIO.setup(5, GPIO.OUT)
def openDoor(self, duration = 0):
"""Sends the open door command to the transponder.
@duration [Optional] the time the relay is switched to high"""
GPIO.output(5, True)
time.sleep(duration)
GPIO.output(5, False)
GPIO.cleanup()
print('1')
if __name__ == '__main__':
door = GPIODoor()
door.openDoor()
Above script is being called from a PHP script as follows:
// some irrelevant class code
exec('sudo python /path/to/script.py', $output);
if ( $output[0] == '1' ) {
return true;
}
return false;
Note that the given path is not the actual path used. In order to allow PHP to execute the Python script, the www-data user is given the permission to do so in the /etc/sudoers
file. This is similar to what is described here.
Now my question is: is anyone able to tell me why the pin remains high? Is it a mistake in my script? Am I missing some initial setup of the GPIO?