I have build the circuit board and have successfully run the python code for testing a Photocell LDR as documented on the Adafruit web site:
http://learn.adafruit.com/basic-resisto ... ll-reading
For various reasons, not least for the challenge, I have tried to transpose the code into PHP as per below, but it only returns a series of zeros.
Code: Select all
<?php
# Light Sensor - loops until cancelled by CTL-C
exec("modprobe w1-gpio");
function Getgpio22()
{
$reading = 0;
# Discharge capacitor
# set up GPIO 22 direction to OUT and value to low
exec("echo \"22\" > /sys/class/gpio/export");
exec("chmod 777 -R /sys/class/gpio/gpio22");
exec("echo \"out\" > /sys/class/gpio/gpio22/direction");
exec("echo \"0\" > /sys/class/gpio/gpio22/value");
sleep(0.1);
# set up GPIO 22 direction to IN
exec("echo \"in\" > /sys/class/gpio/gpio22/direction");
while (exec("cat /sys/class/gpio/gpio22/value") ==0)
{
# Count loops until voltage across
# capacitor reads high on GPIO
$reading++;
}
return $reading;
}
while (true)
{
print Getgpio22();
}
?>
Thanks!