RAK12014 WisBlock ToF Sensor Module Quick Start Guide
Prerequisite
- Assemble the RAK12014 with a WisBlock Base and WisBlock Core by following the RAK12014 Installation Guide.
- Download and install the Arduino IDE, then add the RAKwireless Core boards by installing the RAKwireless Arduino BSP.
- USB Cable
- RAK19005 WisBlock Sensor Extension Cable (optional)
- Li-Ion/LiPo battery (optional)
- Solar charger (optional)
Initial Test of the RAK12014 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- Copy the example code below:
Click to view the code
/**
@file RAK12014_Distance_Detection.ino
@author rakwireless.com
@brief Distance detection by laser
@version 0.1
@date 2021-8-28
@copyright Copyright (c) 2020
**/
#include <Wire.h>
#include <vl53l0x_class.h> // Click to install library: http://librarymanager/All#stm32duino_vl53l0x
VL53L0X sensor_vl53l0x(&Wire, WB_IO2);
void setup() {
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, HIGH);
int status;
// Initialize serial for output.
Serial.begin(115200);
// Initialize I2C bus.
Wire.begin();
// Configure VL53L0X component.
sensor_vl53l0x.begin();
// Switch off VL53L0X component.
sensor_vl53l0x.VL53L0X_Off();
// Initialize VL53L0X component.
status = sensor_vl53l0x.InitSensor(0x52);
if(status)
{
Serial.println("Init sensor_vl53l0x failed...");
}
}
void loop() {
// Read Range.
uint32_t distance;
int status;
status = sensor_vl53l0x.GetDistance(&distance);
if (status == VL53L0X_ERROR_NONE)
{
// Output data.
char report[64];
snprintf(report, sizeof(report), "| Distance [mm]: %ld |", distance);
Serial.println(report);
}
delay(300);
}
If you experience any error in compiling the example sketch, check the updated code for the RAK12014 WisBlock ToF Sensor Module that can be found on the RAK12014 WisBlock Example Code Repository.
- Install the required library.
Figure 1: Getting the library link
Figure 1: Installing the library- Select the right serial port and upload the code.
Figure 1: Selecting the correct serial port
Figure 1: Uploading the sample code- When you have successfully uploaded the sample code, you may open up your serial monitor. You can try to experiment with the data by moving the sensor away from the detected surface.
Figure 1: Serial monitor reading