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
#print GPIO.VERSION
PHOTOIN=14 # GPIO pin connected to Photo sensor
def elecpulsecallback(ch_num):
print "pulse on ch {:d}".format(ch_num)
GPIO.setup(17, GPIO.OUT) # CPICLK
GPIO.setup(11, GPIO.OUT) #
GPIO.setup(9, GPIO.OUT) #
GPIO.setup(10, GPIO.IN) # SPIMISO
GPIO.setup(PHOTOIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.remove_event_detect(PHOTOIN)
GPIO.add_event_detect(PHOTOIN, GPIO.RISING, callback=elecpulsecallback, bouncetime=200)
while True:
time.sleep(0.2)
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.