RAK12031 WisBlock T-Beam-Fork Sensor Module Quick Start Guide
Prerequisite
Package Inclusions
Before going through each and every step on using the RAK12031 WisBlock module, make sure to prepare the necessary items listed below:
Hardware
- RAK12031 WisBlock T-Beam-Fork Sensor Module
- RAK19005 FPC Sensor Extension Cable (optional)
- Your choice of WisBlock Base
- Your choice of WisBlock Core
- USB Cable
- Li-Ion/LiPo battery (optional)
- Solar charger (optional)
Software
- Download and install the ArduinoIDE.
- 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
RAK12031 is a WisBlock T-Beam-Fork (TBF) sensor module that is based on EE-SX1041 from Omron. It can detect the presence of small moving objects, measure the speed of rotation, linear motion, and more. RAK12031 is a separate TBF sensor and have two (2) connectors, which can be connected to the RAK12028 TBF Connector module or by using a RAK19005 WisBlock Sensor Extension Cable to connect it to the WisBlock Base.
For more information about RAK12031, refer to the Datasheet.
RAK12031 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.
Assembling and Disassembling of WisBlock Modules
Assembling
As shown in Figure 3, the location for Slots 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.
Disassembling
The procedure in disassembling any type of WisBlock module is the same.
- First, remove the screws.
- Once the screws are removed, check the silkscreen of the module to find the correct location where force can be applied.
- Apply force to the module at the position of the connector, as shown in Figure 6, to detach the module from the baseboard.
If you will connect other modules to the remaining WisBlock Base slots, check on the WisBlock Pin Mapper tool for possible conflicts.
After all this setup, you can now connect the battery (optional) and USB cable to start programming your WisBlock Core.
- 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 RAK12031 WisBlock Module
-
Install the RAKwireless Arduino BSP for WisBlock by using the
package_rakwireless_index.json
board installation package. The WisBlock Core should now be available on the Arduino IDE. -
You need to select first the WisBlock Core you have.
RAK4631 Board
RAK11200 Board
RAK11310 Board
- Next, copy the following sample code into your Arduino IDE:
Click to view the code
/**
@file RAK12031_T_Fork_SX1041.ino
@author rakwireless.com
@brief TBF example.
Can detect presence of small objects.
Can detect movement and rotation speed of a slot disk.
@version 0.1
@date 2021-10-18
@copyright Copyright (c) 2020
**/
#include <Adafruit_TinyUSB.h>
// It use WB_IO2 to power up and is conflicting with singal pin, so better use in SlotA/SlotC/SlotD.
#define SINGAL_PIN WB_IO1 // Connect with TBF out put pin. Mount in SLOT A.
//#define SINGAL_PIN WB_IO3 // Connect with TBF out put pin. Mount in SLOT C.
//#define SINGAL_PIN WB_IO5 // Connect with TBF out put pin. Mount in SLOT D.
#define ROTATIONL_COUNT 20 // Adjust according to the code wheel used.
volatile uint32_t g_pulse_count=0;
void setup()
{
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, HIGH); // Enable power supply.
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("TBF example.");
pinMode(SINGAL_PIN,INPUT_PULLDOWN); // Connect with TBF out put pin.
attachInterrupt(digitalPinToInterrupt(SINGAL_PIN) ,pulse_INT_call_back ,FALLING); // Enable interrupts.FALLING CHANGE
Serial.println("Waiting for motion.");
}
void pulse_INT_call_back()
{
g_pulse_count++;
}
void loop()
{
float rotationl_speed = 0;
Serial.print("Pulse count:");
Serial.print(g_pulse_count);
rotationl_speed = (float)g_pulse_count / (float)ROTATIONL_COUNT;
g_pulse_count = 0;
Serial.print(" ");
Serial.print("Rotating speed:");
Serial.print(rotationl_speed);
Serial.print("[r/s]");
Serial.print(" ");
if( digitalRead(SINGAL_PIN) == LOW )
{
Serial.println("Object exists.");
}
else
{
Serial.println("Object not exists.");
}
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 RAK12031 WisBlock Example Code Repository and this sample code in Github will work on all WisBlock Core.
- Once the example code is open, you can now select the right serial port and upload the code, as shown in Figure 10 and Figure 11.
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.
- When you have successfully uploaded the example sketch, open the serial monitor of the Arduino IDE and set the baud rate correctly. You will be able to see the sensor's output, as shown in Figure 12. Try to place an object in the middle of the of T-Beam-Fork Sensor. If the presence of the object and the rotation speed, then your RAK12031 is properly communicating with the WisBlock core.