1

enter image description hereUsing a very simple input script to read a button press, Python GPIO isn't reading high when the button is pressed. The wiring is correct - I have checked it using wiringpi readall.

Rpi. GPIO has been updated and is current and I've run the pintest script to test all pins are OK.

Is there anything I'm missing that could cause Rpi. GPIO to miss a high input pin that wiringpi is detecting?

My code is:

import RPi.GPIO as GPIO  
GPIO.setmode(GPIO.BCM)
GPIO.setup(13, GPIO.IN) 
try:
      while True:           
        if GPIO.input(13):  
            Print("button pressed")

Edit: I should have mentioned that I've already tried the pull up/downs, and even tried using physical resistors - still the same result (Without the resistors, I can see from wiringpi that the input is floating.)

I'm not at home to send a photo of the wiring - here's a sketch of the setup. However, I don't believe the physical setup is the issue since wiringpi is picking up the input without issue - it's just Python GPIO that's not behaving.

  • 1
    Can we see a pic(s) of your wiring? What is the other side of the button connected to? – Steve Robillard Oct 4 '15 at 22:24
  • GPIO 13 is connected to pin 33 on the 40 pin expansion header. Which pin is connected to your switch? – joan Oct 4 '15 at 22:33
1

Consider setting the GPIO pin as a pull up or pull down resistor.
For example:
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP)
That sets it as a pull up resistor meaning of it is exposed to ground it will trigger the button being pressed.
You can read it with:
if GPIO.input(13) == False:
Print "desired print text"

  • Thanks for your suggestion - I should have mentioned that I've already tried the pull up/downs, and even tried using physical resistors - still the same result. Without the resistors, I can see from wiringpi that the input is floating. – pa1983 Oct 5 '15 at 9:24

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.