0

I have counter which is sending pulse every second to GPIO 2 and I wrote the following code to detect it

#!/usr/bin/python
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def my_callback(channel):
    print "edge detected on 3"
GPIO.add_event_detect(2, GPIO.BOTH, callback=my_callback)
GPIO.cleanup()

and I run the code using sudo python test.py but this code doesn't do anything, it just exits. I have checked using multimeter so pulse in being send to pin 3.

1
  • 1
    Note that there are 3 different ways of numbering the GPIO pins. Broadcom GPIO pin 2 isn't connected to GPIO header of the Pi. Try using GPIO.setmode(GPIO.BOARD) and changing 2 to some other number, as pin 2 is the 5volt line.
    – Gerben
    Dec 11, 2013 at 14:28

2 Answers 2

1

GPIO 2 (board 3) is intended for I2C connections and has a pull-up resistor permanently connected - the pull_up_down option will therefore have no effect. I don't believe it's possible to pull this (or board pin 5) to ground while the pin is configured as an input.

I can only suggest you try using a different pin to detect the external signal.

0

Pin P1-3 is connected to gpio#2 on Rev.2 boards and gpio#0 on Rev.1 boards.

It has a 1K8 pull-up to 3V3 so your pulse will need to be pulling the signal low for it to have any effect.

You could use gpio#4 (pin P1-7) and have a pull-down rather than a pull-up if you are sending a high pulse.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.