RAK12031 WisBlock T-Beam-Fork Sensor Module Quick Start Guide
Prerequisite
-
Assemble the RAK12031 with a WisBlock Base and WisBlock Core by following the RAK12031 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 RAK12031 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 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.
Figure 1: Selecting the correct serial port
Figure 1: Uploading the RAK12031 example code- 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. 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.
Figure 1: RAK12031 sensor serial readings