Skip to main content

RAK12021 WisBlock RGB Sensor Module Quick Start Guide

Prerequisite

What Do You Need?

Before going through each and every step on using the RAK12021 WisBlock module, make sure to prepare the necessary items listed below:

Hardware

Software

  • Download and install the Arduino IDE.
  • To add the RAKwireless Core boards on your Arduino board, install the RAKwireless Arduino BSP. Follow the steps in the GitHub repo.

Product Configuration

Hardware Setup

RAK12021 is a WisBlock RGB Sensor that extends the WisBlock system which is based on TCS37725FN from AMS. The Red, Green, Blue, and Clear (RGBC) light sensing can be obtained via I2C interface. An external IR LED is also added for Proximity Detection.

For more information about RAK12021, refer to the Datasheet.

RAK12021 module can be connected to the sensor's slot of WisBlock Base to communicate with the WisBlock Core, as shown in Figure 1. It will work on SLOT A, C to F. Also, always secure the connection of the WisBlock module by using compatible screws.

Figure 2587: RAK12021 connection to WisBlock Base

Assembling and Disassembling of WisBlock Modules

Assembling

As shown in Figure 2, the location for Slot A, B, C, and D are properly marked by silkscreen. Follow carefully the procedure defined in WisBlock Base board assembly/disassembly instructions to attach a WisBlock module. Once attached, carefully fix the module with one or more pieces of M1.2 x 3 mm screws depending on the module.

Figure 2588: RAK12021 connection to WisBlock Base
Disassembling

The procedure in disassembling any type of WisBlock modules is the same.

  1. First, remove the screws.
Figure 2589: Removing screws from the WisBlock module
  1. Once the screws are removed, check the silkscreen of the module to find the correct location where force can be applied.
Figure 2590: Detaching silkscreen on the WisBlock module
  1. Apply force to the module at the position of the connector, as shown in Figure 5, to detach the module from the baseboard.
Figure 2591: Applying even forces on the proper location of a WisBlock module
NOTE

If you will connect other modules to the remaining WisBlock Base slots, check on the WisBlock Pin Mapper tool for possible conflicts. RAK12021 uses I2C communication lines, and it can cause possible conflict, especially on some IO modules.

After all this setup, you can now connect the battery (optional) and USB cable to start programming your WisBlock Core.

warning
  • Batteries can cause harm if not handled properly.
  • Only 3.7-4.2 V Rechargeable LiPo batteries are supported. It is highly recommended not to use other types of batteries with the system unless you know what you are doing.
  • If a non-rechargeable battery is used, it has to be unplugged first before connecting the USB cable to the USB port of the board to configure the device. Not doing so might damage the battery or cause a fire.
  • Only 5 V solar panels are supported. Do not use 12 V solar panels. It will destroy the charging unit and eventually other electronic parts.
  • Make sure the battery wires match the polarity on the WisBlock Base board. Not all batteries have the same wiring.

Software Configuration and Example

Initial Test of the RAK12021 WisBlock Module

  1. Install the RAKwireless Arduino BSP's for WisBlock by using the package_rakwireless_index.json board installation package, the WisBlock Core should now be available on the Arduino IDE.

  2. You need to select first the WisBlock Core you have.

RAK4631 Board

Figure 2592: Selecting RAK4631 as WisBlock Core

RAK11200 Board

Figure 2593: Selecting RAK11200 as WisBlock Core

RAK11310 Board

Figure 2594: Selecting RAK11310 as WisBlock Core
  1. 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);
}

NOTE

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.

  1. Once the example code is open, install the RAK12021-TCS3772 library by clicking the yellow-highlighted link, as shown in Figure 9 and Figure 10.
Figure 2595: Accessing the library used for RAK12021 Module
Figure 2596: Installing the compatible library for RAK12021 Module
  1. After the successful installation of the library, you can now select the right serial port and upload the code, as shown in Figure 11 and Figure 12.
NOTE

If you are using the RAK11200 as your WisBlock Core, the RAK11200 requires the Boot0 pin to be configured properly first before uploading. If not done properly, uploading the source code to RAK11200 will fail. Check the full details on the RAK11200 Quick Start Guide.

Figure 2597: Selecting the correct Serial Port
Figure 2598: Uploading the RAK12021 example code
  1. 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, as shown in Figure 13, and also the color values for Red, Green, Blue, and Clear. Therefore, your RAK12021 is properly communicating to the WisBlock core.
Figure 2599: RAK12021 RGB Sensor serial readings