BMP280 - Read temperature, pressure, and more from Bosch sensors

BMP280 is a new library for communicating with Bosch temperature, pressure, and humidity sensors. These sensors are fairly easy to buy and can be found on boards that connect to Raspberry Pis, BeagleBones and similar devices without soldering.

What makes these sensors cool is that the pressure sensor is very sensitive and can detect changes of 12.5 cm (per the datasheet). It sometimes feels better than that in practice, but that’s the official number.

The problem with using the BMP280 and BME280 sensors is that the computation for converting raw measurements into usable numbers is very tedious. This library saves you that pain.

Here’s an example:

iex> {:ok, bmp} = BMP280.start_link(bus_name: "i2c-1", bus_address: 0x77)
{:ok, #PID<0.29929.0>}

iex> BMP280.read(bmp)
{:ok,
 %BMP280.Measurement{
   altitude_m: 46.60861034844783,
   humidity_rh: 50.190531261362295,
   pressure_pa: 100766.41878837062,
   temperature_c: 17.373406414553756
 }}

This was captured using a BME280 sensor so it includes a relative humidity measurement.

Altitude is computed based on the current sea level pressure at your location. The library has to be told this to give accurate altitude estimates since this varies with the weather. If you’re only interested in change in altitude, though, you can skip this step.

8 Likes

awesome!

an unrelated caveat is the confusion between the sensors, when you go and buy some, you’ll often receive the lesser bmP - even if you ordered bmE, so watch out for that…

bmE is the better one which has humidity as well…

1 Like