3

In order to use a GPIO connected button as a power off switch I have set a pullup for pin 23 in a dtb overlay (following http://blog.gegg.us/2017/01/setting-up-a-gpio-button-keyboard-on-a-raspberry-pi/ and https://github.com/fivdi/onoff/wiki/Enabling-Pullup-and-Pulldown-Resistors-on-The-Raspberry-Pi).

Now in python, when I import gpiozero the pin seems to be "reset" and the pullup drops. I don't intend to use pin 23 at all in python. How can I tell gpiozero to leave it alone? Actually i would have assumed the individual pins to only be configured when first used with gpiozero.

RalfFriedl
  • 2,180
  • 2
  • 11
  • 12
buti
  • 141
  • 3

1 Answers1

1

After more testing I found out that there was still active code trying to access GPIO23. As GPIO23 is in use by the kernel, the declaration btn23 = Button(pin=23, pull_up=True) fails with RuntimeError: Failed to add edge detection, which apparently was silently caught in a try/except block.

When an exception is thrown while declaring a Button, the cleanup routine is called and this is where the pullup gets reset. Since there is no way of querying the pullup state of a GPIO on the raspberry pi hardware (https://raspberrypi.stackexchange.com/a/76568/103352) it can't be reset to its previous (pulled up) state and hence becomes floating.

I don't think gpiozero can handle this any better than it currently does.

buti
  • 141
  • 3