TSL2561 Digital Light Sensor

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
MiPy
Posts: 3
Joined: Sat Sep 12, 2015 3:22 pm

TSL2561 Digital Light Sensor

Post by MiPy » Sat Sep 12, 2015 3:29 pm

Hello,

has anyone used the TSL2561 over I2C with the PyBoard? I'm trying to find a library for the sensor but nothing so far. Eventually I want to use I with the WiPy for some smart home applications once it arrives.

Thanks for your help!

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: TSL2561 Digital Light Sensor

Post by kfricke » Mon Feb 08, 2016 11:34 pm

I do have one of those lying around here somewhere. Maybe i can soon find some spare minutes to write a small module for those.

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: TSL2561 Digital Light Sensor

Post by kfricke » Thu Feb 11, 2016 10:50 pm

Most basic stuff is done now and nearly "untested": https://github.com/kfricke/micropython-tsl2561

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: TSL2561 Digital Light Sensor

Post by marfis » Fri Feb 12, 2016 8:17 am

Regarding your question about pow() implementation in fixed points arithmetics:

My preferred way is to program a generic lookup table function that takes x,y fitting point pairs in a list. Plot your desired formula, choose your fitting points and transfer these to your code. You end up having a simple table with x,y value in code which is easy to understand and adapt. This has also the advantage that you can define more fitting points in "critical" areas and less points where it is not so important.

To retain precision you can shift the values to the next data width before entering the lookup function. E.g. if you have a 16bit input, shift it left by 16. After exiting, simply right-shift again.

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: TSL2561 Digital Light Sensor

Post by kfricke » Mon Feb 15, 2016 4:06 pm

pythoncoder wrote:@kfricke The datasheet for the TLS2561 tells you how to perform the Lux calculation using integer arithmetic https://www.adafruit.com/datasheets/TSL2561.pdf - see the final section "Simplified Lux Calculation". It uses a piecewise linear approximation for the pow() function. Translating the C to Python should be straightforward.
Of course i have seen that. But i did hope to get around the wall of define statements that do build the lookup table marfis did suggest.

And tbh i did hope that a math guru like yours jumps in and does implement a software floating point "softmath" module ;)

Post Reply