-
Notifications
You must be signed in to change notification settings - Fork 677
Module for TSL2561 Light Sensor #137
Conversation
|
Hi Phil, As you may know, another pull request for a Adafruit_TSL2561 module was https://forums.adafruit.com/viewtopic.php?f=8&t=34922&p=430913#p430913 His is a very direct port of the Adafruit Arduino code which uses the I found (and debugged) two bugs that need to be fixed in your code: Bug #1: Bytes are swapped in 16-bit data from CHAN0 and CHAN1 Bug #2: The gain is applied incorrectly in the scaling for the lux calculation There is also a problem (possibly in my set up? python version?) that Thanks!
|
This actually started with debugging the fact that my TSL2561 returned 0x0A in its ID register when it was off but 0x00 when it was on. I subsequently realized two things: the bits are reversed from what the datasheet says, and I can use the ID register to distinguish between the T and CS packages, so that doesn't need to be an initialization parameter.
This was something I must have blindly copied from somewhere else. Chris Satterlee pointed out that it wasn't necessary, based on empirical testing. (The datasheet backs Chris up, too. It says that the register values are little-endian, and the I2C's readU16() method assumes little-endian data.)
I was dividing where I should have multipled, and vice versa. :(
I'm not sure whether this ever worked for me, but the old code certainly doesn't work on Python 2.7 for me now. The replacement code does what I intended the old code to do, plus adds a channel instance variable in case that's useful to anyone.
|
What's extra coincidental about the timing is that I wrote this module a couple of years ago and just recently decided that I ought to polish up the documentation and send a pull request. I think I've fixed up all of the problems you pointed out. (In particular, I got the channel scaling pretty much completely backwards, which explains why 16x mode always looked weird to me. It should be right now; I get consistent results when switching between modes, at least. I don't have any other light sensors to compare my readings to, though.) Also in here are some improvements to the use of the contents of the ID register. My original code was copied from the Arduino code (which looks a little off now; instead of |
|
Thank you for the Pull Request Visit https://circuitpython.org/blinka for more information CircuitPython has support for almost 200 different drivers, and a as well as FT232H support for Mac/Win/Linux! |
This includes a module for interacting with the TSL2561 light sensor. I hope that the main class's documentation is sufficient for use. If you have any questions or problems, please let me know.