I try to port my GPIO project from quick2wire to WiringPi. My aim is to read the state of a photocell connected to pin 24 of my raspberry pi (model B, revision 2).
My code (python 3) looks like this:
import wiringpi2 as wiringpi
import time
wiringpi.wiringPiSetupSys()
# wiringpi.wiringPiSetupGpio() # it would work with this instead of wiringPiSetupSys()
counter = 0
status = "unknown"
while True:
counter += 1
light = wiringpi.digitalRead(24)
if not light:
status = "ON"
else:
status = "OFF"
time.sleep(3)
print('(' + str(counter) + ') ' + status)
When I wiringpi.wiringPiSetupGpio()
instead of wiringpi.wiringPiSetupSys()
the code works as expected. Using wiringpi.wiringPiSetupSys()
however the output doesn't change - it would stay ON
or OFF
no matter how the state of the photo cell changes.
I also made sure that the pin is exported
$ gpio exports
GPIO Pins exported:
5: in 0 none
As I checked the state of the photocell with gpio gpio -g read 24
in the shell, I can exclude the possibility of a hardware issue.
As I want to use the code in a web application, I would strongly prefer to use wiringPiSetupSys()
as a non-root user.
Can you help me solve or analyze the cause of this issue?