Grove - Sunlight Sensor V2 correct usage

I’m having some problems using the second version of the Grove - Sunlight Sensor
correctly. The values it’s giving using the official library do not match a calibrated lux sensor at all. I am using this version of the official library, which supports the newer (Si1151?) sensor.

Looking at the datasheet for the sensor itself and the code used in the updated GitHub library, I’m not sure if the code is even using the sensor correctly. Like why is the infrared and visible light values taken from the same registers, but the visible light value is just divided by 3?
IR:

uint16_t Si115X::ReadHalfWord(void) {
    Si115X::send_command(Si115X::FORCE);
    uint8_t data[3];
    data[0] = Si115X::read_register(Si115X::DEVICE_ADDRESS, Si115X::HOSTOUT_0, 1);
    data[1] = Si115X::read_register(Si115X::DEVICE_ADDRESS, Si115X::HOSTOUT_1, 1);
    // Si115X::send_command(Si115X::PAUSE);
    // data[3] = data[0] * 256 + data[1];
    return data[0] * 256 + data[1]; //* 256 + data[1];
}

Visible:

uint16_t Si115X::ReadHalfWord_VISIBLE(void) {
    Si115X::send_command(Si115X::FORCE);
    uint8_t data[3];
    data[0] = Si115X::read_register(Si115X::DEVICE_ADDRESS, Si115X::HOSTOUT_0, 1);
    data[1] = Si115X::read_register(Si115X::DEVICE_ADDRESS, Si115X::HOSTOUT_1, 1);
    return (data[0] * 256 + data[1])/3; 
}

Maybe I’m just not understanding it good enough.

So how do I get the sensor to output correct values? Or do I just need to calibrate it? I’m also wondering if the output value is in lux or lumens? The wiki says they are in lumens, but the Si1151 itself gives lux. Unless the code does some lux to lumen conversion using the photodiode area, which I don’t see in the code, I don’t really how it would be able to output lumens.

Hi, I am working with the same sensor as well, I and I am just as confused as you are. Did you get any updates regarding this. As well as this, the UV cannot be read at least I cannot see how to read the UV values

Hi! I did get some sense out of it, but I had to do it myself. I went over the datasheet for a while and modified the library code to get it to work. The sensor does NOT have a UV sensor unlike advertised, which was a disappointment. The code for it in the library is garbage.

It does however have a visible light and IR sensing capabilities, which it outputs in lux. I couldn’t modify the code in a way that it would produce the correct lux values, perhaps it can be done by messing with the registers in the datasheet, but at least I did not succeed in that. I’m not even really sure if my modified library code is giving me data from the visible light or IR sensor, but it is giving something. Working with the registers has been quite the challenge.

For me to get accurate lux readings I had to calibrate the sensors values against a calibrated lux sensor. I can link the code for the modified library and calibration I used if you want.

Hi, That would be great if you can link that. I have been struggling to quantify any of the values that the sensor gives me. It was something as when I increased the light around the sensor the value went up. But what that value is I was unsure about.

Thanks for the help

Hi! I just checked the sensor’s GitHub page and it seems that they have updated the code available after I had contacted them about it. They have removed the UV measuring, since it doesn’t exist and have also changed the code overall and made it a bit more easier to understand. I tried it and got some different values than my old code, but my calibration may be off.

I’ll try to test the new library to see if I can figure it out, since I also would need light measurements in both IR and visible so that might be easier now. I’ll do the testing perhaps tomorrow or so with a calibrated lux meter to see if the new values are accurate, but I’ll link my old code here if it is of any use. Of course the calibration data could be different for your sensor, but we’ll see. My code should give visible light data in lux.

GitHub of modified library code

Arduino code:

#include "Si115X.h"

Si115X si1151;

void setup()
{
    Wire.begin();
    Serial.begin(115200);
    if (!si1151.Begin())
        Serial.println("Si1151 is not ready!");
    else
        Serial.println("Si1151 is ready!");

}

void loop() {

  float val = 0.0;
  int n = 10;
  for (int i = 0; i < n; i++) {

    // Default
    val += si1151.ReadHalfWord_VISIBLE();

    delay(5);
  }
  val = val/n;

  Serial.print(millis());
  Serial.print(",");

  // Default
  //Serial.println(val);

  // Calibrated against reference light sensor
  Serial.println((val*11.7323)-9.10002);
}
1 Like

Ah great I will try that. This is the code I was using with the updated libraries and it seemed to give me values just unsure what of

#include "Si115X.h"

Si115X si1151;

/**
 * Setup for configuration
 */
void setup()
{
    Wire.begin();
    Serial.begin(115200);
    if (!si1151.Begin()) {
        Serial.println("Si1151 is not ready!");
        while (1) {
            delay(1000);
            Serial.print(".");
        };
    }
    else {
        Serial.println("Si1151 is ready!");
    }
}

/**
 * Loops and reads data from registers
 */
void loop()
{
    Serial.print("IR: ");
    Serial.println(si1151.ReadIR());
    Serial.print("Visible: ");
    Serial.println(si1151.ReadVisible());

    delay(500);
}

I also found for some odd reason, maybe since I am using the XIAO ESP32S3 with the XIAO Expansion board I needed to initalise the OLED display for it to work so I have also attached that code:

#include "Si115X.h"
#include <U8x8lib.h>            // Include U8x8 library for OLED display

Si115X si1151;

U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/*reset=*/U8X8_PIN_NONE); // Create an instance of OLED display

void setup()
{
    u8x8.begin(); 
    Wire.begin();
    Serial.begin(115200);
    if (!si1151.Begin()) {
        Serial.println("Si1151 is not ready!");
        while (1) {
            delay(1000);
            Serial.print(".");
        };
    }
    else {
        Serial.println("Si1151 is ready!");
    }
}

/**
 * Loops and reads data from registers
 */
void loop()
{
    Serial.print("IR: ");
    Serial.println(si1151.ReadIR());
    Serial.print("Visible: ");
    Serial.println(si1151.ReadVisible());

    delay(500);
}

Hi there,
Not sure if this applies , but adding some delay between the init and reads seemed to work for others;
Grove Sunlight Sensor Library doesn't Work - #24 by PJ_Glasso
HTH
GL :slight_smile: PJ

I do get readings without the delays, I am just confused on what the values are quantified at. I do get a trend that makes sense when i increase the light intensity around the sensor, the values increase so I know the sensor theoretically works fine.