Page 1 of 1

Python GPIO status question

Posted: Tue Apr 12, 2016 3:48 pm
by a2carat
Hello, I'm new to python, I'm working on a small project to control the garage door. Along with opening and closing I want to monitor the door like if its open more than x amount of time and there is motion to send me an alert, also it will send mi an alert whenever is open and close or not fully open/closed ( I have two sensors to monitor if its fully open or close).

My question is would it be better to write a big program with all these things all checking a boolean to see if its open or close. or have little scripts all checking into a database to see if its opened or closed? I know I cant have all checking at the same time the status of the sensors thus why I would have the status put into the DB.

Felix

Re: Python GPIO status question

Posted: Wed Apr 13, 2016 7:44 am
by paddyg
I don't think you would need a big program really. The extra functionality is only few lines for each thing you want to check (and get sent a message for). In fact you could structure your program so different conditions (and relevant GPIO pins) were in a list so the marginal extra code would only be a few characters. (But thinking about how to do that: it might be rather subtle coding if you are just learning)

Re: Python GPIO status question

Posted: Wed Apr 13, 2016 8:58 am
by StuckPI
I am only learning and i keep taking on cool projects :D
I can help you a bit in the pseudo code and logic for the program the others are correct its not a big program.

the door has only 2 states open or closed:
So the first thing to do is create a variable called doorstate, this holds a single digit value 0 = closed 1 = open

Now i dont know how much sensors you applied, but you just need a when doorstate = 1 then timer run = true, loop, update total open time.

while doorstate = 1
tick tock
Add time counter
read total from file, add time counter to total.
(for advanced logs you could add a few lines of code to time/date/duration and then at the very end total time.)

Control functions:
Open door - send gpio
Close door - send gpio / check if time counter holds any value
Check door - READ gpio-in.

(alternatives would be offer options based on state:
check door state - toggle option.
check door state - toggle log-out
)

As stated im still learning, but you can see not a lot is involved, the above is not code, just the logic behind what would become code for you.
Hope it shows its not a big huge program.