RAK1904 WisBlock 3-Axis Acceleration Sensor Module Quick Start Guide
Prerequisite
-
WisBlock Base, WisBlock Core, and RAK1904. For assembly instructions, refer to the RAK1904 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 RAK1904 WisBlock Module
-
This guide uses the RAK4631 WisBlock Core to demonstrate the configuration process. You can also use the RAK11200 or RAK11300 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 using the
package_rakwireless_index.jsonboard package. The supported WisBlock Core boards will then be available in the Arduino IDE. -
You need to select the WisBlock Core you have.
Figure 1: Selecting RAK4631 as WisBlock Core- Copy the following sample code into your Arduino IDE:
Click to view the code
/**
@file RAK1904_Accelerate_LIS3DH.ino
@author rakwireless.com
@brief Setup and read values from a lis3dh sensor
@version 0.1
@date 2020-12-28
@copyright Copyright (c) 2020
**/
#include <Arduino.h>
#include "SparkFunLIS3DH.h" //http://librarymanager/All#SparkFun-LIS3DH
#include <Wire.h>
LIS3DH SensorTwo(I2C_MODE, 0x18);
void lis3dh_read_data()
{
// read the sensor value
uint8_t cnt = 0;
Serial.print(" X(g) = ");
Serial.println(SensorTwo.readFloatAccelX(), 4);
Serial.print(" Y(g) = ");
Serial.println(SensorTwo.readFloatAccelY(), 4);
Serial.print(" Z(g)= ");
Serial.println(SensorTwo.readFloatAccelZ(), 4);
}
void setup()
{
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
if (SensorTwo.begin() != 0)
{
Serial.println("Problem starting the sensor at 0x18.");
}
else
{
Serial.println("Sensor at 0x18 started.");
// Set low power mode
uint8_t data_to_write = 0;
SensorTwo.readRegister(&data_to_write, LIS3DH_CTRL_REG1);
data_to_write |= 0x08;
SensorTwo.writeRegister(LIS3DH_CTRL_REG1, data_to_write);
delay(100);
data_to_write = 0;
SensorTwo.readRegister(&data_to_write, 0x1E);
data_to_write |= 0x90;
SensorTwo.writeRegister(0x1E, data_to_write);
delay(100);
}
Serial.println("enter !");
}
void loop()
{
lis3dh_read_data();
delay(1000);
}
If the example sketch does not compile, use the latest code from the RAK1904 WisBlock Example Code Repository. The repository example supports all compatible WisBlock Core modules.
- Once the example code is open, install the SparkFun LIS3DH library by clicking the yellow-highlighted link.
Figure 1: Installing the compatible library for RAK1904 Module
Figure 1: Accessing the library used for RAK1904 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 RAK1904 example code- When you 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 RAK1904 is properly communicating to the WisBlock core.
Figure 1: RAK1904 acceleration sensor data logsResources
For a GPS tracking application based on the RAK4630, refer to the GPS Tracker Sample Code.
