There are many ways to measure the light intensity using a Raspberry Pi and one of them (that doesn’t require an ADC) is the TSL-235. It is a photodiode connected to a small circuit that generates a pulse of which the frequency depends on the light intensity. This frequency can be directly read out using a Raspberry Pi as explained below.
First check out the datasheet of the TSL-235, so you know you are not going to blow up your pi. I used the following layout to connect the TSL235 to the Pi:
TSL235 <-> PI Pin 1 GND - Pin GND Pin 2 VDD - Pin 1 3.3V Pin 3 Out - GPIO 25
Check this small Pi layout to see which pin is whereAs is writting in the datasheet, connect a 0.01-μF to 0.1-μF capacitor between the VCC and GND line close to the TSL-235.
I first tried to interface using a simple python script that just measures how long it takes before the GPIO pin falls again, inspired by this topic on Stackoverflow. However it didn’t run smoothly and the output was very noisy. Also running the script using ‘nice’ (to give it higher priority) didn’t work out. There for I switched to C, which runs obviously faster than python.
Luckily there is already a small script taking care of that on Github RaresPlescan/daisypi.
It relies on the famous Wiring Pi library that can be downloaded here and is easy to install:
git clone git://git.drogon.net/wiringPi cd wiringPi git pull origin cd wiringPi ./build
However the daisypi c version runs as root, to circumvent this put in /etc/local.rc the following to make GPIO port 25 readable as pi user
sudo -u pi /usr/local/bin/gpio export 25 in
I’ve forked the daisypi C file which makes use of wiringPiSetupSys() instead of wiringPiSetup()
Download this version here: https://github.com/EvdH0/daisypi/blob/master/sense/tsl235r/t13.c
gcc -o tsl_read t13.c -lm -lrt -L/usr/local/lib -lwiringPi -lwiringPiDev
Next the executable can be run using
./tsl_read 300000 10
This takes about 5 seconds and results in some output like this
TSL235READ--poll_time--itterations--avg_value--autoscale 300000 10 47.000 16384