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

Revision:
4:0ce65ee5697f
Parent:
3:dda770fa7228
--- 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 @@
 }
             
     
+