A Vishay library for devices VEML6040 R+G+B+W and VEML6075 UVA+UVB optical sensors. Data is stored in a dedicated data structure.

Dependents:   vmel60xx_hello_world

This device library is for use with the Vishay VEML6040 and VEML6075 optical sensors. Ambient light conditions are gathered and stored in a user accessible data structure veml60xx_struct. The library has enough intelligence to determine which device is connected and performs the appropriate functions.

The VEML6040 detects Red, Green, Blue and White light data, which is easily converted to relative Lux intensities.

The VEML6075 detects UVA and UVB light which is converted to a UV Index value.

Since both devices use the same I2C address, they cannot be on the same I2C bus at the same time.

Tested on a K64F

Files at this revision

API Documentation at this revision

Comitter:
loopsva
Date:
Fri Apr 29 16:40:06 2016 +0000
Parent:
3:dda770fa7228
Commit message:
Added a delay variable in veml60xx_struct that is dependent on the IT bits and 6040 vs 6075
; Note: There is something screwy with the VEML6075 and FORCE mode, specially when dynamically changing the IT bits. It required much longer delays than...

Changed in this revision

veml60xx.cpp Show annotated file Show diff for this revision Revisions of this file
veml60xx.h Show annotated file Show diff for this revision Revisions of this file
diff -r dda770fa7228 -r 0ce65ee5697f veml60xx.cpp
--- a/veml60xx.cpp	Wed Apr 27 22:24:37 2016 +0000
+++ b/veml60xx.cpp	Fri Apr 29 16:40:06 2016 +0000
@@ -37,11 +37,11 @@
     _i2c_->read(VEML60_RADDR, vemlBuffer, 2, false);
     Pntr.id = (vemlBuffer[1] << 8)  | vemlBuffer[0];
 
-    if((Pntr.id & VEML6075_DEVICE_ID) == VEML6075_DEVICE_ID) {
+    if(((Pntr.id & 0xff) & VEML6075_DEVICE_ID) == VEML6075_DEVICE_ID) {
         Pntr.is6075 = true;
         Pntr.is6040 = false;
     } else
-    if((Pntr.id & VEML6040_DEVICE_ID) == VEML6040_DEVICE_ID) {
+    if(((Pntr.id & 0xff) & VEML6040_DEVICE_ID) == VEML6040_DEVICE_ID) {
         Pntr.is6075 = false;
         Pntr.is6040 = true;
     } else {
@@ -65,24 +65,31 @@
         switch (c) {
             case VEML60xx_CONF_BITS_IT_50m40m: 
                 Pntr.lux_step = VEML6040_LUX_STEP * 32.0;
+                Pntr.trig_dly = 54;
                 break;
             case VEML60xx_CONF_BITS_IT_100m80m:
                 Pntr.lux_step = VEML6040_LUX_STEP * 16.0;
+                Pntr.trig_dly = 102;
                 break;
             case VEML60xx_CONF_BITS_IT_200m160m:
                 Pntr.lux_step = VEML6040_LUX_STEP * 8.0;
+                Pntr.trig_dly = 204;
                 break;
             case VEML60xx_CONF_BITS_IT_400m320m:
                 Pntr.lux_step = VEML6040_LUX_STEP * 4.0;
+                Pntr.trig_dly = 408;
                 break;
             case VEML60xx_CONF_BITS_IT_800m640m:
                 Pntr.lux_step = VEML6040_LUX_STEP * 2.0;
+                Pntr.trig_dly = 816;
                 break;
             case VEML6040_CONF_BITS_IT_1280m:
                 Pntr.lux_step = VEML6040_LUX_STEP * 1.0;
+                Pntr.trig_dly = 1400;
                 break;
             default:
                 Pntr.lux_step = 0.0;
+                Pntr.trig_dly = 1400;
                 break;
         }
     }
@@ -91,26 +98,32 @@
             case VEML60xx_CONF_BITS_IT_50m40m: 
                 Pntr.uva_step = VEML6075_UVA_RESP * 2.0;
                 Pntr.uvb_step = VEML6075_UVB_RESP * 2.0;
+                Pntr.trig_dly = 80;
                 break;
             case VEML60xx_CONF_BITS_IT_100m80m:
-                Pntr.uva_step = VEML6075_UVA_RESP * 1.0;    //reference dwell time (100mS) from app note
+                Pntr.uva_step = VEML6075_UVA_RESP * 1.0;    //reference integration/dwell time (100mS) from app note
                 Pntr.uvb_step = VEML6075_UVB_RESP * 1.0;
+                Pntr.trig_dly = 320;
                 break;
             case VEML60xx_CONF_BITS_IT_200m160m:
                 Pntr.uva_step = VEML6075_UVA_RESP * 0.5;
                 Pntr.uvb_step = VEML6075_UVB_RESP * 0.5;
+                Pntr.trig_dly = 640;
                 break;
             case VEML60xx_CONF_BITS_IT_400m320m:
                 Pntr.uva_step = VEML6075_UVA_RESP * 0.25;
                 Pntr.uvb_step = VEML6075_UVB_RESP * 0.25;
+                Pntr.trig_dly = 1280;
                 break;
             case VEML60xx_CONF_BITS_IT_800m640m:
                 Pntr.uva_step = VEML6075_UVA_RESP * 0.125;
                 Pntr.uvb_step = VEML6075_UVB_RESP * 0.125;
+                Pntr.trig_dly = 2000;
                 break;
             default:
                 Pntr.uva_step = 0.0;
                 Pntr.uvb_step = 0.0;
+                Pntr.trig_dly = 2000;
                 break;
         }
     }
@@ -223,7 +236,7 @@
 
 //--------------------------------------------------------------------------------------------------------------------------------------//
 // If there is a lux over/underflow, automatically adjust the CONF_BITS_IT by +-1 to compensate accordingly
-// if returns true, the Lux dwell time (IT bits in CONF reg) was changed.
+// if returns true, the Lux integration/dwell time (IT bits in CONF reg) was changed.
 
 bool veml60xx::autoAdjustLux(veml60xx_struct& Pntr) {
     getRawData(Pntr);
@@ -265,3 +278,4 @@
 }
             
     
+
diff -r dda770fa7228 -r 0ce65ee5697f veml60xx.h
--- a/veml60xx.h	Wed Apr 27 22:24:37 2016 +0000
+++ b/veml60xx.h	Fri Apr 29 16:40:06 2016 +0000
@@ -8,10 +8,10 @@
 *
 * The code has all of the hooks for gathering raw data from the VEML60xx chip and performs the necessary compensation 
 * in order to get the corrected output readings.  There is also an optional automatic scaling routine that 
-* modifies the dwell time (IT bits in the CONF register), should the raw register reading saturate (65535) or
+* modifies the integration time (IT bits in the CONF register), should the raw register reading saturate (65535) or
 * are too small (< 255).  Adjustments are made + or - one IT count, each time the routine is called.  If the light
 * striking the sensor changes dramatically, you may have to run the automatic scaling routine a few times.  After 
-* each change in dwell time (changing of IT bits), you must wait a maximum of 2 * 1280mSec before taking a new 
+* each change in integration time (changing of IT bits), you must wait a maximum of 2 * 1280mSec before taking a new 
 * reading in order to get accurate results.
 *
 * NOTE: Both the VEML6040 and the VEML6075 have the same I2C address.  You cannot have both devices on the same I2C 
@@ -23,7 +23,7 @@
 *       the "is6040" flag in the "veml60xx_struct" data structure.
 *
 * NOTE: It is not yet known when using startAccess(), whether or not that TRIG bit clear immediately or after the
-*       dwell time has finished.  As a result, you should not depend on TRIG bit for polling.
+*       integration time has finished.  As a result, you should not depend on TRIG bit for polling.
 *
 **/
 
@@ -74,7 +74,7 @@
 #define VEML6075_DEVICE_ID                  0x0026  //expected device ID
 
 // VEML6040-only ID contents
-#define VEML6040_DEVICE_ID                  0x0123  //expected device ID
+#define VEML6040_DEVICE_ID                  0x0023  //expected device ID
 
 // VEML6075-only conversion coefficients
 #define VEML6075_UVA_RESP                   0.0011
@@ -105,6 +105,7 @@
     typedef struct {
         uint16_t id;        /*!< VEML60xx Device ID*/
         uint16_t conf_reg;  /*!< VEML60xx config register mirror */ 
+        int      trig_dly;  /*!< VEML60xx FORCE mode min trigger delay (mS) before resding data registers */ 
               
         bool     is6075;    /*!< connected device is a VEML6075 */ 
         bool     is6040;    /*!< connected device is a VEML6040 */ 
@@ -153,7 +154,7 @@
     /** 
      * Get VEML60xx ID Register
      *
-     * Note: the VEML6040 seems to have an ID register. However, it's not published
+     * Note: the VEML6040 seems to have an ID register. However, it's not published by Vishay
      * 
      * @param pointer to struct veml60xx_struct
      *