I am using gpiozero
to control devices on the Raspberry Pi. When I create a reference to (for example) an LED device, there is a parameter for creating the object without effecting it's current state: initial_state=None
. (The default is initial_state=False
, which automatically turns the value off upon reference object creation) The problem is it always seems to reset the hardware pin on script exit (though oddly enough not the internal "state"). What's worse, when I run the script again, it knows the state I left it in, and puts the physical pin back to that state!
Here's my jumpers on/off program, it now has a pausing input, during which the state stays unchanged, but when the program exits, the pins reset. (Though as I mention above, the state is "remembered")
#!/usr/bin/env python
from __future__ import print_function
import sys
import time
from gpiozero import LED
jump1=LED(17,initial_value=None)
jump2=LED(27,initial_value=None)
if len(sys.argv)>1:
print ("Jumper were: (%s,%s)"%(str(jump1.is_active),str(jump2.is_active)))
if sys.argv[1].lower() == 'on':
jump1.on()
jump2.on()
print ('turned both on')
elif sys.argv[1].lower() == 'off':
jump1.off()
jump2.off()
print ('turned both off')
print ("Jumper Currently: (%s,%s)"%(str(jump1.is_active),str(jump2.is_active)))
raw_input("Press enter to exit.")
Does anyone know a way to tell gpiozero
to leave the hardware alone after exit? This question details a similar problem, though a different module.
(Edit: it turns out the gpiozero module changes the pin direction to input but doesn't change the output latch, which is how it gets the old state back when the pin direction is changed back to output.)