C
This code base on language C have the propose to get information about this sensor and display it.
First part that we need to write on our code is the libraries that we are going to use. In this case we are going to use
XdkSensorHandle.h
/************************************************************
* EnvironmentalSensor.c
************************************************************/
/* system header files */
#include "stdio.h"
/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"
#include "XdkSensorHandle.h"
/* own header files */A storage struct data need to be declared. The data is then read by the sensor by the Environmental_readData() function and then stored in a passed reference of the storage struct.
The temperature, humidity and pressure measurements can also be read from the environmental sensor separately, if the only one or two of them are needed.
*Snipped/ not part of the code/
Temperature Reading
Pressure Reading
Humidity Reading
*Continue
Then we declared the function to initialized the sensor and variable. We need to use the function of Environmental_init(xdkEnvironmental_BME280_Handle);
Finally we declared the main part of the program where we need to call all the function that we previously defined. Also define the timers.
Considerations
Compensating Temperature Data
Due to the fact that the environment sensor is attached to the board inside the XDK housing, it measures the temperature inside the housing. This leads to temperatures that deviate from the actual environment temperature, because the XDK’s housing temperature increased on runtime. This also affects the relative humidity, since it depends on the output of the environment sensor’s temperature sensor.
To get more usable temperature values, it is recommended to configure an offset that is applied to the temperature after reading. The following code snippet configures an offset of -5000 to compensate the temperature data by reducing it statically by 5 Kelvin.
If temperature has to be added instead, then the offset has to be configured as a positive integer.
Now that the offset is configured, data can be compensated as follows:
This way, the original data can be stored in another variable if neccessary, before it is compensated. Note that the function for compensation requires the entire BME Data struct, as the relative humidity will be adjusted as well.
The following code will immediately return the compensated data:
Last updated
Was this helpful?