Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Solved: GPIO button only works after setting it to pull down manually
#1
I have an issue where a button (connected to GPIO 26) only works after I manually set pin 26 to be used as pull down, by running the following Python code:

Code:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

So I thought a workaround would be to run the above script in /etc/rc.local, but this doesn´t solve the problem. I checked that the script is run at startup by adding other lines of code to it.

I connected the button between 3V3 and GPIO 26 (which should be pulled down, so I connected it to the right pins... right?). I also tried other GPIO pins between 9 and 27, but the same problem persists.

Is there a file where I can check (and change) the default mode (pulled up / pulled down) all the pins have after startup? I think I need to change it there.
Reply
#2
I found a solution. The "problem" is that GPIO pins are always configured as pull-up in the software. This is also clearly stated in point 3 on the GPIO control configuration page  Rolleyes

So I changed line 59 in /var/www/daemon/gpio_buttons.py from
Code:
GPIO.setup(sw_1_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
to
Code:
GPIO.setup(sw_1_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

Now that I have the solution, I think I remember having the same problem a couple of years ago, but I just forgot how to fix it. Anyway, it would be nicer to be able to do this on the config page, because I have the change the source code after every update, which I just forget to do, apparently...
Reply


Forum Jump: