RAK12021 WisBlock RGB Sensor Module Quick Start Guide
Prerequisite
-
Assemble the RAK12021 with a WisBlock Base and WisBlock Core by following the RAK12021 Installation Guide.
-
Download and install the Arduino IDE, then add the RAKwireless Core boards by installing the RAKwireless Arduino BSP.
-
USB Cable
Initial Test of the RAK12021 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's 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 code
/**
@file RAK12021_RGBC_Auto_Gain_TCS37725.ino
@author rakwireless.com
@brief Use automatic gain to read RGBC data.
@version 0.1
@date 2021-11-08
@copyright Copyright (c) 2020
**/
#include <Wire.h>
#include "TCS3772.h" // Click here to get the library: http://librarymanager/All#TCS37725
// It use WB_IO2 to power up and is conflicting with INT1, so better use in SlotA/SlotC/SlotD.
TCS3772 tcs3772;
void setup()
{
//Sensor power switch
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, HIGH);
#if !defined (_VARIANT_RAK11300_)
Wire.begin();
#endif
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("RAK12021 RGBC auto gain example.");
if(tcs3772.begin() == true)
{
Serial.println("Found sensor.");
}
else
{
Serial.println("TCS37725 not found ... check your connections.");
while(1)
{
delay(10);
}
}
delay(1000);
}
void loop()
{
TCS3772_DataScaled tcs3772_data = {0};
uint16_t scale_factor;
tcs3772_data = tcs3772.getMeasurement();
scale_factor = tcs3772.autoGain(tcs3772_data.clear);
Serial.print(" R: ");
Serial.print(tcs3772_data.red);
Serial.print(" G: ");
Serial.print(tcs3772_data.green);
Serial.print(" B: ");
Serial.print(tcs3772_data.blue);
Serial.print(" C: ");
Serial.print(tcs3772_data.clear);
Serial.print(" P: ");
Serial.print(tcs3772_data.blue);
Serial.print(" Gain: ");
Serial.println(scale_factor);
delay(1000);
}
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 RAK12021 WisBlock Example Code Repository. This sample code in Github will work on all WisBlock Core.
- Once the example code is open, install the RAK12021-TCS3772 library by clicking the yellow-highlighted link.
Figure 1: Accessing the library used for RAK12021 Module
Figure 1: Installing the compatible library for RAK12021 Module- After the 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 RAK12021 example code- When you have successfully uploaded the example sketch, open the serial monitor of the Arduino IDE and set the baud rate correctly. You will then see the sensor's output and also the color values for Red, Green, Blue, and Clear. Therefore, your RAK12021 is properly communicating to the WisBlock core.
Figure 1: RAK12021 RGB Sensor serial readings