Getting started with the Sensorian API – Part 2

Home / HowTo / Getting started with the Sensorian API – Part 2

In this post we will look at the temperature sensor. Specifically on how to calibrate it.  The MPL3115A2 is a multifunction sensor which provides data reading for altitude, barometric pressure and temperature.
The sensor is very accurate and very sensitive. This however can be a bit of an issue in itself. The sensor is mounted on the top corner of the Sensorian shield in order to avoid the thermal heat radiated by the microprocessor core. Tests with different Raspberry Pi have revealed that the first generation raspberry Pi is the most thermally inefficient design. Compared to the latest revisions the old design uses a LDO regulator for a power supply. Even though the heat is partially shielded from the PCB there exists a small thermal gradient which shows up in measurements. This varies from 1-3 degrees Celsius with the new Raspberry Pi which to as much as 9 degrees with the old raspberry Pi models. The tests assume that the board is left running for long periods of time until a steady state temperature is achieved.

Calibrating the Temperature Sensor.

Calibrating the Temperature Sensor.

The sensor can be calibrated by adding or removing a temperature offset via its internal registers. This allows for quite accurate calibration in practice. In practice the user can acquire a temperature sample during the transient phase and use that as an offset for further data acquisitions. To calibrate the sensor the temperature reading during startup is saved and used as an input to the offset function shown below .

temp = MPL3115A2_ReadTemperature();//Take a new temperature reading
printf("Temperature 2 : %0.2f degree Celsius.\r\n", temp);

In the code above, found on the Drivers/MPL3115A2/Example3 directory on the Github page the user can add or remove a specific a temperature value by calling the function in order to offset the discrepancy with the room temperature.
This sums up the calibration technique for the temperature sensor. Until next time.


Related Posts
Showing 4 comments
  • pasamonte

    I don’t fully understand how calibration can be done. I can’t find exactly where to use this code in the example cited (assuming that it is example 1, not example 3).
    My sensor is giving between 2 and 3 degrees more than a regular thermometer in the same location. I’d really like to be able to calibrate it.
    Can you explain further?

    Thanks in advance…

  • sensorian

    As shown , you can use the MPL3115A2_SetTempOffset() function to add the offset. There is an example in the firmware drivers directory on Github.

  • pasamonte

    Can you please point me to the place where it is. This is what I find and there’s no offset function:

    Also, the calibration is not implemented into the example:

    That’s what motivated my first comment/request for help.

    • sensorian

      The code example shown on the article uses the C API. You can easily port the function over to Python by using the read, write i2c functions.

Leave a Comment