Trailcam – 6. Control buttons

Other sections

  1. Introduction
  2. Basic setup & Power
  3. PIR sensor
  4. IR lamp
  5. IR filter
  6. Buttons
  7. Completed pics, improvements and parts list
  8. Updates

 

Description.

When the camera is put out in the garden it often drops the Wi-Fi link on the way so I wanted to fit the facility for a hardware button so that I could press it when the camera is positioned outside and re-establish the link.

buttons
The buttons on a small breadboard taken from my Pumoroni explorer hat (main). Buttons in place during “indoors mode” inset

When indoors & for testing I can use simple buttons however anything put outside stands the chance of being chewed so I’d like to be able to fit a waterproof button at a later date.

I’ve taken the button control straight from the main breakout board and it has the pull up resistors fitted before the male connector pegs, so it is simply a case of getting the new buttons fixed in the case and wiring on to them. I also added an LED that flashes (1, 2 or 3 times) depending upon which button is pressed.

main board

The button wiring has been a huge pain. The single core wires regularly snap at the join with the board resulting it a confusing mess of soldering and bodging. The board and wires perform perfectly and it is all an issue with my workmanship – this are would really benefit from having a custom PCM made.

The following basic python script monitors and controls the buttons / LED and is run at startup via my new favourite thing – cron!

Python prog

#! /usr/bin/python
 
import RPi.GPIO as GPIO
import os
import sys
import time
 
# set up button references
BUTTON1 = 18
BUTTON2 = 4
BUTTON3 = 7
GREEN = 3
 
 # set up buttons
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON1, GPIO.IN)
GPIO.setup(BUTTON2, GPIO.IN)
GPIO.setup(BUTTON3, GPIO.IN)
GPIO.setup(GREEN, GPIO.OUT)
# button 1 = green - reboot
# button 2 = yellow - restart wifi
# button 3 = red -
# turn light off
GPIO.output(GREEN,GPIO.LOW)
 
while True:
 if GPIO.input(BUTTON1) == GPIO.HIGH:
 print("button 1")
 GPIO.output(GREEN,GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.LOW)
 time.sleep(.5)
 os.system("sudo reboot")
 elif GPIO.input(BUTTON2) == GPIO.HIGH:
 print("button 2")
 GPIO.output(GREEN,GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.LOW)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.LOW)
 time.sleep(.5)
 os.system("sudo ifup --force wlan0")
 elif GPIO.input(BUTTON3) == GPIO.HIGH:
 print("button 3")
 GPIO.output(GREEN,GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.LOW)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.LOW)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.LOW)
 time.sleep(.5)
 else:
 print("pin is low")
 time.sleep(2)

Leave a Reply

Your email address will not be published. Required fields are marked *