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!
TSL2561 Digital Light Sensor
Re: TSL2561 Digital Light Sensor
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.
Re: TSL2561 Digital Light Sensor
Most basic stuff is done now and nearly "untested": https://github.com/kfricke/micropython-tsl2561
Re: TSL2561 Digital Light Sensor
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.
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.
Re: TSL2561 Digital Light Sensor
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.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.
And tbh i did hope that a math guru like yours jumps in and does implement a software floating point "softmath" module