Skip to content

About

MicroPython Driver for the Bosch BMP585, BMP581, BMP390, BMP280, and BME280 pressure sensors

Resources

Stars

8 stars

Watchers

2 watching

Forks

Latest commit

 

History

276 Commits

Folders and files

Repository files navigation

Micropython BMPxxx - BMP585, BMP581, BMP390, BMP280, and BME280 driver

MicroPython Driver for the Bosch BMP585, BMP581, BMP390, BMP280 and BME280 pressure sensors using I2C interface. One can set the sensor's altitude to a known elevation for accurate altitude tracking or adjust sea level pressure to account for the weather. Tested on Raspberry Pi Pico2 and Pico2. In 2026, support for Pi Zero running Debian was added. To find other MicroPython drivers see: https://awesome-micropython.com/

This code also includes an example of using this driver with a Pi Zero 2 W running Debian Linux.

IC2 Driver For Bosch Pressure Sensors

Hardware & Platform Support

  • Microcontrollers: Raspberry Pi Pico and Pico 2.
  • Single-Board Computers: Raspberry Pi Zero (Debian Linux) supported via the accompanying pi_zero_i2c_bridge_utils.py utility module.
  • Bus Interface: I2C communication (TODO: SPI support ?).
  • I2C address fallback: Checking the primary I2C address and falling back to the secondary address if necessary.
  • High Frequency Updates: up to 240 Hz updates (4.16667ms period.

Supported Sensors & Specialized Metrics

  • Sensor Supported: BMP585, BMP581, BMP390, BMP280, and BME280.
  • BME280-Specific: Dedicated humidity tracking and dew point calculations using Sonntag’s 1990 formula (incorporating humidity, temperature, and pressure).
  • Standard Units:
  • Pressure reported in hPa.
  • Temperature reported in Celsius (°C).

Altitude & Atmospheric Calculations

  • Accurate Altitude Calculation: Altitude is computed using the high-precision NSF NCAR pressure altitude algorithm.
  • Calibration & Accuracy:
  • Uncalibrated measurements can drift by over 1,000 ft (500 m) due to weather changes.
  • The driver defaults to the international standard sea level pressure of 1013.25 hPa, but local weather can cause significant variance (990 hPa to 1040 hPa).
  • Supports setting a known local altitude and adjusting sea level pressure settings to match local meteorological data (e.g., a nearby airport weather station). Note: Local sea level pressure is the theoretical pressure at sea level, not the raw barometric pressure at your current sensor elevation.

Advanced Configuration & Reliability

  • Hardware Tuning: Configurable Oversampling (Pressure/Temperature) and IIR filter parameters.
  • Robust Error Handling: Comprehensive error checks integrated throughout the driver stack.

Buy the amazing but hard-to-find BMP585 sensor here: https://www.tindie.com/products/brad_aiperf/bmp585-high-accuracy-pressure-sensor-33v-board/ or you can get the $30 Bosch shuttle board and hack it as described below.

Getting Started - Installing

This driver has three required files: init.py, bmpxxx.py, and i2c_helpers.py. All three must be copied to the board (/ or /lib). We find it best to have them in a directory micropython_bmpxxx. Next, try some of the provided examples.

Sample Usage

Required Imports:

from machine import Pin, I2C
from micropython_bmpxxx import bmpxxx

If you have BMP581, define your machine.I2C object using I2C 1:

i2c = I2C(1, sda=Pin(2), scl=Pin(3))
bmp = bmpxxx.BMP581(i2c)

Below would be the code for using a BMP390, supported sensors are: BMP585, BMP581, BMP390, BMP280

i2c = I2C(1, sda=Pin(2), scl=Pin(3))
bmp = bmpxxx.BMP390(i2c)

Getting pressure, temperature, and altitude from the sensor:

press = bmp.pressure
temp = bmp.temperature

# altitude in meters is based on sea level pressure of 1013.25 hPA
meters = bmp.altitude
print(f"alt = {meters:.2f} meters")

To improve the accuracy of the Altitude, it is best to explicity set the set sea level pressure to a known sea level pressure in hPa at nearest airport, for exmaple: https://www.weather.gov/wrh/timeseries?site=KPDX:

bmp.sea_level_pressure = 1010.80
meters = bmp.altitude
print(f"alt = {meters:.2f} meters")

Increase BMP585/BMP581 sensor to highest resolution using oversampling. Each sensor has different allowable values:

# Highest resolution for BMP585 & BMP581, can also set IIR to smooth out noise
bmp.pressure_oversample_rate = bmp.OSR128
bmp.temperature_oversample_rate = bmp.OSR8
bmp.iir_coefficient = bmp.COEF_7

Below are the other settings you can adjust on the sensor, see data sheet for more info:

print("Current power mode setting: ", bmp.power_mode)
for power_mode in bmp.power_mode_values:
    bmp.power_mode = power_mode
    print(f"New Power mode setting: {bmp.power_mode}")

print(f"Current Output data rate setting: ", bmp.output_data_rate)
for output_data_rate in range(0, 32, 1):
    bmp.output_data_rate = output_data_rate
    print(f"New data rate setting: {bmp.output_data_rate}")

print("Current IIR setting: ", bmp.iir_coefficient)
for iir_coef in bmp.iir_coefficient_values:
    bmp.iir_coefficient = iir_coef
    print(f"New IRR setting: {bmp.iir_coefficient}")

I2C Addresses

If you only have one sensor on an I2C, use the default addresses. If you have multiple devices on the same I2C, it is a good practice to specify each sensor's address. To change the address to secondary you need to look look up the specs of your specific sensor. Often addresses can be changed with a solder blob or by connecting specific pins on the sensor to ground or Vcc. This driver will scan for both the primary and secondary addresses. It also checks the sensor's unique id to verify it is a BMP sensors.

Table 1: I2C Sensor Address

Sensor Default Secondary
BMP585 0x47 0x46
BMP581 0x47 0x46
BMP390 0x7f 0x7e
BMP280 0x77 0x76
BME280 0x77 0x76

The following code is useful when scanning for device addresses on I2C. I always put this in my code when bringing up new sensor. Also if device not found triple-check all wiring.

# Notice Below shows using i2c1 not i2c0 (i2c0 typically used for REPL connection to the host)
i2c = I2C(id=1, scl=Pin(27), sda=Pin(26))
i2c1_devices = i2c.scan()
if i2c1_devices:
    for d in i2c1_devices: print(f"i2c1 device at address: {hex(d)}")
else:
    print("ERROR: No i2c1 devices")

Example of specifying an address for a BMP581:

bmp = bmpxxx.BMP581(i2c=i2c, address=0x47)

Recommended Oversampling Rates to Improve Sensors' Accuracy

The table 2 below is Bosch's recommended oversampling pressure and temperature settings for BMP585 and BMP581. Higher sampling rates effect the refresh rate and the power consumption. Please checked the Bosch datasheets for more information https://www.bosch-sensortec.com/products/environmental-sensors/pressure-sensors/

Table 2: BMP585/BMP581 Recommendations from Bosch

Oversampling setting OSR Pressure Pressure
Oversampling
Temperature
Oversampling
IIR
Lowest Power 000 x1 x1 COEF_0
001 x2 x1 COEF_0
Standard resolution 010 x4 x1 COEF_3
011 x8 x1 COEF_3
High resolution 100 x16 x1 COEF_3
101 x32 x2 COEF_3
110 x64 x4 COEF_3
Highest resolution 111 x128 x8 COEF_7
# Highest recommended for combined pressure and temperature for BMP581 or BMP585 sensor
bmp.pressure_oversample_rate = bmp.OSR128
bmp.temperature_oversample_rate = bmp.OSR8
bmp.iir_coefficient = bmp.COEF_7

The BMP585 and BMP581 do not have recommended IIR filters to go with the table above.

The table 3 below is Bosch's recommended oversampling pressure and temperature settings for bmp390. There are recommended IIR filter settings for the bmp390 in section 3.5. Filter section, page 17, in bmp390 datasheet

Table 3: BMP390 Recommendations from Bosch

Oversampling setting OSR Pressure Pressure
Oversampling
Temperature
Oversampling
IIR Sample Use
Ultra low power 000 x1 x1 COEF_0 Weather monitoring
lowest power, IIR off
Low power 001 x2 x1 COEF_0 Drop detection, IIR off
Standard resolution 010 x4 x1 COEF_3 Handheld dynamic
High resolution 011 x8 x1 COEF_1 Drone,
low power
Ultra high resolution 100 x16 x2 COEF_3 Indoor navigation
# Highest recommended for combined pressure and temperature for bmp390 sensor
# below are recommended for Indoor Navigation on bmp390 (page 17 of bmp390 datasheet)
bmp.pressure_oversample_rate = bmp.OSR16
bmp.temperature_oversample_rate = bmp.OSR2
bmp.iir_coefficient = bmp.COEF_3

bmp.OSR1 corresponds to x1 for all sensors, bmp.OSR2 corresponds to x2 for all sensors, bmp.OSR4 corresponds to x4 for all sensors, etc. If you go over for a particular sensor, then an error message will show possible values.

Output Data rates (ODR)

The fastest sensor data can be output is 240 Hz (4.16667 msec). This is used as the default rate.

Table 4: Output Data Rate (ODR)

Output Data Rate (ODR) setting ODR Rate
ODR_240_HZ 240.000 Hz (Maximum hardware ODR)
ODR_219_HZ 218.537 Hz
ODR_200_HZ 199.111 Hz
ODR_160_HZ 160.000 Hz
ODR_120_HZ 120.000 Hz
ODR_100_HZ 100.299 Hz
ODR_80_HZ 80.000 Hz
ODR_50_HZ 50.056 Hz
ODR_20_HZ 20.000 Hz
ODR_10_HZ 10.000 Hz
ODR_5_HZ 5.000 Hz
ODR_1_HZ 1.000 Hz
ODR_0_125_HZ 0.125 Hz (Slowest hardware ODR)

Example using Pi Zero with Debian Linux

You can see an example code of using Pi Zero, or any Pi running Debian, in examples/bmp585_altitude_pi_zero.py This example includes a method called scan_i2c_bus which is included in this test code for Pi Zero. This should also work with Pi 4 and Pi 5, but this has not been tested.

To run this code, lib.pi_zero_i2c_bridge_utils.py must be in /lib folder.

Example projects using this Driver

Bosch Sensors Compared

  • Bosch BMP585, MEMS-based barometric pressure sensor, perf similar to BMP581, released 2023.
    • Liquid resistant due to gel sensor
    • The BMP585 accuracy similar to Bosch’s existing BMP581.
      • Measure change in height of just a few centimeters.
      • Relative accuracy of +/-0.06 hPa and typical absolute accuracy of +/-0.5 hPa.
  • The BMP581, capacitive-based barometric pressure sensor, released 2022.
    • The BMP581 accuracy similar to Bosch’s existing BMP585.
      • Measure change in height of just a few centimeters.
      • Relative accuracy of +/-0.06 hPa and typical absolute accuracy of +/-0.3 hPa.
    • the BMP581 vs. BMP390: draws 85% less current, noise is 80% lower, and temperature coefficient offset is reduced by 33%.
  • Bosch BMP390, previous generation, released 2021.
    • Relative accuracy of +/-0.03 hPa and typical absolute accuracy of +/-0.5 hPa.
    • Measure change in height of 0.25 meters.
  • Bosch BMP280, old generation, released 2015.
    • Relative accuracy of +/-0.12 hPa and typical absolute accuracy of +/-1.0 hPa.
    • Measure change in height of+/-1 meter.
  • Bosch BME280, old generation nearly same as bmp280 but also has humidity, released 2013.
    • Relative accuracy of +/-0.12 hPa and typical absolute accuracy of +/-1.0 hPa.
    • Measure change in height of+/-1 meter. Bosch video showing using BMP585 underwater (the Bosch shuttle board won't work underwater :) ):
  • https://www.youtube.com/watch?v=BaAhb2vaAQg

License Information

This software product is open source. Please review the LICENSE.md file for license information.

  • distributed as-is; no warranty is given.

Credits

Code based on great work by Jose & Scott!

  • micropython_bmp581 Author: Jose D. Montoya, jposada202020
    • github:jposada202020/MicroPython_bmp581
    • Corrected error in altitude calculation, also removed code that limits accuracy to 100 cm instead of allowing 1cm.
  • Also based on
    • adafruit_register.i2c_struct, adafruit_register.i2c_bits. Author: Scott Shawcroft

Todos

  • Open Question: IIR code for BMP585 & BMP581 uses the same IIR for pressure and temperature, this simplifies control and is like the bmp280 & bmp390 sensors, but this decision takes away flexibility for these newer sensors.
  • add SPI code

My custom BMP585 Board

I wanted a small BMP585 sensor board (I2C), so I designed my own. One can apply waterproofing to this board for underwater pressure sensing. It is only 16.1 mm * 12 mm. Getting the amazing but hard-to-find BMP585 sensor: https://www.tindie.com/products/brad_aiperf/bmp585-high-accuracy-pressure-sensor-33v-board/

BMP585 Board front - my design BMP585 Board back - my design

I found an error in online BMP585 documentation from other designers and I have changed R1 and R2 in the original design to zero-ohm resistors (was 1K ohm). While these resistors were OK when using with Pi Picos they did not work on Pi Zeros.

Using Bosch's BMP585 Shuttle Board

Bosch makes their own BMP585 Shuttle Board for prototype work, but to connect it to a Raspberry Pico with I2C it requires modifications. Here is a write-up on those modifications: hacked_bosch_shuttle_board.md

About

MicroPython Driver for the Bosch BMP585, BMP581, BMP390, BMP280, and BME280 pressure sensors

Resources

Stars

8 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages