RAK5010 Temperature, Humidity, GPS Battery Level Reading?

Issue: Using the demo (RAK5010.ino) has temperature and humidity data but it is far different from the actual readings.

Setup: It has been set up from the link:

Details:

  1. I have a temperature and humidity checker, and for example, if the readings are 22.6 ©, 72.7(F), 38% humidity - the RAK chip reads like this:

I tried to make it to the closest values possible matching to the thermometer by adding and subtracting numbers from the initial settings but it still gives me very shaky data. I am very new to Arduino and the programming industry so could you please explain how the data is gathered and how should I alter to get accurate readings?

  1. I would like to code the RAK chip to access features like sleep mode and notify the battery level, and how do I do that? Somehow I find it difficult to add this feature to Arduino.

Actually, there was an article about using RUI there were somethings like sleep mode but there is another document that mentions BG96 Quectel Manual AT commands. (Honestly, I do not have a strong concept of these things and I would like to learn more about it)

Thank you,

Hi,
The example is very primary. I advise install the sensors library to get data.
RAK5010 uses SHTC3, you can install this lib:

About the sleep mode, MCU runs freertos and can enter sleep automatically. But BG96 and others sensors, Arduino library not provide the function. So it is a difficult work.

Below is the new example:
#include <Wire.h>
#include <math.h>

//Pin define
#define bg96_W_DISABLE 29
#define bg96_RESET 28
#define bg96_PWRKEY 2
#define bg96_GPS_EN 39

#include “SparkFunLIS3DH.h” ////https://github.com/sparkfun/SparkFun_LIS3DH_Arduino_Library/blob/master/examples/MultiI2C/MultiI2C.ino
LIS3DH SensorOne( I2C_MODE, 0x19 );
#include “SparkFun_SHTC3.h” // Click here to get the library: http://librarymanager/All#SparkFun_SHTC3
SHTC3 mySHTC3;

#include <Arduino_LPS22HB.h> // Click here to get the library: http://librarymanager/All#Arduino_LPS22HB
#include <ClosedCube_OPT3001.h> // Click here to get the library: http://librarymanager/All#OPT3001
ClosedCube_OPT3001 opt3001;
#define OPT3001_ADDRESS 0x44

const int baudrate = 115200;
String bg96_rsp = “”;
String send_data = “”;

//bg96 power up
void bg96_init()
{
pinMode(19, OUTPUT);

 pinMode(bg96_RESET, OUTPUT);
 pinMode(bg96_PWRKEY, OUTPUT);
 pinMode(bg96_GPS_EN, OUTPUT);
 pinMode(bg96_W_DISABLE, OUTPUT);

 digitalWrite(bg96_RESET,0);
 digitalWrite(bg96_PWRKEY,1);
 digitalWrite(bg96_W_DISABLE,1);
 delay(2000);
 digitalWrite(bg96_PWRKEY,0);
 digitalWrite(bg96_GPS_EN,1);
 delay(2000);

}
//this function is suitable for most AT commands of bg96. e.g. bg96_at(“ATI”)
void bg96_at(char *at, uint16_t timeout)
{
Serial1.println(String(at));
String result = “”;
time_t t = millis();
while ((millis() - t) < timeout)
{
if (Serial1.available())
{
result = Serial1.readString();
}
}
Serial.println(result);
result = “”;
}

//sensor init
void sensor_init()
{
if( SensorOne.begin() != 0 )
{
Serial.printf("-----------LIS3DH Init Failed!-----------\n");
}
else
{
Serial.printf("\n-----------LIS3DH Init OK!-----------\n");
}
mySHTC3.begin();
if(mySHTC3.passIDcrc)
{
Serial.printf("\n-----------SHTC3 Init OK!-----------\n");
}
else
{
Serial.printf("-----------SHTC3 Init Failed!-----------\n");
}
/* LPS22HB init */
if (!BARO.begin()) {
//Serial.println(“Failed to initialize pressure sensor!”);
Serial.printf("-----------LPS22HB Init Failed!-----------\n");
}
else
{
Serial.printf("\n-----------LPS22HB Init OK!-----------\n");
}
opt3001.begin(OPT3001_ADDRESS);
configureSensor();
if(opt3001.readDeviceID() == 0x3001)
{
Serial.printf("\n-----------OPT3001 Init OK!-----------\n");
}
else
{
Serial.printf("-----------OPT3001 Init Failed!-----------\n");
}
}
void configureSensor() {
OPT3001_Config newConfig;

newConfig.RangeNumber = B1100;
newConfig.ConvertionTime = B0;
newConfig.Latch = B1;
newConfig.ModeOfConversionOperation = B11;

OPT3001_ErrorCode errorConfig = opt3001.writeConfig(newConfig);
if (errorConfig != NO_ERROR)
//printError(“OPT3001 configuration”, errorConfig);
Serial.printf("-----------OPT3001 Configuration Failed!-----------\n");
else
OPT3001_Config sensorConfig = opt3001.readConfig();
}

//
/*!
@brief The setup function runs once when reset the board
*/
/
/
void setup()
{
Serial.begin (baudrate);
while ( !Serial ) delay(10); // for nrf52840 with native usb
Serial.println(“Arduino on Rak5010”);
sensor_init();
Serial1.begin(baudrate);
delay(3000);
Serial1.println(“ATI”);
// Check if the modem is already awake
time_t timeout = millis();
bool moduleSleeps = true;
//BG96 init
while ((millis() - timeout) < 4000)
{
if (Serial1.available())
{
String result = Serial1.readString();
Serial.println(“Modem response after start:”);
Serial.println(result);
moduleSleeps = false;
}
}
if (moduleSleeps)
{
Serial.println(“bg96 power up!\n”);
bg96_init();
}
bg96_at(“ATI”,2000);
delay(2000);
bg96_at(“AT+QGPSCFG=“gpsnmeatype”,1”,5000);
delay(2000);
bg96_at(“AT+QGPS=1,1,1,1,1”,5000);
delay(2000);
}
//
/*!
@brief The loop function runs over and over again forever
*/
/
/
void loop()
{
update_data();
delay(1000);
}

void update_data()
{
mySHTC3.update();
float temp = mySHTC3.toDegC();
float hum = mySHTC3.toPercent();
float pres = BARO.readPressure();
OPT3001 result = opt3001.readResult();
send_data = “”;
send_data = “ACC(g):”+String(SensorOne.readFloatAccelX())+","+String(SensorOne.readFloatAccelY())+","+
String(SensorOne.readFloatAccelZ())+";"+“Tem:”+String(temp)+"C “+“Hum:”+String(hum)+”% "+“Pres:”+String(pres)+"KPa "+“Lig:”+String(result.lux)+“lux”;
Serial.println(send_data);
bg96_at(“AT+QGPSGNMEA=“GGA””,2000);
delay(2000);
}

1 Like

Thank you Nero for the reply. I will install the libraries and get back to you if I have more questions!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.