VEML7700 - Ambient light

Description

Library for interfacing Vishay VEML7700 Ambient Light Sensor with I2C Interface

The VEML7700 is a high accuracy ambient light digital 16-bit resolution sensor -) I2C interface with communication speed up to 400 kHz -) Includes a high sensitive photo diode -) Includes a low noise amplifier -) Includes an 16-bit A/D converter

OVERVIEW

VEML7700_Abstract:
This library can be used to handle Vishay Semiconductors VEML7700 type high accuracy ambient light sensors.
Interfaces: 1x I2C

The VEML7700 is a high accuracy ambient light digital 16-bit resolution sensor
  • I2C interface with communication speed up to 400 kHz
  • Includes a high sensitive photo diode
  • Includes a low noise amplifier
  • Includes an 16-bit A/D converter
  • VEML7700_How_to_use:
    /* Hardware setup */ const { PORT_I2C = 0, // The first I2C interface should be used. } /* Handles for available sensors */ new hALS[TVEML7700_Handle]; // Handle to manage the VEML7700 /* 1 sec. timer is used for the general program sequence */ #callback MainTimer() { new als; // Ambient Light Result [16-bit value] new white; // WHITE Output data, [16-bit value] catch(VEML7700_Read(hALS, als, white)); // Reads the measured values ​​from the VEML7700 #watch("ALS=%d", als); // Issues Ambient Light Result via the watch panel #watch("WHITE=%d", white); // Issues WHITE Output data via the watch panel } /* Application entry point */ main() { // Inits the I2C interface catch( rM2M_I2cInit( PORT_I2C, VEML7700_CLOCK, 0)); // Initializes i2c communication with the VEML7700 catch(VEML7700_Init(hALS, PORT_I2C)); /* Activates the VEML7700 using the following configuration: -) 100ms integration time (Power-On Default) -) gain x1 (Power-On Default) */ new config = VEML7700_CFG_IT_100MS | VEML7700_CFG_GAIN_MUL_1; catch(VEML7700_Enable(hALS, config)); // Initialisation of a cyclic sec. timer setInterval(MainTimer, 1000); }

    BASIC

    VEML7700_CLOCK -

    typical I2C clock speed to be used

    VEML7700_I2C_ADR:

    VEML7700 I2C address

    VEML7700_CFG_x:

    VEML7700 configuration (Bitmask for VEML7700_CMD_ALS_CONF_0)

  • Gain selection (Bit 11-12) see VEML7700_CFG_GAIN_x
  • ALS integration time setting (Bit 6-9) see VEML7700_CFG_IT_x
  • ALS interrupt enable setting (Bit 1) see VEML7700_CFG_INT_EN
  • ALS shut down setting (Bit 0) see VEML7700_CFG_SD
  • VEML7700_CFG_GAIN_x:

    Available ALS gain settings (VEML7700_CMD_ALS_CONF_0, Bit 11-12)

    VEML7700_CFG_GAIN_MUL_1 - (0 << 11): Gain x1 (Default)
    VEML7700_CFG_GAIN_MUL_2 - (1 << 11): Gain x2
    VEML7700_CFG_GAIN_DIV_8 - (2 << 11): Gain /8
    VEML7700_CFG_GAIN_DIV_4 - (3 << 11): Gain /4
    VEML7700_CFG_IT_x:

    Available ALS integration time settings (VEML7700_CMD_ALS_CONF_0, Bit 6-9)

    VEML7700_CFG_IT_25MS - (12 << 6): 25ms integration time
    VEML7700_CFG_IT_50MS - (8 << 6): 50ms integration time
    VEML7700_CFG_IT_100MS - (0 << 6): 100ms integration time (Default)
    VEML7700_CFG_IT_200MS - (1 << 6): 200ms integration time
    VEML7700_CFG_IT_400MS - (2 << 6): 400ms integration time
    VEML7700_CFG_IT_800MS - (3 << 6): 800ms integration time
    VEML7700_CFG_INT_EN:

    (1 << 1): ALS interrupt enable setting

    (VEML7700_CMD_ALS_CONF_0, Bit 1)
    VEML7700_CFG_SD:

    (1 << 0): ALS shut down setting (Default)

    (VEML7700_CMD_ALS_CONF_0, Bit 0)
    VEML7700_Init(handle[TVEML7700_Handle], i2c)

    Initializes i2c communication with the VEML7700

    handle : TVEML7700_Handle - Empty device handle for a VEML7700
    i2c : s32 - I2C interface where VEML7700 is connected to
    returns : s32
    OK - If successful
    ERROR - If an error occurs
  • The selected I2C interface must be enabled (rM2M_I2cInit()) before calling VEML7700_Init.
  • VEML7700 is specified for I2C Fast-Mode (400kHz, use VEML7700_CLOCK).
  • I2C Address is fixed to 0x20 (use VEML7700_I2C_ADR).
  • The power-on default for VEML7700 is shutdown mode (see VEML7700_CFG_x definitions).
  • VEML7700_Enable(handle[TVEML7700_Handle], config)

    Activates the VEML7700 by setting the "ALS_CONF_0" register

    handle : TTVEML7700_Handle - Device handle of a specific VEML7700 (Initialized by VEML7700_Init() )
    config : s32 - VEML7700 configuration (Gain / integration time / interrupt enable / shut down )
    Use VEML7700_CFG_GAIN_x | VEML7700_CFG_IT_x | VEML7700_CFG_INT_EN | VEML7700_CFG_SD
    returns : s32
    OK - If successful
    ERROR - If an error occurs
    VEML7700_Read(handle[TVEML7700_Handle], &als, &white)

    Reads Ambient Light Result and WHITE Output data form the VEML7700

    handle - VEML7700 device handle
    als : s32 - Buffer for storing Ambient Light Result, 16-bit value
    white : s32 - Buffer for storing WHITE Output data, 16-bit value
    returns : s32
    OK - If successful
    ERROR - If an error occurs
    VEML7700_Disable(handle[TVEML7700_Handle])

    Sets the VEML7700 into shut down mode and thus grants minimum power consumption

    handle : TTVEML7700_Handle - Device handle of a specific VEML7700 (Initialized by VEML7700_Init() )
    returns : s32
    OK - If successful
    ERROR - If an error occurs

    EXPERT

    VEML7700_CLOCK_MAX -

    absolute maximum I2C clock speed

    VEML7700_CMD_x:

    Available Commands for VEML7700 Access (Command | R/W | Description)

    VEML7700_CMD_ALS_CONF_0 - 0x00 | W |
    ALS gain, integration time, interrupt, and shutdown (use VEML7700_Enable())
    Default value is 01 = devices is shut down
    VEML7700_CMD_ALS_WH - 0x01 | W |
    ALS high threshold window setting
    VEML7700_CMD_ALS_WL - 0x02 | W |
    ALS low threshold window setting
    VEML7700_CMD_POWER_SAVING - 0x03 | reserved |
    Power Saving Modes
    VEML7700_CMD_ALS - 0x04 | R |
    Whole ALS bits (use VEML7700_Read())
    VEML7700_CMD_WHITE - 0x05 | R |
    Whole WHITE bits (use VEML7700_Read())
    VEML7700_CMD_ALS_INT - 0x06 | R |
    ALS INT trigger event
    VEML7700_Com(handle[TVEML7700_Handle], aData{}, writeLen, readLen)

    Perform raw VEML7700 Read/Write access. Data is first of all sent and data is then received.

    handle : TTVEML7700_Handle - Device handle of a specific VEML7700 (Initialized by VEML7700_Init() )
    aData : {} - Array in which the data to be sent must initially be saved. Once the data has been sent, the array is used as a memory for the data to be received.
    writeLen : s32 - Number of bytes to be sent
    readLen : s32 - Number of bytes to be received
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Number of bytes to be sent >255
  • Number of bytes to be received >255
  • Another error occurs
  • Access to VEML7700 is always started by sending one byte command code (see VEML7700_CMD_x definitions) followed by two bytes (16-bit value) send or receive (depending on the selected command) data. Please see datasheet for more information.

    On this page

    VEML7700 - Ambient light