RAK12008 WisBlock CO2 Sensor Quick Start Guide
Prerequisite
- Assemble the RAK12008 with a WisBlock Base and WisBlock Core by following the RAK12008 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 RAK12008 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 t he 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. -
After that, you need to select 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 RAK12008_CO2_BasicReadings_STC31.ino
@author rakwireless.com
@brief Read CO2 and temperature data of STC31, and output data through serial port.
@version 0.1
@date 2022-02-21
@copyright Copyright (c) 2022
**/
#include <Wire.h>
#include "SparkFun_STC3x_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_STC3x
#define STC31_ADDRESS 0x2C
STC3x mySensor;
void setup()
{
pinMode(WB_IO2,OUTPUT);
digitalWrite(WB_IO2,HIGH); //power on RAK12008.
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println(F("STC31 Basic Readings Example."));
Wire.begin();
//mySensor.enableDebugging(); // Uncomment this line to get helpful debug messages on Serial.
if (mySensor.begin(STC31_ADDRESS,Wire) == false)
{
while (1)
{
Serial.println("Sensor not detected. Please check wiring. Freezing...");
delay(5000);
}
}
/*
* We need to tell the sensor what binary gas and full range we are using
* Possible values are:
* STC3X_BINARY_GAS_CO2_N2_100 : Set binary gas to CO2 in N2. Range: 0 to 100 vol%
* STC3X_BINARY_GAS_CO2_AIR_100 : Set binary gas to CO2 in Air. Range: 0 to 100 vol%
* STC3X_BINARY_GAS_CO2_N2_25 : Set binary gas to CO2 in N2. Range: 0 to 25 vol%
* STC3X_BINARY_GAS_CO2_AIR_25 : Set binary gas to CO2 in Air. Range: 0 to 25 vol%
*/
if (mySensor.setBinaryGas(STC3X_BINARY_GAS_CO2_AIR_25) == false)
{
while (1)
{
Serial.println("Could not set the binary gas! Freezing...");
delay(5000);
}
}
}
void loop()
{
if (mySensor.measureGasConcentration()) // measureGasConcentration will return true when fresh data is available.
{
Serial.print(F("CO2(%):"));
Serial.print(mySensor.getCO2(), 2);
Serial.print(F("\tTemperature(C):"));
Serial.print(mySensor.getTemperature(), 2);
Serial.println();
}
else
{
Serial.print(F("."));
}
delay(1000);
}
If you experience any error in compiling the example sketch, check the updated code for your WisBlock Core Module. You can find it on the RAK12008 WisBlock Example Code Repository. The sample code on GitHub will work on all WisBlock Core.
- Once the example code is open, install the SparkFun STC3x library. Click the highlighted link.
Figure 1: Accessing the library used for RAK12008 Module
Figure 1: Installing the compatible library for RAK12008 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 RAK12008 example code- When you have 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 RAK12008 is properly communicating to the WisBlock core. In this example code, you will see CO2 concentration and temperature readings.
RAK12008 is developed for high-concentration CO2 applications and not for common ambient air.
Figure 1: RAK12008 Ambient Light data logs