1
votes

I am using RPi.GPIO Raspberry Pi GPIO library.

I know how to set an output to high or low, but i need to set it as high impedance.

GPIO.output(PIN, GPIO.HIGH)  # or GPIO.LOW

Is there a way to set the output as "high impedance", something like:

GPIO.output(PIN, GPIO.FLOAT)

so that the output is floating and constrained by surrounding circuitry only? (like the drain or collector of a MOS or BJT)?

A possible way would be switch the pin mode to input and set pull up/down resistors to no pullup or pull down, is this the only way, or there is a better solution?

1
First and main recommendation is to forget about custom RPi GPIO library and switch to generic libgpiod.0andriy
Interesting the fact it is "generic"; can you please link some documentation? Is there a "learning path" where i can know what is standard/generic versus odd/custom?Ettore Galli
GitHub page github.com/brgl/libgpiod probably. For the record libgpiod is hosted on kernel.org. Linux kernel provides a tons of ABIs, and many tools either as examples (tools/gpio/) or ready-to-go (tools/perf/). kernel.org hosts the official libraries and tools for some of ABIs.0andriy

1 Answers

2
votes

Setting the pin to input and disabling the pull-up/-down resistors seems the way to go. You would have to define a helper function that accepts low, high and float as parameters.

FLOAT:

GPIO.setup(port_or_pin, GPIO.IN, pull_up_down=GPIO.PUD_OFF)

LOW:

GPIO.setup(port_or_pin, GPIO.OUT)
GPIO.output(self.reset_pin, GPIO.LOW)

HIGH:

GPIO.setup(port_or_pin, GPIO.OUT)
GPIO.output(self.reset_pin, GPIO.HIGH)