2
votes

I am working on a Raspberry Pi garage door opener. I have the base code written so far, but I am looking to add one more thing in, but I'm not sure how to. For those of you who don't know, the Raspberry Pi has GPIO pins that can be set using Python scripts. I am using a script that sets a GPIO pin to high (5 volt output), staying on for 0.5 seconds, and then to low. The output is connected to a relay which is then connected to my garage door.

What I want to do is use the other GPIO pin to trigger an alarm for 2 seconds, and then set the state of the first GPIO pin to high, therefore opening the door. Here is what I have so far.

#!/usr/bin/python

# Import required Python libraries
import RPi.GPIO as GPIO
import time

# Use BCM GPIO references instead of physical pin numbers
GPIO.setmode(GPIO.BCM)

# init list with pin numbers
pinList = [2]

# loop through pins and set mode and state to 'low'
for i in pinList:
    GPIO.setup(i, GPIO.OUT)
    GPIO.output(i, GPIO.HIGH)

def trigger() :
    for i in pinList:
      GPIO.output(i, GPIO.LOW)
      time.sleep(0.5)
      GPIO.output(i, GPIO.HIGH)
      GPIO.cleanup()

try:
    trigger()
except KeyboardInterrupt:
    print "  Quit"

# Reset GPIO settings
GPIO.cleanup()

Can anyone help me figure out how to add another GPIO pin to trigger for 2 seconds, and THEN trigger the main relay to open the door?

1
You want to simultaneously set pin 2 & 3 to LOW & then pin 2 to HIGH after 2 seconds, to open the door?shad0w_wa1k3r
Please specify the order in which to set the state of the pins in order to accomplish your end goal.shad0w_wa1k3r

1 Answers

0
votes

I have used WiringPi a lot with Raspberry Pi to control the GPIO's directly as well as used it to interface other devices by SPI and I2C.

Here is the link to the python Libraries.

Once you have the libraries up and running, just use a variant of the code below:

import wiringpi
import time
wiringpi.pinMode(1,1)       #Set GPIO 1 to Output
wiringpi.pinMode(2,1)       #Set GPIO 1 to Output
wiringpi.digitalWrite(1,1)  #Write HIGH to pin1
time.sleep(2)               #2 sec delay
wiringpi.digitalWrite(2,1)  #Write HIGH to pin2

Just be careful with the outputs and inputs as the Raspberry Pi GPIO's run at 3.3v not 5v and you might end up destroying your Raspberry Pi if you are driving something big with it(the GPIO is rated for 16mA) or have faulty connections.