Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: implementation of the veml7700 driver #492

Merged
merged 3 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -664,3 +664,11 @@ labels:
- "components/ads130e08/**"
- "components/ads130e08/.eil.yml"
- "examples/ads130e08/**"
- label: "area:components:veml7700"
sync: true
matcher:
files:
any:
- "components/veml7700/**"
- "components/veml7700/.eil.yml"
- "examples/veml7700/**"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ or [GitLab examples](https://gitlab.com/UncleRus/esp-idf-lib/tree/master/example
| **tsl2561** | Driver for light-to-digital converter TSL2561 | BSD-3 | `esp32`, `esp8266`, `esp32s2`, `esp32c3` | Yes
| **tsl2591** | Driver for light-to-digital converter TSL2591 | MIT | `esp32`, `esp8266`, `esp32s2`, `esp32c3` | Yes
| **tsl4531** | Driver for digital ambient light sensor TSL4531 | BSD-3 | `esp32`, `esp8266`, `esp32s2`, `esp32c3` | Yes
| **veml7700** | Driver for VEML7700 ambient light sensor | ISC | `esp32`, `esp8266`, `esp32s2`, `esp32c3` | Yes

### Magnetic sensors

Expand Down Expand Up @@ -308,3 +309,4 @@ or [GitLab examples](https://gitlab.com/UncleRus/esp-idf-lib/tree/master/example
- [Jose Manuel Perez](https://github.com/jmpmscorp), developer of LC709203F driver
- [Weslley Duarte](https://github.com/weslleymfd), developer of ADS130E08 driver
- [Jan Veeh](https://github.com/janveeh), developer of ICM42670 driver
- [Marc Luehr](https://github.com/Th3Link), developer of VEML7700 driver
23 changes: 23 additions & 0 deletions components/veml7700/.eil.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
components:
- name: veml7700
description: Driver for VEML7700 ambient light sensor
group: light
groups: []
code_owners: Th3Link
depends:
- i2cdev
- log
- esp_idf_lib_helpers
thread_safe: yes
targets:
- name: esp32
- name: esp8266
- name: esp32s2
- name: esp32c3
licenses:
- name: ISC
copyrights:
- author:
name: Th3Link
year: 2019
5 changes: 5 additions & 0 deletions components/veml7700/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
idf_component_register(
SRCS veml7700.c
INCLUDE_DIRS .
REQUIRES i2cdev log esp_idf_lib_helpers
)
17 changes: 17 additions & 0 deletions components/veml7700/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ISC License

SPDX-License-Identifier: ISC

Copyright (c) 2022 Marc Luehr <marcluehr@gmail.com>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
104 changes: 104 additions & 0 deletions components/veml7700/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Driver for the VEML7700 ambient light sensor

This is the driver for the VEML7700 ambiernt light sensor from Vishay. It is not the
cheapest solution but very easy to integrate, with a minimum of further components.
The sensor can be SMD soldered by hand on a custom PCB, but also several breakout boards
are available.

## About the sensor

The VEML7700 is a high-accuracy ambient light sensor. All measurements and filtering
is done on the chip which makes it easy to integrate. The sensitivity can be adjusted
by a gain setting and by changing the integration time. The output of the sensor is a
count value which must be converted using the resolution value in the driver.

The sensor has power saving features which reduces the repetition of measurements.
It has also a power off feature to save even more power.

The ambient light sensor value is filterd very clone to the caracteristic of the
human eye. Besides, als the white channel with a wider wavelength spectrum. In most
applications, the ambient light value will do just fine.

## Power consumption

- 0.5 μA in shut-down mode (@3.3V)
- down to 2 μA in power save mode 4 (@3.3V)
- 45 μA on 100ms integration time (@3.3V)

## Communication interface

I2C is used as communication interface without any further interrupt pins. It has six
command codes for the settings and the output values. Read the datasheet or application
note for further information.

To reduce interactions with the integrated microcontroller, the interrupt feature can
be used. Therefore, one must configure the low and high threshold and enable the interrupt.

## Interrupt application examples

If values below a certain threshold is of interest, i.e. to activate lights when its
getting dark outside, the low threshold should be adjusted and setting the high threshold
to maximum (65535).

Another application could be an automated rollershutter, then both thresholds sould be
set to trigger the up and down movement of rollershutters.

## Measurement process

The measurement takes time and the sensor should not be read out faster than the
measurement time. Therefore the application should be adjusted to the sensor configuration
regarting integration time and power save modes. Alternatively, the interrupt feature
can be used by repeatetive reading of the interrupt status.

## Usage

This driver uses i2cdev which must be initialized first. Then initialize the device
decriptor, one discriptor per device. The sensor can be used without configuration,
but has a high chance of over-saturation on sunlight. Therefore, change gain and
integration time to your needs and configure the device.

Then, the veml7700_ambient_light and veml7700_white_channel functions can be used
to read out the brightness. The driver converts the counts from the device to lx using
the configuration.

### Hardware configurations

The driver supports multiple VEML7700 sensors at the same time that are
connected to I2C. Following figure show some possible hardware
configurations.

First figure shows the configuration with one sensor at I2C bus 0.

```text
+------------------+ +----------+
| ESP8266 / ESP32 | | VEML7700 |
| | | |
| GPIO 14 (SCL) ----> SCL |
| GPIO 13 (SDA) <---> SDA |
+------------------+ +----------+
```

Next figure shows a possible configuration with two I2C buses.

```text
+------------------+ +----------+
| ESP8266 / ESP32 | | VEML7700 |
| | | |
| GPIO 14 (SCL) ----> SCL |
| GPIO 13 (SDA) <---> SDA |
| | +----------+
| | | VEML7700 |
| | | |
| GPIO 5 (SCL) ----> SCL |
| GPIO 4 (SDA) <---> SDA |
+------------------+ +----------+
```

Only one sensor per I2C bus is possible, since it uses a unconfigurable I2C slave address.
However, one could also use GPIO controller bus buffer to connect the bus to different
devices.

## References
[Datasheet](https://www.vishay.com/docs/84286/veml7700.pdf)

[Application Note](https://www.vishay.com/docs/84323/designingveml7700.pdf)
2 changes: 2 additions & 0 deletions components/veml7700/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COMPONENT_ADD_INCLUDEDIRS = .
COMPONENT_DEPENDS = i2cdev log esp_idf_lib_helpers
Loading