Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output pins left in floating state instead of low input state after program end #1146

Open
Nilles3D opened this issue May 17, 2024 · 1 comment

Comments

@Nilles3D
Copy link

Operating system: Raspbian Bookworm
Python version: 3.11.2
Pi model: Pi 3 Model B
GPIO Zero version: 2.0
Pin factory used: lgpio

Pins that are at default state "input, pull-down" and called as "output" by the LED class are left floating after the pin is closed.

Discussion has been had at the RPI forum, and there were two possible conclusions:

  1. The default pull value is deactivated, changed, or removed on close
  2. The libgpiod ownership is closed instead of released

The test code was run originally with v1.6.2 on Bullseye and then later with v2.0 on Bookworm to the same effect.

import gpiozero as gp
from time import sleep

pinB=gp.LED(19) #theoretically an unused, unset pin

pinB.blink(n=2)
sleep(2) #voltages seen at expected levels during this time
pinB.off() #not necessary after blink thread is done
sleep(1) #pin is held at Ground

pinB.close() #not required, but added for completeness
#voltages rise to and persist at 0.9V - 1.9V
@Nilles3D
Copy link
Author

Patch proposed in the same forum:
https://forums.raspberrypi.com/viewtopic.php?p=2222393#p2222445

class LGPIOPin(LocalPiPin):
    ...
    def close(self):
        return # ++ HIPPY FIX ++
        if self.factory._handle is not None:
            # Closing is really just "resetting" the function of the pin;
            # we let the factory close deal with actually freeing stuff
            lgpio.gpio_claim_input(
                 self.factory._handle, self._number, lgpio.SET_PULL_NONE)
            
    def _get_function(self):
    ...      

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant