leon-anavi / rpi-examples

Raspberry Pi examples
MIT License
149 stars 83 forks source link

Issue with TSL2561 Code #2

Closed mcummings1 closed 7 years ago

mcummings1 commented 7 years ago

Hello Leon!

First of all, thank you for your example code - I've gotten a fair amount of mileage out of what I've worked with so far, very much appreciated!

I am however having an issue with the TSL2561 Flora Lux Sensor. I have tried both the code in example and the code in example-wiringpi with similar results. When I first ran the software, I got large numbers (i.e., 65535) for my lux value along with an Input/output error. This was because I had to change the address to the LOW value (hard coded on the Flora Lux - verified with I2CDetect). Now, however, I always receive 0. This is the case in both examples - example and example-wiringpi.

To try and do some high level debugging, I edited TSL2561_test.c again and printed out the return code for each function; OPEN SETGAIN SETINTEGRATIONTIME SENSELIGHT

Everything returns 0, which appears to be normal based upon what I'm seeing in the lower level code. I also tried playing with the gain, integration time and library auto gain, just to see if anything I did gave me a different value, but 0 on all values all the time.

Before I dive headfirst into your lower level code, is there anything you might suggest I look into? I looked at a few other examples to use, but I really much prefer going with your C code at this point, especially after the HTU21D code has proven to be so helpful!

Alright, thank you so much in advance for any assistance you might be able to provide!

Respectfully, Marshall

leon-anavi commented 7 years ago

Hi Marshall,

Could you please double check that the wiring of the sensor is correct? What is the I2C address of your sensor?

I am using a cheap TSL2561 sensor module that I bought from ebay. After attaching it to Raspberry Pi I can see the sensor as:

pi@raspberrypi:~/rpi-examples $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- 39 -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

After that the usage of the examples is straight-forward. The second example uses library wiringPi:

pi@raspberrypi:~/rpi-examples $ cd TSL2561/c/example
example/          example-wiringpi/ 
pi@raspberrypi:~/rpi-examples $ cd TSL2561/c/example
example/          example-wiringpi/ 
pi@raspberrypi:~/rpi-examples $ cd TSL2561/c/example/
pi@raspberrypi:~/rpi-examples/TSL2561/c/example $ make
gcc -c -o TSL2561.o TSL2561.c -I.
gcc -c -o TSL2561_test.o TSL2561_test.c -I.
gcc -o TSL2561_test TSL2561.o TSL2561_test.o -I.
pi@raspberrypi:~/rpi-examples/TSL2561/c/example $ sudo ./TSL2561_test 
Test. RC: 0(Success), broadband: 80, ir: 13, lux: 8
pi@raspberrypi:~/rpi-examples/TSL2561/c/example $ cd ..
pi@raspberrypi:~/rpi-examples/TSL2561/c $ cd example-wiringpi/
pi@raspberrypi:~/rpi-examples/TSL2561/c/example-wiringpi $ make
gcc -c -o TSL2561.o TSL2561.c -I.
gcc -o TSL2561 TSL2561.o -I. -lwiringPi
pi@raspberrypi:~/rpi-examples/TSL2561/c/example-wiringpi $ sudo ./TSL2561 
Lux: 10

Best regards, Leon

mcummings1 commented 7 years ago

Good morning Leon,

Well, this is a little embarrassing, but I didn't want to just leave you hanging - it turns out that the device I've been working with is actually the TCS34725, not the TSL2561 at all! When I used the appropriate code for the device - everything works as it should! Sorry for the confusion!

Just the same, my thanks to you for the code I did successfully use for the HTU21D-F, not to mention your response above. Have a great day!

Sincerely, Marshall

leon-anavi commented 7 years ago

Hi Marshall,

Thank you for the feedback and no worries. Btw feel free to add an example about TCS34725 to this project. I will be more than happy to review and merge a GitHub pull request with such an example :)

Best regards, Leon