Back to Smartcitizen.me

The light sensor is fixed!

Hey everyone!

This post is dedicated to talk about the issues and fixes of the light sensor readings on the SCK2.1 that were found by many of you. There are only good news in this post, so don’t worry, it’s all under control! :ok_hand:

TL;DR
Below we will talk about the sensor working principle and the current readings implementation. If you want to skip the post, the good news are that it only takes a little firmware update in 3 steps:

  1. Download the release from here
  2. Follow the update instructions from here
  3. Tell us how it goes in the comments!

Now, some interesting stuff about the light readings! The sensor in question is the ROHM Semiconductor BH1730FVC. It’s an I2C sensor with many applications, such as mobile phones, and LCD backlight adjustment in screens in general. It has quite a wide detection range, going up to 100klx (kilolux), and is able to distinguish between visible and infrared (IR from now on), and with some help from the datasheet linked above we are able to combine them both into a single reading. Very briefly, to understand these two readings: the visible component goes from red to purple and is what we see (duh) and the IR component has a lower frequency than red (and hence not visible to the human eye), and is able to heat things up by what we know thermal radiation. Most of the thermal radiation emitted by objects near room temperature is infrared.

So, let’s stop praising the sensor and understand what was happening to make some you see this?

One single letter.

Long story short: the variable that was storing the visible component of the light reading was declared as int16_t, whereas it should have been uint16_t. For those who know about this, it means that the first variable was only able to store numbers from -32.768 to 32.768, while the second one ranges from 0 to 65.536. That’s why when the light was going above one certain threshold, it went down to zero. Also known as overflow.

But hey! That typo is gone. However, while trying to find this problem, we found out that sometimes, when the light sources are constant, the output of the sensor was going down :exploding_head:. By much. For instance, if we left the sensor under the sun, we could see an instant rise of the light reading, quite comparable to that of a luxometer. However, after 5-10s, the sensor reading decreased, with no aparent reason. This brings us to the next point. How the sensor was implemented and how we improved it’s reading.

As said above, the sensor reads both, the IR and visible components. In terms of implementation, and so that we can have a wider range, it has what is called integration time. This integration time is similar to the exposure of a camera. The longer the time, the more light the sensor will see and the best the accuracy we will have in low regions. On the contrary, for high light situations, as in the camera example, we want to have low integration times, so that the sensor doesn’t saturate (or make the picture look burnt).

The sensor response to the IR and visible component is shown below:

On the z-axis of the graph you can see that, when we increase the visible component, the sensor reading in lx grows, but it’s not the case in the IR. In general, an increase of IR component will provoke a reduction in the light values, and this looks worse when the sensor is saturated in the visible range (right side of the graph). This graph was calculated with a normal integration time.

The maximum value from the sensor is 100klx, which is rightly matching the top right corner of the graph. However, with this graph, we might not be able to differentiate when we have a lot of light, or when we have a lot, a lot of light. For this, we thought that would be a good practice to reduce that integration time from before, when one of the components (normally the visible one) is saturated. In this case, our graph, limited to the 100klx from the datasheet, looks like:

Which helps us understand that, when we have a saturated value, we don’t want to mess around with lower values due to the infrared component. We just have a lot of light, and that’s it. And also, that we want to adapt our integration time, because in case of it being too short, a minimal amount of light will saturate our sensor and we won’t have nice smooth curves during the day.

So, to conclude, after a typo, a lot of boring stuff and some worries about the sanity of the kits, the light sensor issues can be fixed quickly and with little hassle. The fix is simple to apply (see above) and there is no problem with the light sensors hardware. We really hope this has been somehow explanatory and that you are able to upgrade your kits firmware and read the light sensors properly now! Apologies for the inconvenience!

Let us know in the comments below :slight_smile:

Happy sensing!

Thank you very much for your enlightening explanation about the light sensor. I really enjoyed reading.

Also, the update procedure went without a hitch and light data are steadily coming trough now. Great!

Great to hear the update process went smooth!

Please, keep reporting any issues, comments or questions!

We’re all Smart Citizens!

All working here, it even fixed my temperature figures.:heart_eyes:

Thank you very much for the hard work that went in to this.

Andy

1 Like

We just performed this update. Not really getting any data after the update, but I think it might be a website issue?
https://api.smartcitizen.me/v0/devices/9875

We’ve gone through the onboarding with a new token to see if that helped, but no luck.
New kit URL:
https://smartcitizen.me/kits/10113
Any ideas?

Hi!

It seems your hardware version is not matching. In the hardware_info property of your device.

hw_ver	"2.0"

However, the frontend is expecting a 2.1 kit. Which board do you have, and which firmware did you upgrade it into?

Regards,

Óscar

OK. I followed the instructions linked to above:
https://docs.smartcitizen.me/Components/Firmware/guides/Update%20the%20firmware/
I did download the firmware from here as instructed above


but at no point did the instructions ask me to use that, and in any case I can’t see any .uf2 file in there?

Hi!

If you have an SCK 2.1 you’ll find the latest .uf2 firmware at the bottom of the page here:

Do you mean the file called SAM_firmware_096.uf2 under the ‘Assets’ dropdown menu?

Seems odd that the index.htm file on the SCK 2.1 takes you to a page meant for v2.0 kits. Can i suggest that be amended in the future?

Hi!

Blockquote
Do you mean the file called SAM_firmware_096.uf2 under the ‘Assets’ dropdown menu?

Yes, that’s the one.

Blockquote
Seems odd that the index.htm file on the SCK 2.1 takes you to a page meant for v2.0 kits. Can i suggest that be amended in the future?

If that’s the case, it’s a bug! We’ll fix it for sure.

Is the kit working now?

Yes it was a bug,@fy81le thanks for reporting it!
Fixed here this will be included in the next firmware release.

Ah great. Yes we are back up and running now, thanks for the insights!

1 Like