Wemos and Barometric Pressure Shield example

In this article we look at a relatively new shield for the Wemos/Lolin products – this is a Barometric Pressure shield based on a HP303B. Here is some info about the sensor

The HP303B is a miniaturized Digital Barometric Air Pressure Sensor with a high accuracy and a low current consumption, capable of measuring both pressure and temperature.
The pressure sensor element is based on a capacitive sensing principle which guarantees high precision during temperature changes. The small package makes the HP303B ideal for mobile applications and wearable devices.

The internal signal processor converts the output from the pressure and temperature sensor elements to 24 bit results. Each unit is individually calibrated, the calibration coeicients calculated during this process are stored in the calibration registers. The coeicients are used in the application to convert the measurement results to high accuracy pressure and temperature values.

The result FIFO can store up to 32 measurement results, allowing for a reduced host processor polling rate. Sensor measurements and calibration coeicients are available through the serial I2C or SPI interface. The measurement status is indicated by status bits or interrupts on the SDO pin.

Features

• Operation range: Pressure: 300 –1200 hPa. Temperature: -40 – 85 °C.
• Pressure sensor precision: ± 0.005 hPa (or ±0.05 m) (high precision mode).
• Relative accuracy: ± 0.06 hPa (or ±0.5 m)
• Absolute accuracy: ± 1 hPa (or ±8 m)
• Temperature accuracy: ± 0.5°C.
• Pressure temperature sensitivity: 0.5Pa/K
• Measurement time: Typical: 27.6 ms for standard mode (16x). Minimum: 3.6 ms for low precision mode.
• Average current consumption: 1.7 µA for Pressure Measurement, 1.5uA for Temperature measurement @1Hz sampling rate, Standby: 0.5 µA.
• Supply voltage: VDDIO: 1.2 – 3.6 V, VDD: 1.7 – 3.6 V.
• Operating modes: Command (manual), Background (automatic), and Standby.
• Calibration: Individually calibrated with coeicients for measurement correction.
• FIFO: Stores up to 32 pressure or temperature measurements.
• Interface: I2C and SPI (both with optional interrupt)

This is the Wemos shield

Code

The example requires the https://github.com/wemos/LOLIN_HP303B_Library

This examples works OK

#include <LOLIN_HP303B.h>
 
// HP303B Opject
LOLIN_HP303B HP303BPressureSensor;
 
 
void setup()
{
  Serial.begin(115200);
  while (!Serial);
  HP303BPressureSensor.begin();
  Serial.println("Init complete!");
}
 
 
void loop()
{
  int32_t temperature;
  int32_t pressure;
  int16_t oversampling = 7;
  int16_t ret;
  Serial.println();
 
  ret = HP303BPressureSensor.measureTempOnce(temperature, oversampling);
 
  if (ret != 0)
  {
    //Something went wrong.
    //Look at the library code for more information about return codes
    Serial.print("FAIL! ret = ");
    Serial.println(ret);
  }
  else
  {
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" degrees of Celsius");
  }
 
  //Pressure measurement behaves like temperature measurement
  //ret = HP303BPressureSensor.measurePressureOnce(pressure);
  ret = HP303BPressureSensor.measurePressureOnce(pressure, oversampling);
  if (ret != 0)
  {
    //Something went wrong.
    //Look at the library code for more information about return codes
    Serial.print("FAIL! ret = ");
    Serial.println(ret);
  }
  else
  {
    Serial.print("Pressure: ");
    Serial.print(pressure);
    Serial.println(" Pascal");
  }
 
  //Wait some time
  delay(500);
}

 

Output

Open the serial monitor and you should see something like this

Temperature: 31 degrees of Celsius
Pressure: 100469 Pascal

Temperature: 31 degrees of Celsius
Pressure: 100471 Pascal

Temperature: 31 degrees of Celsius
Pressure: 100470 Pascal

Temperature: 31 degrees of Celsius
Pressure: 100470 Pascal

 

Links

https://cdn.sos.sk/productdata/59/18/835e5d50/hp303b.pdf

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*