Page 1 of 1

Detect GPIO states at program start

Posted: Wed May 15, 2013 10:04 pm
by jakebpg
OK here's the question:
I've built a system to control lights and environmental controls for my cabin. All works fine as currently programmed except for the fact that when I close the app and restart it the app resets all gpios to out with a state value of 0(off). I want the program to detect current setting and pin values(if light 1 is on it needs to stay on, if the air is on it needs to stay on). But restarting the program clears all gpios. I'm using the quick2wire module.
How do I go about checks the states before it resets every thing?

I think this is the line that is resetting the gpios:
pin1 = Pin(int(sys.argv[1]) if len(sys.argv) > 1 else 12, Pin.Out) # = gpio 18

So how do I detect this?
Is there a different way to set the gpios?
Is there a better package to use then the quick2wire module for python? Keep in mind that a normal user needs to be able to execute the program, NOT root!

Any help would be greatly appreciated.

Re: Detect GPIO states at program start

Posted: Thu May 16, 2013 11:37 am
by cae2100
I believe the setup routines for the gpio pins will reset them no matter what you try, but just an odd suggestion, maybe try outputting the settings to a text file/configuration file, and have it save settings on exit, and load the settings on startup, then it'll tell what's what.

Re: Detect GPIO states at program start

Posted: Thu May 16, 2013 8:46 pm
by jakebpg
I already thought of that, but it is a huge problem for environmental devices, like air-conditioning, heating not to mention dehumidifiers.

With lights it's not a big problem but for the others it is a huge problem if they are running when the program restarts. This program is controlling multiple relays, hence the need to work around needed to prevent the resetting of the GPIOs every-time the program is started.