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.

  • Do you mean GPIO23 on pin 16? See pinout.xyz – joan May 6 at 16:43
  • I do not see this behaviour. Can you include a small script which demonstrates the behaviour? – joan May 6 at 16:48
  • @joan yes i'll try this again with a simpler pyhton script. there might have been something else interfering. – buti May 6 at 16:57
  • @joan indeed i can't reproduce this with a short script. i also currently can't run the original code since i blew the adafuit motor hat that is usually connected. i'll report back when i have rechecked. – buti May 6 at 17:28
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.

  • That sounds like a bug. It probably shouldn't be tidying up a resource it is not using. – joan May 14 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.