RAK12016 WisBlock Flex Sensor Module Quick Start Guide
Prerequisite
-
Assemble the RAK12016 with a WisBlock Base and WisBlock Core by following the RAK12016 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 RAK12016 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 code
/**
@file RAK12016_Flex_FSL0095103ST.ino
@author rakwireless.com
@brief use Flex sensor read sensor datas example.
@version 0.1
@date 2021-07-26
@copyright Copyright (c) 2021
*/
#include <Wire.h>
#include "ADC121C021.h" // Click here to get the library: http://librarymanager/All#RAKwireless_MQx_library
#define ReferenceVoltage 3.3
#define FLEX_ADDRESS 0x54 //the device i2c address
// Measure the voltage at 3.3V and the actual resistance of your// 10k resistor, and enter them below:
const float VCC = 3.3; //Module supply voltage, ADC reference voltage is 3.3V
const float R_DIV = 10000.0; // The partial voltage resistance is 10KΩ
// Upload the code, then try to adjust these values to more// accurately calculate bend degree.
const float STRAIGHT_RESISTANCE = 11563.0; // The flat Resistance
const float BEND_RESISTANCE = 21117.0; //Resistance at 90 degree bending
ADC121C021 Flex;
void setup() {
// put your setup code here, to run once:
/* WisBLOCK 12016 Power On*/
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, HIGH);
delay(300);
/* WisBLOCK 12016 Power On*/
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
//********ADC121C021 ADC convert init ********************************
while (!(Flex.begin(FLEX_ADDRESS, Wire)))
{
Serial.println("please check device!!!");
delay(200);
}
Flex.setVoltageResolution(ReferenceVoltage);
float flexRef = Flex.getVoltageResolution();
uint8_t flexflag = abs(flexRef - ReferenceVoltage);
while(flexflag)
{
Serial.println("please check the Reference Voltage!!!");
delay(200);
}
Serial.println("RAK12016 test Example");
}
/*
* Step 1: Connect the Flex sensor to the sensor module, supply power VCC (3.3V) to the module
* Step 2: Open serial debugging assistant (baud rate 115200), you can see the current printed resistance value. Record the resistance value (unit Ω) at the level and maximum bending to be measured respectively.
* Step 3: Rerunned the test routine after correcting the values of STRAIGHT_RESISTANCE and BEND_RESISTANCE both horizontal resistance variables
* Step 4: The Flex sensor can only be bent to one side of the print. Bending the sensor in the other direction does not produce any reliable data and may damage the sensor,Also be careful not to bend the sensors near the bottom, as they have the potential to kink and fail
*/
void loop() {
// put your main code here, to run repeatedly:
float flexVoltage = Flex.getSensorVoltage();
float flexR = R_DIV * (VCC / flexVoltage - 1.0);
Serial.println("Voltage: " + String(flexVoltage) + " V");
Serial.println("Resistance: " + String(flexR) + " ohms");
float angle = map(flexR, STRAIGHT_RESISTANCE, BEND_RESISTANCE, 0, 90.0);
Serial.println("Bend: " + String(angle) + " degrees");
Serial.println();
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 RAK12016 WisBlock Example Code Repository. This sample code in Github will work on all WisBlock Core.
- Once the example code is open, install the RAKWireless MQx library by clicking the yellow highlighted link.
Figure 1: Accessing the library used for RAK12016 Module
Figure 1: Installing the compatible library for RAK12016 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 RAK12016 example code- When you successfully uploaded the example sketch, open the Serial Monitor of the Arduino IDE to see the sensor's reading logs. Try to bend the flex sensor, and you will see that the resistance readings increase, as well as the bent degrees. Therefore, your RAK12016 is properly communicating to the WisBlock core.
Figure 1: RAK12016 Flex Sensor readings