SparkFun_VEML7700_Arduino_Library
SparkFun_VEML7700_Arduino_Library.h
Go to the documentation of this file.
1 
20 #ifndef __SFE_SMOL_POWER_BOARD__
21 #define __SFE_SMOL_POWER_BOARD__
22 
23 #include <Arduino.h>
24 #include <Wire.h>
25 
26 typedef uint16_t VEML7700_t;
27 
29 #define VEML7700_I2C_ADDRESS 0x10
30 
32 typedef enum
33 {
34  VEML7700_ERROR_READ = -4,
35  VEML7700_ERROR_WRITE = -3,
36  VEML7700_ERROR_INVALID_ADDRESS = -2,
37  VEML7700_ERROR_UNDEFINED = -1,
38  VEML7700_ERROR_SUCCESS = 1
40 const VEML7700_error_t VEML7700_SUCCESS = VEML7700_ERROR_SUCCESS;
41 
43 typedef enum
44 {
45  VEML7700_SENSITIVITY_x1,
46  VEML7700_SENSITIVITY_x2,
47  VEML7700_SENSITIVITY_x1_8,
48  VEML7700_SENSITIVITY_x1_4,
49  VEML7700_SENSITIVITY_INVALID
51 
55 typedef enum
56 {
57  VEML7700_INTEGRATION_25ms,
58  VEML7700_INTEGRATION_50ms,
59  VEML7700_INTEGRATION_100ms,
60  VEML7700_INTEGRATION_200ms,
61  VEML7700_INTEGRATION_400ms,
62  VEML7700_INTEGRATION_800ms,
63  VEML7700_INTEGRATION_INVALID
65 
67 typedef enum
68 {
69  VEML7700_PERSISTENCE_1,
70  VEML7700_PERSISTENCE_2,
71  VEML7700_PERSISTENCE_4,
72  VEML7700_PERSISTENCE_8,
73  VEML7700_PERSISTENCE_INVALID
75 
77 typedef enum
78 {
79  VEML7700_INT_DISABLE,
80  VEML7700_INT_ENABLE,
81  VEML7700_INT_INVALID
83 
85 typedef enum
86 {
87  VEML7700_INT_STATUS_NONE,
88  VEML7700_INT_STATUS_HIGH,
89  VEML7700_INT_STATUS_LOW,
90  VEML7700_INT_STATUS_BOTH,
91  VEML7700_INT_STATUS_INVALID
93 
95 typedef enum
96 {
97  VEML7700_POWER_ON,
98  VEML7700_SHUT_DOWN,
99  VEML7700_SHUTDOWN_INVALID
101 
103 class VEML7700
104 {
105 public:
107  VEML7700();
108 
110  bool begin(TwoWire &wirePort = Wire);
111 
113  void enableDebugging(Stream &debugPort = Serial);
114  void disableDebugging();
115 
116  bool isConnected();
117 
121  VEML7700_error_t powerOn() { return setShutdown(VEML7700_POWER_ON); };
122  VEML7700_error_t shutdown() { return setShutdown(VEML7700_SHUT_DOWN); };
124 
128 
132  const char * getPersistenceProtectStr();
133 
137  const char * getIntegrationTimeStr();
138 
142  const char * getSensitivityModeStr();
143 
144  VEML7700_error_t setHighThreshold(uint16_t threshold);
145  VEML7700_error_t getHighThreshold(uint16_t *threshold);
146  uint16_t getHighThreshold();
147 
148  VEML7700_error_t setLowThreshold(uint16_t threshold);
149  VEML7700_error_t getLowThreshold(uint16_t *threshold);
150  uint16_t getLowThreshold();
151 
154  VEML7700_error_t getAmbientLight(uint16_t *ambient);
155  uint16_t getAmbientLight();
156 
157  VEML7700_error_t getWhiteLevel(uint16_t *whiteLevel);
158  uint16_t getWhiteLevel();
159 
160  VEML7700_error_t getLux(float *lux);
161  float getLux();
162 
167 
168 private:
169 
171  typedef struct
172  {
173  union
174  {
175  VEML7700_t all;
176  struct
177  {
178  VEML7700_t CONFIG_REG_SD : 1; // ALS shut down
179  VEML7700_t CONFIG_REG_INT_EN : 1; // ALS interrupt enable
180  VEML7700_t CONFIG_REG_RES1 : 2; // Reserved
181  VEML7700_t CONFIG_REG_PERS : 2; // ALS persistence protect number
182  VEML7700_t CONFIG_REG_IT : 4; // ALS integration time
183  VEML7700_t CONFIG_REG_RES2 : 1; // Reserved
184  VEML7700_t CONFIG_REG_SM : 2; // ALS sensitivity mode
185  VEML7700_t CONFIG_REG_RES3 : 3; // Reserved
186  };
187  };
188  } VEML7700_CONFIGURATION_REGISTER_t;
189  VEML7700_CONFIGURATION_REGISTER_t _configurationRegister;
190 
194  typedef struct
195  {
196  union
197  {
198  VEML7700_t all;
199  struct
200  {
201  VEML7700_t INT_STATUS_REG_RES : 14; // Reserved
202  // Bit 14 indicates if the high threshold was exceeded
203  // Bit 15 indicates if the low threshold was exceeded
204  VEML7700_t INT_STATUS_REG_INT_FLAGS : 2;
205  };
206  };
207  } VEML7700_INTERRUPT_STATUS_REGISTER_t;
208 
210  typedef enum
211  {
212  VEML7700_CONFIGURATION_REGISTER,
213  VEML7700_HIGH_THRESHOLD,
214  VEML7700_LOW_THRESHOLD,
215  VEML7700_ALS_OUTPUT = 4,
216  VEML7700_WHITE_OUTPUT,
217  VEML7700_INTERRUPT_STATUS
218  } VEML7700_registers_t;
219 
221  typedef enum
222  {
223  VEML7700_CONFIG_INTEGRATION_25ms = 0b1100,
224  VEML7700_CONFIG_INTEGRATION_50ms = 0b1000,
225  VEML7700_CONFIG_INTEGRATION_100ms = 0b0000,
226  VEML7700_CONFIG_INTEGRATION_200ms = 0b0001,
227  VEML7700_CONFIG_INTEGRATION_400ms = 0b0010,
228  VEML7700_CONFIG_INTEGRATION_800ms = 0b0011,
229  VEML7700_CONFIG_INTEGRATION_INVALID
230  } VEML7700_config_integration_time_t;
231 
232  TwoWire *_i2cPort;
233  Stream *_debugPort;
234  uint8_t _deviceAddress;
235  bool _debugEnabled;
236 
237  VEML7700_error_t _connected(void);
238 
240  VEML7700_error_t readI2CBuffer(uint8_t *dest, VEML7700_registers_t startRegister, uint16_t len);
241  VEML7700_error_t writeI2CBuffer(uint8_t *src, VEML7700_registers_t startRegister, uint16_t len);
242  VEML7700_error_t readI2CRegister(VEML7700_t *dest, VEML7700_registers_t registerAddress);
243  VEML7700_error_t writeI2CRegister(VEML7700_t data, VEML7700_registers_t registerAddress);
244 
246  VEML7700_config_integration_time_t integrationTimeConfig(VEML7700_integration_time_t it);
248  VEML7700_integration_time_t integrationTimeFromConfig(VEML7700_config_integration_time_t it);
249 
250 };
251 
252 #endif
VEML7700_interrupt_enable_t
Definition: SparkFun_VEML7700_Arduino_Library.h:78
VEML7700_integration_time_t
Definition: SparkFun_VEML7700_Arduino_Library.h:56
VEML7700_shutdown_t
Definition: SparkFun_VEML7700_Arduino_Library.h:96
VEML7700_error_t
Definition: SparkFun_VEML7700_Arduino_Library.h:33
VEML7700_interrupt_status_t
Definition: SparkFun_VEML7700_Arduino_Library.h:86
VEML7700_sensitivity_mode_t
Definition: SparkFun_VEML7700_Arduino_Library.h:44
VEML7700_persistence_protect_t
Definition: SparkFun_VEML7700_Arduino_Library.h:68
Definition: SparkFun_VEML7700_Arduino_Library.h:104
const char * getPersistenceProtectStr()
Get the VEML7700's persistence protect number setting (ALS_PERS) as printable text.
Definition: SparkFun_VEML7700_Arduino_Library.cpp:366
VEML7700_error_t setInterruptEnable(VEML7700_interrupt_enable_t ie)
Set the VEML7700's interrupt enable setting (ALS_INT_EN)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:223
VEML7700_interrupt_enable_t getInterruptEnable()
Get the VEML7700's interrupt enable setting (ALS_INT_EN)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:270
VEML7700_error_t setShutdown(VEML7700_shutdown_t)
Set the VEML7700's shut down setting (ALS_SD)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:179
void enableDebugging(Stream &debugPort=Serial)
Enable debug messages on the chosen Serial port (Stream)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:117
VEML7700_error_t setLowThreshold(uint16_t threshold)
Set the VEML7700's ALS low threshold window setting (ALS_WL)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:612
uint16_t getLowThreshold()
Get the VEML7700's ALS low threshold window setting (ALS_WL)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:636
VEML7700()
Class to communicate with the VEML7700.
Definition: SparkFun_VEML7700_Arduino_Library.cpp:64
VEML7700_error_t setHighThreshold(uint16_t threshold)
Set the VEML7700's ALS high threshold window setting (ALS_WH)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:573
VEML7700_interrupt_status_t getInterruptStatus()
Read the VEML7700's interrupt status register Note: reading the interrupt status register clears the...
Definition: SparkFun_VEML7700_Arduino_Library.cpp:833
VEML7700_error_t setIntegrationTime(VEML7700_integration_time_t it)
Set the VEML7700's integration time setting (ALS_IT) Note: these are defined here in simple sequenti...
Definition: SparkFun_VEML7700_Arduino_Library.cpp:391
uint16_t getAmbientLight()
Get the VEML7700's ambient light sensor data (ALS)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:662
VEML7700_integration_time_t getIntegrationTime()
Get the VEML7700's integration time setting (ALS_IT)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:446
const char * getIntegrationTimeStr()
Get the VEML7700's integration time setting (ALS_IT) as printable text.
Definition: SparkFun_VEML7700_Arduino_Library.cpp:464
const char * getSensitivityModeStr()
Get the VEML7700's sensitivity mode selection (ALS_SM) as printable text.
Definition: SparkFun_VEML7700_Arduino_Library.cpp:556
bool isConnected()
Check that the VEML7700 is awake and communicating.
Definition: SparkFun_VEML7700_Arduino_Library.cpp:139
VEML7700_sensitivity_mode_t getSensitivityMode()
Get the VEML7700's sensitivity mode selection (ALS_SM)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:538
void disableDebugging()
Disable debug messages.
Definition: SparkFun_VEML7700_Arduino_Library.cpp:128
uint16_t getWhiteLevel()
Get the VEML7700's white level data (WHITE)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:688
uint16_t getHighThreshold()
Get the VEML7700's ALS high threshold window setting (ALS_WH)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:597
float getLux()
Read the sensor data and calculate the lux.
Definition: SparkFun_VEML7700_Arduino_Library.cpp:776
VEML7700_error_t setPersistenceProtect(VEML7700_persistence_protect_t pp)
Set the VEML7700's persistence protect number setting (ALS_PERS)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:295
VEML7700_error_t setSensitivityMode(VEML7700_sensitivity_mode_t sm)
Set the VEML7700's sensitivity mode selection (ALS_SM)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:485
VEML7700_persistence_protect_t getPersistenceProtect()
Get the VEML7700's persistence protect number setting (ALS_PERS)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:348
VEML7700_shutdown_t getShutdown()
Get the VEML7700's shut down setting (ALS_SD)
Definition: SparkFun_VEML7700_Arduino_Library.cpp:200
bool begin(TwoWire &wirePort=Wire)
Begin communication with the VEML7700.
Definition: SparkFun_VEML7700_Arduino_Library.cpp:81