APDS-9301 Lux Sensor with C# on IOT

Have questions about a SparkFun product or board? This is the place to be.

Moderators: phalanx, TS-Tim

Post Reply
ftosteve
Posts: 2
Joined: Fri Dec 22, 2017 4:48 am

APDS-9301 Lux Sensor with C# on IOT

Post by ftosteve » Fri Dec 22, 2017 5:07 am

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.

ftosteve
Posts: 2
Joined: Fri Dec 22, 2017 4:48 am

Re: APDS-9301 Lux Sensor with C# on IOT

Post by ftosteve » Wed Jan 03, 2018 9:18 am

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)

paulvha
Posts: 240
Joined: Sat Nov 11, 2017 2:39 am

Re: APDS-9301 Lux Sensor with C# on IOT

Post by paulvha » Wed Jan 03, 2018 12:47 pm

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.

savage
Posts: 1
Joined: Thu Feb 01, 2018 6:07 pm

Re: APDS-9301 Lux Sensor with C# on IOT

Post by savage » Thu Feb 01, 2018 6:22 pm

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.

Post Reply