Barometric Pressure and Temperature Readings with the BMP280
Table of contents
- Overview
- Install the BMP280 Library
- Run the
bmp280_sensortest.ino
sketch from the Adafruit library - Run the
bmp280test.ino
sketch from the Adafruit library
Overview
This web page demonstrates how to retrieve the barometric pressure and temperature readings from the BMP280 sensor mounted on the Feather nRF52840 Sense. Because the BMP280 sensor is mounted directly on the Feather nRF52840 the temperature reading is strongly influenced by the temperature of the board. The barometric pressure is not directly affected by proximity to the board.
Adafruit provides a software library and instructions with examples for using the BMP280 sensor. Note that the Adafruit documentation is for a BMP280 on a breakout board. Just use the instructions for I2C communication, which work because the on-board BMP280 is connected to the nRF52840 via I2C. The full capabilities of the BMP280 are described in the datasheet on the Adafruit website.
Install the BMP280 Library
To write Arduino sketches that use the BMP280, you first need to install the Adafruit BMP280 Library. The following steps use the Arduino Library Manager and assume that you have properly configured the board support page.
From menu at the top of the Arduino IDE, select Sketch –> Include Library –> Manage Libraries…
- Enter “bmp280” in the search box to narrow the range of choices. Or, if you prefer, scroll through the entire list of libraries
- Choose the “Adafruit BMP280 Library” panel
- Click Install
Run the bmp280_sensortest.ino
sketch from the Adafruit library
After installing the library you should test the sensor with the sample sketch provided by Adafruit. In the Arduino IDE, select File –> Examples –> Adafruit BMP280 Library –> bmp280_sensortest, which will open up the bmp280_sensortest
sketch.
Running the bmp280_sensortest
sketch produces output similar to the following in the Serial Monitor. The barometric pressure and temperature will depend on the ambient conditions where you are when you run the sketch.
BMP280 Sensor event test
------------------------------------
Sensor: BMP280
Type: Ambient Temp (C)
Driver Ver: 1
Unique ID: 280
Min Value: -40.00
Max Value: 85.00
Resolution: 0.01
------------------------------------
Temperature = 19.31 *C
Pressure = 1021.25 hPa
Temperature = 19.50 *C
Pressure = 1021.23 hPa
...
Run the bmp280test.ino
sketch from the Adafruit library
In addition to bmp280_sensor
test, the Adafruit Library has a bmp280test
sketch which includes a calculation to estimate altitude. In the Arduino IDE, select File –> Examples –> Adafruit BMP280 Library –> bmp280test, which will open up the bmp280test
sketch.
Running the bmp280test
sketch produces output similar to the following in the Serial Monitor. The barometric pressure and temperature will depend on the ambient conditions where you are when you run the sketch.
BMP280 test
Temperature = 19.47 *C
Pressure = 102123.95 Pa
Approx altitude = -66.31 m
Temperature = 19.47 *C
Pressure = 102123.80 Pa
Approx altitude = -66.29 m
Temperature = 19.48 *C
Pressure = 102123.55 Pa
Approx altitude = -66.27 m
...
Note that the Approx alititude
is negative! But the measurements are not taken below sea level.
The correct calculation of altitude requires a value of the barometric pressure corresponding to sea level a the local weather conditions. You will need to consult a local weather station that provides that data. Otherwise, if you know your current altitude and the current barometric pressure, you could compute the effective barometric pressure at sea level with the seaLevelForAltitude
method in the Adafruit Library.