RAK1902 WisBlock Barometer Pressure Sensor Module Quick Start Guide
Prerequisite
-
WisBlock Base, WisBlock Core, and RAK1902. For assembly instructions, refer to the RAK1902 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 RAK1902 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 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 RAK1902_Pressure_LPS22HB.ino
@author rakwireless.com
@brief Setup and read values from a lps22hb sensor
@version 0.1
@date 2020-12-28
@copyright Copyright (c) 2020
**/
#include <Wire.h>
#include <Adafruit_LPS2X.h>
#include <Adafruit_Sensor.h> // Click here to get the library: http://librarymanager/All#Adafruit_LPS2X
Adafruit_LPS22 g_lps22hb;
void setup(void) {
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("Adafruit LPS22 test!");
// Try to initialize!
if (!g_lps22hb.begin_I2C(0x5c))
{
Serial.println("Failed to find LPS22 chip");
while (1)
{
delay(10);
}
}
Serial.println("LPS22 Found!");
g_lps22hb.setDataRate(LPS22_RATE_10_HZ);
Serial.print("Data rate set to: ");
switch (g_lps22hb.getDataRate())
{
case LPS22_RATE_ONE_SHOT: Serial.println("One Shot / Power Down");
break;
case LPS22_RATE_1_HZ: Serial.println("1 Hz");
break;
case LPS22_RATE_10_HZ: Serial.println("10 Hz");
break;
case LPS22_RATE_25_HZ: Serial.println("25 Hz");
break;
case LPS22_RATE_50_HZ: Serial.println("50 Hz");
break;
}
}
void loop() {
sensors_event_t temp;
sensors_event_t pressure;
g_lps22hb.getEvent(&pressure, &temp);
Serial.print("Temperature: ");Serial.print(temp.temperature);Serial.println(" degrees C");
Serial.print("Pressure: ");Serial.print(pressure.pressure);Serial.println(" hPa");
Serial.println("");
delay(1000);
}
If the example sketch does not compile, use the latest code from the RAK1902 WisBlock Example Code Repository. The repository example supports all compatible WisBlock Core modules.
- Once the example code is open, install the Adafruit LPS2X library by clicking the yellow highlighted link.
Figure 1: Accessing the library used for RAK1902 Module
Figure 1: Installing the compatible library for RAK1902 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 RAK1902 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 RAK1902 is properly communicating to the WisBlock core.
Figure 1: RAK1902 pressure and temperature data logsResources
- For a weather monitoring application based on the RAK4630, refer to the Weather Monitoring Sample Code.
- For a complete weather monitoring solution using the RAK1902, refer to the LoRaWAN Weather Monitoring Kit.
