Keep GPIO from resetting on program restart.(not the pi)

This forum is for topics specific to the Raspberry Pi and Arch Linux ARM

Keep GPIO from resetting on program restart.(not the pi)

Postby jakebpg » Thu May 16, 2013 9:34 pm

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). Now when this happens it also resets all the relays turning everything 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). Using a file to hold states when closing will not work because it will not stop the resetting of the gpios on restart of the program. The gpios are left in their current state when closing the app. But restarting the program clears all gpios. I'm using the quick2wire module. Now this program does leave the gpios in the state set in order to keep devices running when closing the app.

How do I go about checking 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
Could some one explain what the above line is doing exactly? And is there another way to initialize the gpios then as in the above statement?

I've tried this package RPi.GPIO-0.5.2a but it requires root to use it, and that is a no no since this software will be accessed over the net.

So how do I detect this?
Is there a different way to set the gpios in python(other then quick2wire)?
Is there a better package to use besides 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.
jakebpg
 
Posts: 21
Joined: Fri Sep 14, 2012 3:27 pm
Location: NE, USA

Re: Keep GPIO from resetting on program restart.(not the pi)

Postby sdjf » Thu May 30, 2013 12:54 am

You might run a separate script that stores the state every 60 seconds (or whatever frequency of sleep you want) and stores that in a file. I have a script I have running that records the unix time every 60 seconds in a file so programs can access that without a real time clock when I reboot the pi or after a crash, and you could do similar. When program starts, read the contents of that file. Or only read it's contents under certain conditions, depending on what works for your situation.

Also, probably you would want to store the prior 1 or 2 readings in backup files if the most recent reading is not right, you would have to fiddle with it, like we do with most scripts until they suite our needs.
sdjf
 
Posts: 178
Joined: Wed May 08, 2013 1:55 pm

Re: Keep GPIO from resetting on program restart.(not the pi)

Postby jakebpg » Thu May 30, 2013 1:35 pm

$this->bbcode_second_pass_quote('sdjf', 'Y')ou might run a separate script that stores the state every 60 seconds (or whatever frequency of sleep you want) and stores that in a file. I have a script I have running that records the unix time every 60 seconds in a file so programs can access that without a real time clock when I reboot the pi or after a crash, and you could do similar. When program starts, read the contents of that file. Or only read it's contents under certain conditions, depending on what works for your situation.

Also, probably you would want to store the prior 1 or 2 readings in backup files if the most recent reading is not right, you would have to fiddle with it, like we do with most scripts until they suite our needs.


Thanks for the reply, but that does not answer my question. I've though of that also but it creates a huge problem if the air-conditioner or heater are running when the gpios are rest when starting the program a second, third or even forth time.

Any environmental equipment can not just be turned off and on when a program starts and can actually damage said equipment.

I've figured out how to detect if the gpios are on or off at program startup and avoid resetting them at program startup now. If anyone else wishes to know how to do it I'll be glad to post an example here for you. 8-) 8-)
jakebpg
 
Posts: 21
Joined: Fri Sep 14, 2012 3:27 pm
Location: NE, USA

Re: Keep GPIO from resetting on program restart.(not the pi)

Postby WarheadsSE » Thu May 30, 2013 6:14 pm

I'd suggest posting, whether anyone asks or not, for future references.
Core Developer
Remember: Arch Linux ARM is entirely community donation supported!
WarheadsSE
Developer
 
Posts: 6807
Joined: Mon Oct 18, 2010 2:12 pm


Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 4 guests