RAK12010 WisBlock Ambient Light Sensor Module Quick Start Guide
Prerequisite
- Assemble the RAK12010 with a WisBlock Base and WisBlock Core by following the RAK12010 Installation Guide.
- Download and install the Arduino IDE, then add the RAKwireless Core boards by installing the RAKwireless Arduino BSP.
- USB Cable
- Li-Ion/LiPo battery (optional)
- Solar charger (optional)
Initial Test of the RAK12010 WisBlock Module
-
This guide uses the RAK4631 WisBlock Core to demonstrate the configuration process. You can also use the RAK11200 or RAK11310 as the WisBlock Core.
-
When using the RAK11200, configure the BOOT0 pin correctly before uploading the source code. Otherwise, the upload may fail. For detailed instructions, refer to the RAK11200 Quick Start Guide.
-
Install the RAKwireless Arduino BSP for WisBlock by using the
package_rakwireless_index.jsonboard installation package. The WisBlock Core should now be available on the Arduino IDE. -
You need to select first the WisBlock Core you have.
Figure 1: Selecting RAK4631 as WisBlock Core- Next, copy the following sample code into your Arduino IDE:
Click to view the example
/**
@file RAK12010_VEML7700_Light.ino
@author rakwireless.com
@brief Measure ambient light.
@version 0.1
@date 2021-7-15
@copyright Copyright (c) 2021
**/
#include "Light_VEML7700.h" ////http://librarymanager/All#Light_veml7700
Light_VEML7700 VMEL = Light_VEML7700();
void setup()
{
// Initialize Serial for debug output
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, HIGH);
delay(300);
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
if (!VMEL.begin())
{
Serial.println("Sensor not found");
while (1);
}
VMEL.setGain(VEML7700_GAIN_1);
VMEL.setIntegrationTime(VEML7700_IT_800MS);
Serial.print(F("Gain: "));
switch (VMEL.getGain())
{
case VEML7700_GAIN_1: Serial.println("1"); break;
case VEML7700_GAIN_2: Serial.println("2"); break;
case VEML7700_GAIN_1_4: Serial.println("1/4"); break;
case VEML7700_GAIN_1_8: Serial.println("1/8"); break;
}
Serial.print(F("Integration Time (ms): "));
switch (VMEL.getIntegrationTime())
{
case VEML7700_IT_25MS: Serial.println("25"); break;
case VEML7700_IT_50MS: Serial.println("50"); break;
case VEML7700_IT_100MS: Serial.println("100"); break;
case VEML7700_IT_200MS: Serial.println("200"); break;
case VEML7700_IT_400MS: Serial.println("400"); break;
case VEML7700_IT_800MS: Serial.println("800"); break;
}
//veml.powerSaveEnable(true);
//veml.setPowerSaveMode(VEML7700_POWERSAVE_MODE4);
VMEL.setLowThreshold(10000);
VMEL.setHighThreshold(20000);
VMEL.interruptEnable(true);
}
void loop()
{
Serial.print("Lux: ");
Serial.println(VMEL.readLux());
Serial.print("White: ");
Serial.println(VMEL.readWhite());
Serial.print("Raw ALS: ");
Serial.println(VMEL.readALS());
uint16_t irq = VMEL.interruptStatus();
if (irq & VEML7700_INTERRUPT_LOW)
{
Serial.println("Low threshold");
}
if (irq & VEML7700_INTERRUPT_HIGH)
{
Serial.println("High threshold");
}
delay(500);
}
If you experience any error in compiling the example sketch, check the updated code for your WisBlock Core Module that can be found on the RAK12010 WisBlock Example Code Repository. This sample code in Github will work on all WisBlock Core.
- Once the example code is open, install the RAKWireless VEML7700 library by clicking the yellow highlighted link.
Figure 1: Accessing the library used for RAK12010 Module
Figure 1: Installing the compatible library for RAK12010 Module- After successful installation of the library, you can now select the right serial port and upload the code.
Figure 1: Selecting the correct Serial Port
Figure 1: Uploading the RAK12010 example code- When you successfully uploaded the example sketch, open the serial monitor of the Arduino IDE to see the sensor's reading logs. If you see the logs, then your RAK12010 is properly communicating to the WisBlock core. The values changes depending on the brightness/illuminance level of the ambient light.
Figure 1: RAK12010 Ambient Light data logs