Close

Bench Test Success - Alpha

A project log for Home Automation - Garage Door Opener

Extract best practices from existing garage door projects. Build version that suites my needs; eventually integrate into other HA efforts.

luffmanbluffmanb 03/23/2016 at 04:480 Comments

In the end, I got everything working in a bench setup--including prevention of unintended relay activation during RPi reboot. Then... I accidentally killed bootup of uSD card by trying to test a power outage scenario--thankfully I had already saved my working Python script to main computer.

In short, here was my setup:

Components & Circuit:

Simple Snap Circuits test circuit:

Software:

A single Python script named garageCtrl.py as follows:

#!/usr/bin/env python2.7
# Purpose: Testing garage door state toggle via relay triggered by button on RPi. For use in garage w/o keyboard/monitor.
# Button1 - (P23) Kill program
# Button2 - (P24) Trigger relay
# Relay   - (P18) Toggle garage door opener next state

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

def my_callback(channel):
  print "Rising edge detected on port 24, in the main thread."
  GPIO.output(18, False)
  time.sleep(0.1)
  GPIO.output(18, True)

print "Press Button #1 (P23) to kill program."
print "Press Button #2 (P24) to trigger relay."
#raw_input("Press Enter when ready\n")

GPIO.add_event_detect(24, GPIO.RISING, callback=my_callback, bouncetime=300)

try:
  print "Waiting for falling edge on port 23"
  GPIO.wait_for_edge(23, GPIO.FALLING)
  print "Falling edge detected. Here endeth the second lesson."
except KeyboardInterrupt:
  GPIO.cleanup()  # clean up GPIO on CTRL+C exit
GPIO.cleanup()    # clean up GPIO on normal exit
Raspbian Configuration:

In order enter a "ready" state automatically upon applying power to the RPi, I tweak the OS configuration as follows:

  1. At bottom of .bashrc file, added line: sudo ./garageCtrl.py
  2. Modified /etc/inittab line 1:2345:respawn:/sbin/getty --noclear 38400 tty1 with line 1:2345:respawn:/sbin/getty --autologin pi --noclear 38400 tty1
  3. Changed boot-up to console rather than X-Window via raspi-config tool.

These changes cause the RPi to bootup headless (w/o GUI resource overhead), automatically login, and finally execute python program to listen for button presses that trigger the relay/garage door opener.

Garage Door Test:

It works on the bench lighting up an LED, but just for validation-sake also confirmed it worked in the garage by replacing the Snap Circuit node w/ leads to the garage door opener's contacts 1 & 2.

Discussions