Skip to content

Commit 30fa18c

Browse files
committed
Add: examples2-4; getIntegrationTimeStr; getSensitivityModeStr
1 parent 3698a61 commit 30fa18c

File tree

7 files changed

+273
-3
lines changed

7 files changed

+273
-3
lines changed

examples/Example1_getLux/Example1_getLux.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ void loop()
4444
{
4545
Serial.println(mySensor.getLux(), 4); // Read the lux from the sensor and print it
4646
delay(250);
47-
}
47+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*!
2+
* @file Example2_changeSettings.ino
3+
*
4+
* This example was written by:
5+
* Paul Clark
6+
* SparkFun Electronics
7+
* November 4th 2021
8+
*
9+
* This example demonstrates how to change the VEML7700's sensitivity (gain) and integration time settings.
10+
*
11+
* Want to support open source hardware? Buy a board from SparkFun!
12+
* <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
13+
*
14+
* Please see LICENSE.md for the license information
15+
*
16+
*/
17+
18+
#include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700
19+
20+
VEML7700 mySensor; // Create a VEML7700 object
21+
22+
void setup()
23+
{
24+
Serial.begin(115200);
25+
Serial.println(F("SparkFun VEML7700 Example"));
26+
27+
Wire.begin();
28+
29+
//mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
30+
31+
// Begin the VEML7700 using the Wire I2C port
32+
// .begin will return true on success, or false on failure to communicate
33+
if (mySensor.begin() == false)
34+
{
35+
Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing...");
36+
while (1)
37+
;
38+
}
39+
40+
//The default integration time is 100ms.
41+
//Possible values are:
42+
//VEML7700_INTEGRATION_25ms
43+
//VEML7700_INTEGRATION_50ms
44+
//VEML7700_INTEGRATION_100ms
45+
//VEML7700_INTEGRATION_200ms
46+
//VEML7700_INTEGRATION_400ms
47+
//VEML7700_INTEGRATION_800ms
48+
//Let's change the integration time to 50ms:
49+
mySensor.setIntegrationTime(VEML7700_INTEGRATION_50ms);
50+
51+
//Confirm the integration time was set correctly
52+
Serial.print(F("The sensor integration time is: "));
53+
Serial.println(mySensor.getIntegrationTimeStr());
54+
55+
//The default gain (sensitivity mode) is x1
56+
//Possible values are:
57+
//VEML7700_SENSITIVITY_x1
58+
//VEML7700_SENSITIVITY_x2
59+
//VEML7700_SENSITIVITY_x1_8
60+
//VEML7700_SENSITIVITY_x1_4
61+
//Let's change the sensitivity to x2:
62+
mySensor.setSensitivityMode(VEML7700_SENSITIVITY_x2);
63+
64+
//Confirm that the sensitivity mode was set correctly
65+
Serial.print(F("The sensor gain (sensitivity mode) is: "));
66+
Serial.println(mySensor.getSensitivityModeStr());
67+
68+
Serial.println(F("Lux:"));
69+
}
70+
71+
void loop()
72+
{
73+
Serial.println(mySensor.getLux(), 4); // Read the lux from the sensor and print it
74+
delay(250);
75+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*!
2+
* @file Example3_threshold.ino
3+
*
4+
* This example was written by:
5+
* Paul Clark
6+
* SparkFun Electronics
7+
* November 4th 2021
8+
*
9+
* This example demonstrates how to change the VEML7700's threshold settings.
10+
*
11+
* Want to support open source hardware? Buy a board from SparkFun!
12+
* <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
13+
*
14+
* Please see LICENSE.md for the license information
15+
*
16+
*/
17+
18+
#include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700
19+
20+
VEML7700 mySensor; // Create a VEML7700 object
21+
22+
void setup()
23+
{
24+
Serial.begin(115200);
25+
Serial.println(F("SparkFun VEML7700 Example"));
26+
27+
Wire.begin();
28+
29+
//mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
30+
31+
// Begin the VEML7700 using the Wire I2C port
32+
// .begin will return true on success, or false on failure to communicate
33+
if (mySensor.begin() == false)
34+
{
35+
Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing...");
36+
while (1)
37+
;
38+
}
39+
40+
//Let's change the high thresold to 30000 counts:
41+
mySensor.setHighThreshold(30000);
42+
43+
//Confirm the high threshold was set correctly
44+
Serial.print(F("The high threshold is: "));
45+
Serial.println(mySensor.getHighThreshold());
46+
47+
//Let's change the low threshold to 1000 counts:
48+
mySensor.setLowThreshold(1000);
49+
50+
//Confirm the low threshold was set correctly
51+
Serial.print(F("The low threshold is: "));
52+
Serial.println(mySensor.getLowThreshold());
53+
54+
//Enable the high and low threshold interrupts
55+
mySensor.setInterruptEnable(VEML7700_INT_ENABLE);
56+
57+
//Check that the interrupts are enabled
58+
Serial.print(F("Interrupts are "));
59+
VEML7700_interrupt_enable_t ie;
60+
mySensor.getInterruptEnable(&ie);
61+
if ((ie == VEML7700_INT_DISABLE) || ( ie == VEML7700_INT_INVALID))
62+
Serial.print(F("not "));
63+
Serial.println(F("enabled"));
64+
}
65+
66+
void loop()
67+
{
68+
Serial.print(F("Ambient: "));
69+
Serial.print(mySensor.getAmbientLight()); // Read the ambient light level from the sensor and print it
70+
71+
if (mySensor.getHighInterruptStatus()) // Check the high threshold interrupt status
72+
Serial.print(F("\tHigh Threshold Exceeded"));
73+
74+
if (mySensor.getLowInterruptStatus()) // Check the low threshold interrupt status
75+
Serial.println(F("\tLow Threshold Exceeded"));
76+
else
77+
Serial.println();
78+
79+
//Clear the interrupt flags
80+
mySensor.clearInterruptStatus();
81+
82+
delay(250);
83+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*!
2+
* @file Example3_threshold.ino
3+
*
4+
* This example was written by:
5+
* Paul Clark
6+
* SparkFun Electronics
7+
* November 4th 2021
8+
*
9+
* This example demonstrates how to shut down the VEML7700.
10+
*
11+
* Want to support open source hardware? Buy a board from SparkFun!
12+
* <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
13+
*
14+
* Please see LICENSE.md for the license information
15+
*
16+
*/
17+
18+
#include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700
19+
20+
VEML7700 mySensor; // Create a VEML7700 object
21+
22+
unsigned long lastMillis = 0; // Keep track of time
23+
24+
VEML7700_shutdown_t shutdownState = VEML7700_POWER_ON; // Toggle between VEML7700_POWER_ON and VEML7700_SHUT_DOWN
25+
26+
void setup()
27+
{
28+
Serial.begin(115200);
29+
Serial.println(F("SparkFun VEML7700 Example"));
30+
31+
Wire.begin();
32+
33+
//mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
34+
35+
// Begin the VEML7700 using the Wire I2C port
36+
// .begin will return true on success, or false on failure to communicate
37+
if (mySensor.begin() == false)
38+
{
39+
Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing...");
40+
while (1)
41+
;
42+
}
43+
44+
lastMillis = millis(); // Keep track of time
45+
}
46+
47+
void loop()
48+
{
49+
if (shutdownState == VEML7700_POWER_ON) // Are we "On"? (Comment this if you are interested in how it effects the sleep current)
50+
{
51+
Serial.print(F("Lux: "));
52+
Serial.println(mySensor.getLux(), 4); // Read the lux from the sensor and print it
53+
}
54+
55+
//Check if it is time to change the power state
56+
if (millis() > (lastMillis + 5000)) // Change state every 5 seconds
57+
{
58+
lastMillis = millis(); // Keep track of time
59+
60+
if (shutdownState == VEML7700_POWER_ON) // Are we "On"?
61+
{
62+
shutdownState = VEML7700_SHUT_DOWN; // Put sensor to sleep
63+
mySensor.setShutdown(shutdownState);
64+
65+
//mySensor.shutDown(); // This would do the same thing
66+
}
67+
else
68+
{
69+
shutdownState = VEML7700_POWER_ON; // Power sensor on
70+
mySensor.setShutdown(shutdownState);
71+
72+
//mySensor.powerOn(); // This would do the same thing
73+
}
74+
}
75+
76+
delay(125);
77+
}

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ setPersistenceProtect KEYWORD2
3434
getPersistenceProtect KEYWORD2
3535
setIntegrationTime KEYWORD2
3636
getIntegrationTime KEYWORD2
37+
getIntegrationTimeStr KEYWORD2
3738
setSensitivityMode KEYWORD2
3839
getSensitivityMode KEYWORD2
40+
getSensitivityModeStr KEYWORD2
3941
setHighThreshold KEYWORD2
4042
getHighThreshold KEYWORD2
4143
setLowThreshold KEYWORD2

src/SparkFun_VEML7700_Arduino_Library.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ const float VEML7700_LUX_RESOLUTION[VEML7700_NUM_GAIN_SETTINGS][VEML7700_NUM_INT
3232
{0.9216, 0.4608, 0.2304, 0.1152, 0.0576, 0.0288} // Gain (sensitivity) 1/4
3333
};
3434

35+
const char *VEML7700_GAIN_SETTINGS[VEML7700_NUM_GAIN_SETTINGS + 1] =
36+
{
37+
// Note: these are in the order define by ALS_SM and VEML7700_sensitivity_mode_t
38+
"x1","x2","x1/8","x1/4","INVALID"
39+
};
40+
41+
const char *VEML7700_INTEGRATION_TIMES[VEML7700_NUM_INTEGRATION_TIMES + 1] =
42+
{
43+
// Note: these are in ascending (VEML7700_integration_time_t) order
44+
// _not_ in ALS_IT (VEML7700_config_integration_time_t) order
45+
"25ms","50ms","100ms","200ms","400ms","800ms","INVALID"
46+
};
47+
3548
VEML7700::VEML7700()
3649
{
3750
_i2cPort = NULL;
@@ -269,6 +282,15 @@ VEML7700_integration_time_t VEML7700::getIntegrationTime()
269282
return ((VEML7700_integration_time_t)integrationTimeFromConfig((VEML7700_config_integration_time_t)_configurationRegister.CONFIG_REG_IT));
270283
}
271284

285+
const char * VEML7700::getIntegrationTimeStr()
286+
{
287+
VEML7700_integration_time_t it;
288+
289+
getIntegrationTime(&it);
290+
291+
return (VEML7700_INTEGRATION_TIMES[it]);
292+
}
293+
272294
VEML7700_error_t VEML7700::setSensitivityMode(VEML7700_sensitivity_mode_t sm)
273295
{
274296
VEML7700_error_t err;
@@ -315,6 +337,15 @@ VEML7700_sensitivity_mode_t VEML7700::getSensitivityMode()
315337
return ((VEML7700_sensitivity_mode_t)_configurationRegister.CONFIG_REG_SM);
316338
}
317339

340+
const char * VEML7700::getSensitivityModeStr()
341+
{
342+
VEML7700_sensitivity_mode_t sm;
343+
344+
getSensitivityMode(&sm);
345+
346+
return (VEML7700_GAIN_SETTINGS[sm]);
347+
}
348+
318349
VEML7700_error_t VEML7700::setHighThreshold(uint16_t threshold)
319350
{
320351
return (writeI2CRegister((VEML7700_t)threshold, VEML7700_HIGH_THRESHOLD));
@@ -390,7 +421,7 @@ VEML7700_error_t VEML7700::getLux(float *lux)
390421
if (_debugEnabled)
391422
{
392423
_debugPort->print(F("VEML7700::getLux: gain / sensitivity: "));
393-
_debugPort->println(sm);
424+
_debugPort->println(VEML7700_GAIN_SETTINGS[sm]);
394425
}
395426

396427
VEML7700_integration_time_t it;
@@ -403,7 +434,7 @@ VEML7700_error_t VEML7700::getLux(float *lux)
403434
if (_debugEnabled)
404435
{
405436
_debugPort->print(F("VEML7700::getLux: integration time: "));
406-
_debugPort->println(it);
437+
_debugPort->println(VEML7700_INTEGRATION_TIMES[it]);
407438
}
408439

409440
// Now we can extract the correct resolution from the look up table.

src/SparkFun_VEML7700_Arduino_Library.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ class VEML7700
112112
VEML7700_error_t setIntegrationTime(VEML7700_integration_time_t it);
113113
VEML7700_error_t getIntegrationTime(VEML7700_integration_time_t *it);
114114
VEML7700_integration_time_t getIntegrationTime();
115+
const char * getIntegrationTimeStr();
115116

116117
VEML7700_error_t setSensitivityMode(VEML7700_sensitivity_mode_t sm);
117118
VEML7700_error_t getSensitivityMode(VEML7700_sensitivity_mode_t *sm);
118119
VEML7700_sensitivity_mode_t getSensitivityMode();
120+
const char * getSensitivityModeStr();
119121

120122
VEML7700_error_t setHighThreshold(uint16_t threshold);
121123
VEML7700_error_t getHighThreshold(uint16_t *threshold);

0 commit comments

Comments
 (0)