VEML6030 - Lux readout depends on the gain level?

Hi,

I recently bought the VEML6030 sensor.

I am operating the sensor using a particle photon and the SparkFun library.

I observed a behavior that seems strange to me and which I cannot fully understand.

The sensor output in lux depends on the GAIN level.

In more detail, with GAIN of 0.125 and 1, I got a values of circa 155 lx.

With GAIN of 0.25 the value is circa 4x higher, that is, 610 lx.

This behavior is independent from the integration time.

I would expect the sensor output to be independent from the GAIN.

Am I missing something or there is a bug in the code?

Bests,

Matteo

Hi Matteo,

The output of the sensor will absolutely depend on what you set the GAIN to along with the Integration Time. The GAIN acts as a multiplier to the signal from the VEML6030. We have a handy table at the end of the [Hardware Overview Section of our Hookup Guide that will go into that in more detail.

I hope this helps clear up any confusion here.](https://learn.sparkfun.com/tutorials/qwiic-ambient-light-sensor-veml6030-hookup-guide#hardware-overview)

Hi Mark,

Thanks for the answer but I still do not fully understand.

From my understanding, the raw signal (counts) is dependent from the sensor setting that are the GAIN and integration time, as you said.

Changing these parameters changes the resolution and the detection range, as indicated in the tables.

On the other hand, the lux output should be independent from the parameters, if within the detection range.

I would expect just small variations depending on the different resolution not a 4x variation!

This is what the function _calculateLux and the conversion table are for. Correct?

I had a closer look at the library and I think the index in the _calculateLux function points to the wrong column of the conversion table.

If you look at the following index selection in the _calculateLux function, for GAIN=0.125 (1/8) it points to _convPos = 2 (3rd column of the conversion table, see below) while on the website (https://learn.sparkfun.com/tutorials/qw … e-overview) it is the the 4th column that holds the values for GAIN=1/8. The same is valid for GAIN = 1 and GAIN = 2.

 if (_gain == 1.00) 
    _convPos = 0;
  else if (_gain == 2.00)
    _convPos = 1; 
  else if (_gain == .125)
    _convPos = 2; 
  else if (_gain == .25)
    _convPos = 3; 
  else
    return UNKNOWN_ERROR;
const float eightHIt[]     = {.0036, .0072, .0288, .0576};
const float fourHIt[]      = {.0072, .0144, .0576, .1152};
const float twoHIt[]       = {.0144, .0288, .1152, .2304};
const float oneHIt[]       = {.0288, .0576, .2304, .4608};
const float fiftyIt[]      = {.0576, .1152, .4608, .9216};
const float twentyFiveIt[] = {.1152, .2304, .9216, 1.8432};

Please let me know what is your opinion.

I am not an Arduino expert.

Bests,

Matteo

Hi Mark,

I changed the _calculateLux function (see below) and now the output behaves as expected, that is, the Lux level is independent from the GAIN.

Also the _calculateBits function must be modified accordingly.

Bests,

Matteo

uint32_t SparkFun_Ambient_Light::_calculateLux(uint16_t _lightBits){

  float _luxConv; 
  uint8_t _convPos;  

  float _gain = readGain(); 
  uint16_t _integTime = readIntegTime();

  // Here the gain is checked to get the position of the conversion value
  // within the integration time arrays. These values also represent the bit
  // values for setting the gain. 
  //if (_gain == 1.00) 
    //_convPos = 0;
  //else if (_gain == 2.00)
    //_convPos = 1; 
  //else if (_gain == .125)
    //_convPos = 2; 
  //else if (_gain == .25)
    //_convPos = 3; 
  //else
    //return UNKNOWN_ERROR;
  
  // Corrected index selection
  if (_gain == 2.00) 
    _convPos = 0;
  else if (_gain == 1.00)
    _convPos = 1; 
  else if (_gain == .25)
    _convPos = 2; 
  else if (_gain == .125)
    _convPos = 3; 
  else
    return UNKNOWN_ERROR;

Hi again Matteo,

Ah, that makes sense. Sorry for the confusion here. I have forwarded this on to the engineer who wrote the library and we will review it and, if necessary, will update the library to fix that issue.

Hello @GWMatteo! Thanks for digging through the library. As Mark mentioned the LUX levels are definitely dependent on the GAIN selection. This allows for the same light sensor to sense such a wide spectrum of light levels while only needing to adjust the strength of that signal. With that being said, you’ve found an error in my library and so thank you for pointing that out! I had a derpy moment and assigned the wrong index to the wrong gain, woops! Thanks again, library has been fixed!

Library Fix: https://github.com/sparkfun/SparkFun_Am … f71979bd0c

Release Live: https://github.com/sparkfun/SparkFun_Am … tag/v1.0.2

In case you wanted to see where that table came from:

Hi wonder_boom,

Thanks!

I am happy that I could help improve the library

I still have some feedback that I think can help you to improve the library and the understanding of the hookup guide:

  1. Also the index for GAIN 0.25 and 0.125 are swapped and the same typos are observed in the _calculateBits function.

  2. In the hookup guide I found confusing the definition of resolution as lux/bit. It took me a while to understand the physical meaning of it. I had to carefully read the Application Note of the sensor to fully understand. I think it would be more appropriate and easy to grasp for the user to define the resolution as lux/counts, where counts is the raw signal from the sensor, as defined in the Application Note.

  3. I am trying to setup the automatic procedure for setting up GAIN and IntTime, as described in the Application Note at page 9 and 21. The procedure relies on the raw counts and not on the Lux level. The library has a function for calculation of the raw counts, that is, _calculateBits . However this function is private. Perhaps, you may consider to make it public or even to write a function that performs the automatic setting procedure, as described in the flow chart at page 21.

  4. In the description of _calculateLux it is stated that: The lux value of the Ambient Light sensor depends on both the gain and the integration time settings. .

This is incorrect. Only the raw signal from the sensor (what you call bits) depends on GAIN and IntTime, not the lux value. The GAIN and IntTime change only the detection range (max and min detectable values) for the light intensity or lux value. If you think about the physical meaning of the two quantities, the light intensity in the room (number of photons hitting the sensor) cannot depend on the sensor setting :smiley: .

As a test, try to measure both Lux and counts at different GAIN. You will see that the Lux (light intensity) is almost constant while the counts are variable.

I hope the comments are useful.

Bests,

Matteo