BME280 Field Notes: Taking sensor on a bike ride

BME280 sensor is a pressure, humidity and temperature sensor from Bosche and wonderfully packaged with I²C interface by Adafruit Industries, which makes it very easy to use with devices such as Raspberry Pi.
I have written about monitoring temperature and humidity in the past and this post is about evaluating its barometric pressure measurement capabilities. In particular, I took this sensor on a bike ride and correlated data captured using this sensor against what was reported by GPS sensing Strava app running on my phone. Let’s dig into details…
GPX Data from Strava
Strava is a very popular ride tracking app that can be used for a variety of activities such as running, biking, swimming etc. We can download the so-called GPX (GPS Extended) formatted data that was captured by the app. This file captures the GPS coordinates along with elevation and we will use it as a reference to evaluate how well BME280 senses barometric pressure changes.

As you can see GPX data is an XML formatted data, which we will parse later in a Go code to correlate against BME280 data.
BME280 Data
I wrote a simple Go code which leveraged open source drivers to capture data over I²C bus using an open source library. Eventually I am printed output as JSON strings in a logfile bme.json
.
└─ $ ▶ cat bme.json | head -n 1 | jq '.'
{
"level": "info",
"time": "2021-05-23T10:28:00.200-0700",
"name": "bme280.data",
"msg": "data",
"temperature": 19.82,
"pressure": 1010.69,
"humidity": 43.36,
"altitude": 21
}
Now these two data sets can be merged based on the timestamp and analyzed for correlation.
Data Analysis
I followed a very simple approach to merge the two data sets by first reading in BME280 data and building a hashmap (in Go) with timestamp (in seconds) as keys. I then iterated over GPX data entries and looked up corresponding timestamps in the hashmap with a tolerance of +/- 2 seconds. If a match was found, combined data was printed in a new CSV file.
Below is elevation profile over time as recorded by GPX and BME280. I was amazed to see a stunning correlation between these two data sets. The barometric pressure was converted to altitude and offset was removed from both data sets. In other words, BME280 measures the “change” in altitude very well but I have not yet figured out how to calibrate the offset for it.

And here is the scatter plot of the same data showing an excellent R² value:

Summary
I am impressed by the capabilities of BME280 sensor and plan to use it for several IoT projects. It integrates very well with Raspberry Pi (including RPi Zero) and there are excellent libraries for capturing data from it. Stay tuned for further updates on it as I tinker with it more…