Initial commit of Arduino libraries
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/*!
|
||||
* @file Example1_getLux.ino
|
||||
*
|
||||
* This example was written by:
|
||||
* Paul Clark
|
||||
* SparkFun Electronics
|
||||
* November 4th 2021
|
||||
*
|
||||
* This example demonstrates how to initialize the VEML7700 and then get the ambient light lux.
|
||||
*
|
||||
* Want to support open source hardware? Buy a board from SparkFun!
|
||||
* <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
|
||||
*
|
||||
* Please see LICENSE.md for the license information
|
||||
*
|
||||
*/
|
||||
|
||||
#include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700
|
||||
|
||||
VEML7700 mySensor; // Create a VEML7700 object
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(F("SparkFun VEML7700 Example"));
|
||||
|
||||
Wire.begin();
|
||||
|
||||
//mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
|
||||
|
||||
// Begin the VEML7700 using the Wire I2C port
|
||||
// .begin will return true on success, or false on failure to communicate
|
||||
if (mySensor.begin() == false)
|
||||
{
|
||||
Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing...");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
Serial.println(F("Lux:"));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println(mySensor.getLux(), 4); // Read the lux from the sensor and print it
|
||||
delay(250);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*!
|
||||
* @file Example2_changeSettings.ino
|
||||
*
|
||||
* This example was written by:
|
||||
* Paul Clark
|
||||
* SparkFun Electronics
|
||||
* November 4th 2021
|
||||
*
|
||||
* This example demonstrates how to change the VEML7700's sensitivity (gain) and integration time settings.
|
||||
*
|
||||
* Want to support open source hardware? Buy a board from SparkFun!
|
||||
* <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
|
||||
*
|
||||
* Please see LICENSE.md for the license information
|
||||
*
|
||||
*/
|
||||
|
||||
#include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700
|
||||
|
||||
VEML7700 mySensor; // Create a VEML7700 object
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(F("SparkFun VEML7700 Example"));
|
||||
|
||||
Wire.begin();
|
||||
|
||||
//mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
|
||||
|
||||
// Begin the VEML7700 using the Wire I2C port
|
||||
// .begin will return true on success, or false on failure to communicate
|
||||
if (mySensor.begin() == false)
|
||||
{
|
||||
Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing...");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
//The default integration time is 100ms.
|
||||
//Possible values are:
|
||||
//VEML7700_INTEGRATION_25ms
|
||||
//VEML7700_INTEGRATION_50ms
|
||||
//VEML7700_INTEGRATION_100ms
|
||||
//VEML7700_INTEGRATION_200ms
|
||||
//VEML7700_INTEGRATION_400ms
|
||||
//VEML7700_INTEGRATION_800ms
|
||||
//Let's change the integration time to 50ms:
|
||||
mySensor.setIntegrationTime(VEML7700_INTEGRATION_50ms);
|
||||
|
||||
//Confirm the integration time was set correctly
|
||||
Serial.print(F("The sensor integration time is: "));
|
||||
Serial.println(mySensor.getIntegrationTimeStr());
|
||||
|
||||
//The default gain (sensitivity mode) is x1
|
||||
//Possible values are:
|
||||
//VEML7700_SENSITIVITY_x1
|
||||
//VEML7700_SENSITIVITY_x2
|
||||
//VEML7700_SENSITIVITY_x1_8
|
||||
//VEML7700_SENSITIVITY_x1_4
|
||||
//Let's change the sensitivity to x2:
|
||||
mySensor.setSensitivityMode(VEML7700_SENSITIVITY_x2);
|
||||
|
||||
//Confirm that the sensitivity mode was set correctly
|
||||
Serial.print(F("The sensor gain (sensitivity mode) is: "));
|
||||
Serial.println(mySensor.getSensitivityModeStr());
|
||||
|
||||
//We can also change the persistence ptotect number. Default is 1.
|
||||
//Possible values are:
|
||||
//VEML7700_PERSISTENCE_1
|
||||
//VEML7700_PERSISTENCE_2
|
||||
//VEML7700_PERSISTENCE_4
|
||||
//VEML7700_PERSISTENCE_8
|
||||
//Let's change the persistence protect to 4:
|
||||
mySensor.setPersistenceProtect(VEML7700_PERSISTENCE_4);
|
||||
|
||||
//Confirm that the persistence protect was set correctly
|
||||
Serial.print(F("The sensor persistence protect setting is: "));
|
||||
Serial.println(mySensor.getPersistenceProtectStr());
|
||||
|
||||
Serial.println(F("Lux:\tAmbient:\tWhite Level:"));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(mySensor.getLux(), 4); // Read the lux from the sensor and print it
|
||||
Serial.print("\t");
|
||||
Serial.print(mySensor.getAmbientLight()); // Read the ambient light level
|
||||
Serial.print("\t");
|
||||
Serial.println(mySensor.getWhiteLevel()); // Read the white channel level
|
||||
delay(250);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*!
|
||||
* @file Example3_threshold.ino
|
||||
*
|
||||
* This example was written by:
|
||||
* Paul Clark
|
||||
* SparkFun Electronics
|
||||
* November 4th 2021
|
||||
*
|
||||
* This example demonstrates how to change the VEML7700's threshold settings.
|
||||
*
|
||||
* Want to support open source hardware? Buy a board from SparkFun!
|
||||
* <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
|
||||
*
|
||||
* Please see LICENSE.md for the license information
|
||||
*
|
||||
*/
|
||||
|
||||
#include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700
|
||||
|
||||
VEML7700 mySensor; // Create a VEML7700 object
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(F("SparkFun VEML7700 Example"));
|
||||
|
||||
Wire.begin();
|
||||
|
||||
//mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
|
||||
|
||||
// Begin the VEML7700 using the Wire I2C port
|
||||
// .begin will return true on success, or false on failure to communicate
|
||||
if (mySensor.begin() == false)
|
||||
{
|
||||
Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing...");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
//Let's change the high threshold to 30000 counts:
|
||||
mySensor.setHighThreshold(30000);
|
||||
|
||||
//Confirm the high threshold was set correctly
|
||||
Serial.print(F("The high threshold is: "));
|
||||
Serial.println(mySensor.getHighThreshold());
|
||||
|
||||
//Let's change the low threshold to 1000 counts:
|
||||
mySensor.setLowThreshold(1000);
|
||||
|
||||
//Confirm the low threshold was set correctly
|
||||
Serial.print(F("The low threshold is: "));
|
||||
Serial.println(mySensor.getLowThreshold());
|
||||
|
||||
//Enable the high and low threshold interrupts
|
||||
mySensor.setInterruptEnable(VEML7700_INT_ENABLE);
|
||||
|
||||
//Check that the interrupts are enabled
|
||||
Serial.print(F("Interrupts are "));
|
||||
VEML7700_interrupt_enable_t ie;
|
||||
mySensor.getInterruptEnable(&ie);
|
||||
if ((ie == VEML7700_INT_DISABLE) || ( ie == VEML7700_INT_INVALID))
|
||||
Serial.print(F("not "));
|
||||
Serial.println(F("enabled"));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(F("Ambient: "));
|
||||
Serial.print(mySensor.getAmbientLight()); // Read the ambient light level from the sensor and print it
|
||||
|
||||
// Note: reading the interrupt status register clears the interrupts, so we need to check both
|
||||
// the high and low interrupt flags in a single read
|
||||
|
||||
VEML7700_interrupt_status_t intStatus = mySensor.getInterruptStatus(); // Check the interrupt status
|
||||
|
||||
// Possible values for intStatus are:
|
||||
// VEML7700_INT_STATUS_NONE
|
||||
// VEML7700_INT_STATUS_HIGH
|
||||
// VEML7700_INT_STATUS_LOW
|
||||
// VEML7700_INT_STATUS_BOTH
|
||||
// VEML7700_INT_STATUS_INVALID
|
||||
|
||||
if (intStatus == VEML7700_INT_STATUS_INVALID)
|
||||
{
|
||||
Serial.print(F("\tInterrupt Status Read Error!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (intStatus & VEML7700_INT_STATUS_HIGH) // Use a logical AND to check if the high flag is set
|
||||
Serial.print(F("\tHigh Threshold Exceeded"));
|
||||
|
||||
if (intStatus & VEML7700_INT_STATUS_LOW) // Use a logical AND to check if the low flag is set
|
||||
Serial.print(F("\tLow Threshold Exceeded"));
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
|
||||
delay(250);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*!
|
||||
* @file Example4_shutDown.ino
|
||||
*
|
||||
* This example was written by:
|
||||
* Paul Clark
|
||||
* SparkFun Electronics
|
||||
* November 4th 2021
|
||||
*
|
||||
* This example demonstrates how to shut down the VEML7700.
|
||||
*
|
||||
* Want to support open source hardware? Buy a board from SparkFun!
|
||||
* <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
|
||||
*
|
||||
* Please see LICENSE.md for the license information
|
||||
*
|
||||
*/
|
||||
|
||||
#include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700
|
||||
|
||||
VEML7700 mySensor; // Create a VEML7700 object
|
||||
|
||||
unsigned long lastMillis = 0; // Keep track of time
|
||||
|
||||
VEML7700_shutdown_t shutdownState = VEML7700_POWER_ON; // Toggle between VEML7700_POWER_ON and VEML7700_SHUT_DOWN
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(F("SparkFun VEML7700 Example"));
|
||||
|
||||
Wire.begin();
|
||||
|
||||
//mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
|
||||
|
||||
// Begin the VEML7700 using the Wire I2C port
|
||||
// .begin will return true on success, or false on failure to communicate
|
||||
if (mySensor.begin() == false)
|
||||
{
|
||||
Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing...");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
lastMillis = millis(); // Keep track of time
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (shutdownState == VEML7700_POWER_ON) // Are we "On"? (Comment this line if you are interested in how it effects the sleep current)
|
||||
{
|
||||
Serial.print(F("Lux: "));
|
||||
Serial.println(mySensor.getLux(), 4); // Read the lux from the sensor and print it
|
||||
}
|
||||
|
||||
//Check if it is time to change the power state
|
||||
if (millis() > (lastMillis + 5000)) // Change state every 5 seconds
|
||||
{
|
||||
lastMillis = millis(); // Keep track of time
|
||||
|
||||
if (shutdownState == VEML7700_POWER_ON) // Are we "On"?
|
||||
{
|
||||
shutdownState = VEML7700_SHUT_DOWN; // Put sensor to sleep
|
||||
mySensor.setShutdown(shutdownState);
|
||||
|
||||
//mySensor.shutDown(); // This would do the same thing
|
||||
}
|
||||
else
|
||||
{
|
||||
shutdownState = VEML7700_POWER_ON; // Power sensor on
|
||||
mySensor.setShutdown(shutdownState);
|
||||
|
||||
//mySensor.powerOn(); // This would do the same thing
|
||||
}
|
||||
}
|
||||
|
||||
delay(125);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*!
|
||||
* @file Example5_alternatePorts.ino
|
||||
*
|
||||
* This example was written by:
|
||||
* Paul Clark
|
||||
* SparkFun Electronics
|
||||
* November 4th 2021
|
||||
*
|
||||
* This example demonstrates how to use alternate Wire and Serial ports when communicating with the VEML7700.
|
||||
*
|
||||
* Want to support open source hardware? Buy a board from SparkFun!
|
||||
* <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
|
||||
*
|
||||
* Please see LICENSE.md for the license information
|
||||
*
|
||||
*/
|
||||
|
||||
#include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700
|
||||
|
||||
VEML7700 mySensor; // Create a VEML7700 object
|
||||
|
||||
#define myWire Wire // Change this to (e.g.) Wire1 if required
|
||||
#define mySerial Serial // Change this to (e.g.) Serial1 if required
|
||||
|
||||
void setup()
|
||||
{
|
||||
mySerial.begin(115200);
|
||||
mySerial.println(F("SparkFun VEML7700 Example"));
|
||||
|
||||
myWire.begin();
|
||||
|
||||
//mySensor.enableDebugging(mySerial); // Uncomment this line to enable helpful debug messages on mySerial
|
||||
|
||||
// Begin the VEML7700 using the myWire I2C port
|
||||
// .begin will return true on success, or false on failure to communicate
|
||||
if (mySensor.begin(myWire) == false)
|
||||
{
|
||||
mySerial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing...");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
mySerial.println(F("Lux:"));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
mySerial.println(mySensor.getLux(), 4); // Read the lux from the sensor and print it
|
||||
delay(250);
|
||||
}
|
||||
Reference in New Issue
Block a user