08-25-2016, 06:53 AM
(08-25-2016, 01:17 AM)vigor Wrote: Alright, the relay via GPIO project works, my python code attached at the bottom, one anomaly i noticed just now, whenever i power cycle or turn on the pine64 board, it triggers the relay, which is obviously a bad thing because my relay triggers the garage gate to open or close.
so then if power blips - my garage gate will open.
Any idea how to prevent GPIO blips on boot or on power on ?
my python code (no rocket science, and based on relay rpi lab):
import RPi.GPIO as GPIO ## Import GPIO library
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(15, GPIO.OUT)
GPIO.output(15,False)
time.sleep(4)
GPIO.output(15,True)
Unless one of the GPIO pins always starts up in a state that is usable as an 'off' state and stays that way until your python code can take over (which I wouldn't personally rely on), you're going to be out be out of luck. The pine64 is not suited for direct control of something like this, and needs a bit of help. Since it is a full blown computer, it has the inherent problem of things like the GPIO pin state being unreliable until they are initialised, it taking while for it to start up if it is powered down or reset, and the odd crash. So either it is better to use secondary boards that are intelligent enough to be able to wait for the pine64 to initialise / or can confirm/verify an command before doing something to make sure it's not a false trigger. Last thing you want is for the board to crash and in doing so... open your garage door for whoever wants to wander in...
To do the sort of thing you want to do, I would be considering using something like an 3v Arduino Nano to do the actual relay control (you can buy cheap clones for around $3 on eBay). This means you would have a chip/board that is dedicated to driving the relay. One way to get the two to communicate could be to connect the serial of the pine to the serial of the Arduino, meaning you could send a message via the serial to instruct the Arduino to trigger the relay on or off, and the Arduino could confirm that back. If invalid data goes over the serial to the arduino, it can just ignore it as it isn't what it's waiting for.
You might also have override switches on the Arduino for 'manual control' if the pine64 crashes and you just want to open/close the door. You can even take it a step further, and have the Arduino monitor the pine64 for a regular heartbeat, and if it doesn't see it, trigger a reset (basically a software emulation of a hardware watchdog timer).