SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By ftosteve
#197293
Has anyone managed to get the Lux sensor outputting 'real' values using C# on a Pi3?

I have converted the following:
https://github.com/sparkfun/APDS-9301_B ... rduino/src
CPP code to C# and although it compiles and 'works' the value returned is much less than I am expecting.

In an office environment the code is returning ~8.9lx.
But a colleages hand held Lux meter reports ~120lx.

I can provide my code upon request.
Any help is much appreciated.
By ftosteve
#197773
Well, I am both happy and annoyed.
The issue has been resolved thanks to some smart peeps @ iotify. On thier site I found they use the APDS-9301 but used Python.
https://iotify.help/virtual-lab/custom- ... #APDS-9301
Thier code is here
https://github.com/iotify/custom-lab/bl ... pds9301.py
I shiftly converted that to C# and all worked as expected.

Upoin closer inspection I have noticed that there are some very obvious differences in the code...
For instance, all thier register bytes start at 0x0# as per the datasheet for the chip.
Going back to the SparkFun .H file, all thier register bytes start at 0.8#!

Not sure why the CPP code is so different, but clearly it doesn't work.

Anyways, I am happy now :o)
By paulvha
#197777
Thanks for sharing the feedback and great it works. However I checked the .h file in the earlier provided link, in my browser I see all the register bytes starting with 0x0 (copy/paste example: #define CONTROL_REG 0x80). I can not find the 0.8# you mention. Maybe I am looking on the wrong place, but maybe this is an issue/setting that you might get again in a future project. Hence I am sharing this observation to save potential time in the future.
By savage
#198130
ftosteve wrote: Fri Dec 22, 2017 5:07 am In an office environment the code is returning ~8.9lx.
But a colleages hand held Lux meter reports ~120lx.
Take a look at that library now: there was an ambiguity in the technical documents as to how to convert the readings to lux (see here). In short, the lux was being returned a factor of 16 too low. The library is fixed now and that link should show you where to update your own code.