Adafruit VEML6075 UV Sensor Library
Adafruit_VEML6075.h
Go to the documentation of this file.
1 
20 #include "Arduino.h"
21 #include <Adafruit_I2CDevice.h>
22 #include <Adafruit_I2CRegister.h>
23 #include <Wire.h>
24 
25 #define VEML6075_ADDR (0x10)
26 #define VEML6075_REG_CONF (0x00)
27 #define VEML6075_REG_UVA (0x07)
28 #define VEML6075_REG_DARK (0x08)
29 #define VEML6075_REG_UVB (0x09)
30 #define VEML6075_REG_UVCOMP1 (0x0A)
31 #define VEML6075_REG_UVCOMP2 (0x0B)
32 #define VEML6075_REG_ID (0x0C)
33 
34 #define VEML6075_DEFAULT_UVA_A_COEFF 2.22
35 #define VEML6075_DEFAULT_UVA_B_COEFF 1.33
36 #define VEML6075_DEFAULT_UVB_C_COEFF 2.95
37 #define VEML6075_DEFAULT_UVB_D_COEFF 1.74
38 #define VEML6075_DEFAULT_UVA_RESPONSE 0.001461
39 #define VEML6075_DEFAULT_UVB_RESPONSE 0.002591
40 
41 /**************************************************************************/
45 /**************************************************************************/
47  VEML6075_50MS,
48  VEML6075_100MS,
49  VEML6075_200MS,
50  VEML6075_400MS,
51  VEML6075_800MS,
53 
54 /**************************************************************************/
58 /**************************************************************************/
59 typedef union {
60  struct {
61  uint8_t SD : 1;
62  uint8_t UV_AF : 1;
63  uint8_t UV_TRIG : 1;
64  uint8_t UV_HD : 1;
65  uint8_t UV_IT : 3;
66  uint8_t high_byte;
67  } bit;
68  uint16_t reg;
70 
71 /**************************************************************************/
76 /**************************************************************************/
78 public:
80 
81  boolean begin(veml6075_integrationtime_t itime = VEML6075_100MS,
82  bool highDynamic = false, bool forcedReads = false,
83  TwoWire *theWire = &Wire);
84 
85  void shutdown(bool sd);
86 
89  void setHighDynamic(bool hd);
90  bool getHighDynamic(void);
91  void setForcedMode(bool flag);
92  bool getForcedMode(void);
93 
94  void setCoefficients(float UVA_A, float UVA_B, float UVA_C, float UVA_D,
95  float UVA_response, float UVB_response);
96 
97  float readUVA(void);
98  float readUVB(void);
99  float readUVI(void);
100  void readUVABI(float *a, float *b, float *i);
101 
102  Adafruit_I2CRegister *Config_Register;
103 
104 private:
105  void takeReading(void);
106 
107  uint16_t _read_delay;
108 
109  // coefficients
110  float _uva_a, _uva_b, _uvb_c, _uvb_d, _uva_resp, _uvb_resp;
111  float _uva_calc, _uvb_calc;
112 
113  veml6075_commandRegister _commandRegister;
114 
115  Adafruit_I2CDevice *i2c_dev;
116 };
uint8_t UV_AF
Auto or forced.
Definition: Adafruit_VEML6075.h:62
uint16_t reg
The raw 16 bit register data.
Definition: Adafruit_VEML6075.h:68
void setHighDynamic(bool hd)
Sets whether to take readings in &#39;high dynamic&#39; mode.
Definition: Adafruit_VEML6075.cpp:191
boolean begin(veml6075_integrationtime_t itime=VEML6075_100MS, bool highDynamic=false, bool forcedReads=false, TwoWire *theWire=&Wire)
setup and initialize communication with the hardware
Definition: Adafruit_VEML6075.cpp:65
uint8_t UV_TRIG
Trigger forced mode.
Definition: Adafruit_VEML6075.h:63
void readUVABI(float *a, float *b, float *i)
read the calibrated UVA & UVB band reading and calculate the approximate UV Index reading ...
Definition: Adafruit_VEML6075.cpp:329
bool getHighDynamic(void)
Gets whether to take readings in &#39;high dynamic&#39; mode.
Definition: Adafruit_VEML6075.cpp:203
Adafruit_VEML6075()
constructor initializes default configuration value
Definition: Adafruit_VEML6075.cpp:45
uint8_t SD
Shut Down.
Definition: Adafruit_VEML6075.h:61
CMSIS style register bitfield for commands.
Definition: Adafruit_VEML6075.h:59
veml6075_integrationtime_t getIntegrationTime(void)
Get the time over which we sample UV data per read from the sensor.
Definition: Adafruit_VEML6075.cpp:177
float readUVA(void)
read the calibrated UVA band reading
Definition: Adafruit_VEML6075.cpp:293
uint8_t UV_IT
Integration Time.
Definition: Adafruit_VEML6075.h:65
Adafruit_I2CRegister * Config_Register
Chip config register.
Definition: Adafruit_VEML6075.h:102
bool getForcedMode(void)
Gets whether to take readings on request.
Definition: Adafruit_VEML6075.cpp:229
void shutdown(bool sd)
Shut down the sensor.
Definition: Adafruit_VEML6075.cpp:135
veml6075_integrationtime
integration time definitions
Definition: Adafruit_VEML6075.h:46
float readUVI(void)
Read and calculate the approximate UV Index reading.
Definition: Adafruit_VEML6075.cpp:315
uint8_t high_byte
unused
Definition: Adafruit_VEML6075.h:66
Class that stores state and functions for interacting with VEML6075 sensor IC.
Definition: Adafruit_VEML6075.h:77
float readUVB(void)
read the calibrated UVB band reading
Definition: Adafruit_VEML6075.cpp:304
enum veml6075_integrationtime veml6075_integrationtime_t
integration time definitions
void setCoefficients(float UVA_A, float UVA_B, float UVA_C, float UVA_D, float UVA_response, float UVB_response)
Set the UVI calculation coefficients, see datasheet for some example values. We use the default "no c...
Definition: Adafruit_VEML6075.cpp:118
void setForcedMode(bool flag)
Sets whether to take readings on request.
Definition: Adafruit_VEML6075.cpp:217
uint8_t UV_HD
High dynamic.
Definition: Adafruit_VEML6075.h:64
void setIntegrationTime(veml6075_integrationtime_t itime)
Set the time over which we sample UV data per read.
Definition: Adafruit_VEML6075.cpp:146