RAK12032 WisBlock 3-Axis Accelerometer Sensor Quick Start Guide
Prerequisite
-
Assemble the RAK12032 with a WisBlock Base and WisBlock Core by following the RAK12032 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 RAK12032 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. -
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 code
/**
@file RAK12032_3_Axis_Read_ADXL313.ino
@author rakwireless.com
@brief Read 3-axis acceleration data and print it out through the serial port.
@version 0.1
@date 2021-12-25
@copyright Copyright (c) 2021
**/
#include <Wire.h>
#include <SparkFunADXL313.h> //Click here to get the library: http://librarymanager/All#SparkFun_ADXL313
ADXL313 myAdxl;
void setup()
{
// Initialize Serial for debug output
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("Reading values from ADXL313");
Wire.begin();
if (myAdxl.begin() == false) //Begin communication over I2C
{
Serial.println("The sensor did not respond. Please check wiring.");
while(1)
{
delay(10);
}
}
Serial.println("Sensor is connected properly.");
myAdxl.measureModeOn(); // Wakes up the sensor from standby and puts it into measurement mode
}
void loop()
{
float xAxis,yAxis,zAxis;
if(myAdxl.dataReady()) // Check data ready interrupt, note, this clears all other int bits in INT_SOURCE reg
{
myAdxl.readAccel(); // Read all 3 axis, they are stored in class variables: myAdxl.x, myAdxl.y and myAdxl.z
/*
* ±0.5 g : 1024 LSB/g
* ±1 g : 512 LSB/g
* ±2 g : 256 LSB/g
* ±4 g : 128 LSB/g
*/
xAxis = (float)myAdxl.x / 1024;
yAxis = (float)myAdxl.y / 1024;
zAxis = (float)myAdxl.z / 1024;
Serial.print(" x: ");
Serial.print(xAxis);
Serial.print("[g] y: ");
Serial.print(yAxis);
Serial.print("[g] z: ");
Serial.print(zAxis);
Serial.println("[g]");
}
else
{
Serial.println("Waiting for dataReady.");
}
delay(50);
}
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 RAK12032 WisBlock Example Code Repository. The sample code on GitHub will work on all WisBlock Core.
- Once the example code is open, install the SparkFun_ADXL313_Arduino_Library library. Click the highlighted link.
It is important to install version 1.0.0, since it is the stable version of the library. The latest version still has compatibility issues that need to be resolved.
Figure 1: Installing RAK12032 sensor library
Figure 1: Installing RAK12032 sensor library- 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 RAK12032 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 RAK12032 is communicating with the WisBlock core properly. The polarity of the axis depends on the sensor slot where you connected the module.
Figure 1: RAK12032 3-Axis Accelerometer Sensor Module Data Logs