0

I am writing a script that should query if an input pin is configured as pull-up or pull-down using the RPi.GPIO package.

When configuring each output I can call

GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  # or
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

This is done by user input at runtime. After that my application needs to check if the user configured everything properly (one can never be sure!). Is there anything like GPIO.gpio_function(pin) but that will output the pull state of the input? (It would be a plus if it also returned the initial state of an output.)

Thanks in advance for taking the time to read!

2 Answers 2

0

It is impossible to determine the pull state of GPIO on most Pi (except by measurement).

It is possible with the BCM2711 used by Pi4 and I have written a Python3 library (based on RPi.GPIO) which does this and a program gpioread which shows this and the actual programmed function/state.

See https://raspberrypi.stackexchange.com/a/117593/8697

Corrupted git repository fixed. This can be downloaded

git clone https://github.com/Milliways2/Pi.GPIO.git

And installed with

sudo apt install python-dev python3-dev
sudo python3 setup.py install

NOTE you can also get pull using the raspi-gpio utility.

2
  • Thank you @Milliways for your answer and package suggestion. I tried installing it but when I execute sudo python3 setup.py build I get the error: package directory 'Pi' does not exist. Is there a step I'm missing? Thanks once more!
    – tron_ccp
    Commented Feb 23, 2021 at 17:47
  • @tron_ccp My apologies. The original git file got corrupted and lost its directory structure. It should now be fixed.
    – Milliways
    Commented Feb 24, 2021 at 0:54
0

You can't query the pull state with RPi.GPIO.

In fact you can only query the pulls in software in the latest Pi models based on the BCM2711. I'm not sure if any of the mainstream GPIO libraries actually provide support for doing so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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