Jerd
Posts: 12
Joined: Sun Sep 30, 2012 8:35 pm

GPIO input not working in BCM mode?

Sun Mar 10, 2013 1:37 pm

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

User avatar
jojopi
Posts: 3079
Joined: Tue Oct 11, 2011 8:38 pm

Re: GPIO input not working in BCM mode?

Sun Mar 10, 2013 1:42 pm

If you have a Revision2 Pi (the board has mounting holes), then P1 pin3 is BCM GPIO2, not GPIO0.

Jerd
Posts: 12
Joined: Sun Sep 30, 2012 8:35 pm

Re: GPIO input not working in BCM mode?

Sun Mar 10, 2013 1:46 pm

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?

User avatar
metachris
Posts: 96
Joined: Wed Feb 06, 2013 1:52 pm
Location: Vienna, Austria

Re: GPIO input not working in BCM mode?

Sun Mar 10, 2013 5:31 pm

http://elinux.org/RPi_Low-level_periphe ... .28GPIO.29 (note that the image shows Rev1 and the table below both revisions)
pythonhosted.org/RPIO

Return to “Python”