Page 1 of 1

GPIO input not working in BCM mode?

Posted: Sun Mar 10, 2013 1:37 pm
by Jerd
Hi all!

I wounder what i'm doing wrong. I'm trying to get a button press to work with a small simple script. I've followed RPiMag issue 5, and want to read if GPIO 0 (pin 3) is connected to ground (pin 6) or not.

The following code is not working:

Code: Select all

from time import sleep
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(0, GPIO.IN)

while True:
   if (GPIO.input(0) == 0):
      print("Button!")
   sleep(0.5);
If i change to GPIO.setmode(GPIO.BOARD) and GPIO.setup(3, GPIO.IN) and change the if statement to check for input on 3 it works.

Any idea how to get it working with GPIO.BCM mode? What am i doing wrong?

Best regards /Jon

Re: GPIO input not working in BCM mode?

Posted: Sun Mar 10, 2013 1:42 pm
by jojopi
If you have a Revision2 Pi (the board has mounting holes), then P1 pin3 is BCM GPIO2, not GPIO0.

Re: GPIO input not working in BCM mode?

Posted: Sun Mar 10, 2013 1:46 pm
by Jerd
This is problably the error - is there somewhere an image of GPIO pins of board rev2?

Is it still hardwired with a 1.8kOhms resistor?

Re: GPIO input not working in BCM mode?

Posted: Sun Mar 10, 2013 5:31 pm
by metachris
http://elinux.org/RPi_Low-level_periphe ... .28GPIO.29 (note that the image shows Rev1 and the table below both revisions)