I'm using the RPi.GPIO library to control a the GPIO pins on my RPi, I have a 12 bit ADC which is bit-banged to get the data in a similar manner to this tutorial on adafruit. This has been working well as a temperature logging circuit from a couple of TMP37 analogue thermometers.

I am now wanting to expand the use to monitor a flashing LED on my electricity meter and have constructed a photo-transistor circuit which works well as a receiver. When combining these two projects with the python code

import RPi.GPIO as GPIO
import pi_breakout
import time

PHOTOIN=14 # GPIO pin connected to Photo sensor

def elecpulsecallback(ch_num):
    print "pulse on ch {:d}".format(ch_num)

GPIO.setup(11, GPIO.OUT) #
GPIO.setup(9, GPIO.OUT) #
GPIO.setup(PHOTOIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(PHOTOIN, GPIO.RISING, callback=elecpulsecallback, bouncetime=200)
while True:
    n=pi_breakout.readadc(1, 17,9,10,11) # bit bang code in separate file
    print n

I see the elecpulsecallback callback code fired every time I make a call to the ADC. It seems to happen whichever pin I have the PHOTOIN assigned to even though the callback argument always indicates that it is PHOTOIN that is rising. If I shorten the bouncetime I can get multiple events.

Can anyone spot what I'm doing wrong?

EDIT: I seem to have solved the problem. On closer inspection of the pin voltages, GPIO was at ~1.4V when the pull_up_down=GPIO.PUD_UP or pull_up_down=GPIO.PUD_OFF. Snipping the 3.3V zenner I had on the input for protection seems to have solved the problem.

  • Could be a wiring problem, generation noise on GPIO 14. Could you post a photo of your wiring?
    – Gerben
    Nov 28, 2013 at 16:52
  • I'm using a breakout board based on this thebox.myzen.co.uk/Raspberry/Breakout.html I'll take a photo over the weekend. It's not specific to GPIO14. It seems to fire whichever pin I set PHOTOIN to be.
    – mor22
    Nov 29, 2013 at 11:28

1 Answer 1


Solved by snipping the 3.3V zenner I had on the input for protection

  • care to explain what you mean by 'snipping'? As a non-native English speaker I don't get what you did :)
    – ExploWare
    Mar 13, 2014 at 20:20
  • 1
    Snipping means to cut thought, or to remove
    – mor22
    Mar 25, 2014 at 11:14

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.