BME280 Field Notes: Taking sensor on a bike ride

RPi Zero with battery pack (left), BME280 sensor (right)

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.

GPX formatted output showing latitude, longitude and elevation

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": "",
"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.

Correlation of BME280 data with GPX data from Strava

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

Scatter plot of BME280 data against GPX data from Strava


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…




Software engineer and entrepreneur currently building Kubernetes infrastructure and cloud native stack for edge/IoT and ML workflows.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How do FDA uses statistics to approve covid vaccines to the world?

Reaching for the Sky at our latest recommender systems meetup

Used Car data set: From crunching to predictions.

Real-Life Machine Learning: Deal With Missing Values in Raw Data

Do people still support Trump ?

Drive Bubble — The Daily PPILL #93

How to Learn Machine Learning & Data Science in 2020

Data Reveals: What Makes a Ted Talk Popular?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Saurabh Deoras

Saurabh Deoras

Software engineer and entrepreneur currently building Kubernetes infrastructure and cloud native stack for edge/IoT and ML workflows.

More from Medium

How to Create Dynamic Libraries in C

Creating and Using Dynamic Libraries in C


Are you writing your commit messages in the best way?