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.

asked Oct 4, 2015 at 20:42
2
  • 1
    Can we see a pic(s) of your wiring? What is the other side of the button connected to? Commented Oct 4, 2015 at 22:24
  • GPIO 13 is connected to pin 33 on the 40 pin expansion header. Which pin is connected to your switch? Commented Oct 4, 2015 at 22:33

1 Answer 1

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"

answered Oct 5, 2015 at 0:26
1
  • 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. Commented Oct 5, 2015 at 9:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.