In this article we connect a HP303B Barometic shield to a LOLIN D32 Pro, using the new board you can connect them using a 4 pin cable
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)
Parts
Code
You need to install the https://github.com/wemos/LOLIN_HP303B_Library
One of the default examples with comments removed
[cpp]
#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);
}
[/cpp]
Output
Open the serial monitor and you should see something like this
Temperature: 24 degrees of Celsius
Pressure: 100473 Pascal
Temperature: 24 degrees of Celsius
Pressure: 100472 Pascal
Temperature: 26 degrees of Celsius
Pressure: 100487 Pascal
Temperature: 27 degrees of Celsius
Pressure: 100484 Pascal
Video
This shows the connection from the module to the shield