I've hooked up an LDR to a pi's GPIO and ground pin directly. I set up the internal pull-up resistor on the broadcom chip. This created essentially a voltage divider, that would make the pin would read low if a led shined on it, and high is not.
Since you only need a yes/no answer there is no need to measure the time to charge a cap, just like analog-to-digital converters do. You just need the voltage to be either above or below the tripping point of the GPIO for either state of the led.
The tripping point for the gpio seems to be around 1.2v (http://www.youtube.com/watch?v=Wr49ia3oID4).
So under normal lighting condition the voltage should be above 1.2v. When the led is shining on the LDR, the voltage should be above 1.2v.
Just note that in my setup I've taped the LDR to the led with black tape, so the LDR is in complete darkness. You probably have to have some external pull-up resister that better matches the resistance of the LDR. Some variable resistor (pot) would be a cheap and handy way to calibrate.
My sample test script for reading the gpio pin.
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import subprocess
GPIO.setmode(GPIO.BOARD)
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
state = GPIO.input(26)
if state == 0 :
print "LDR: 0"
else :
print "LDR: 1"
time.sleep(.5)
As for the interrupts. Not sure if that was really the question. You could do something like.
channel = 26
def my_callback(channel):
print('This is a edge event callback function!')
print('Edge detected on channel %s'%channel)
print('This is run in a different thread to your main program')
GPIO.add_event_detect(channel, GPIO.RISING, callback=my_callback) # add rising edge detection on a channel
More info at http://code.google.com/p/raspberry-gpio-python/wiki/Inputs
Or just ask me later, as I'm currently not near the pi of mine that uses gpio interrupts for triggering.