Single readings in forced mode
What this example shows
In FORCED mode the BMP585 takes one measurement when you ask for it, then goes back to sleep. That suits projects that need a reading only now and then. The script lowers the oversampling to 1x, bypasses the IIR filter, and then asks for one measurement per second.
Wire the breakout over I2C as in the Quick Start (SCL on pin 9, SDA on
pin 8, plus 3V3 and GND), or change the pins to match your board. The INT
pin is not needed: the script reads the interrupt status over I2C.
The example code
# FILE: bmp585-forcedModeCustomConfig.py
# AUTHOR: Soldered Electronics
# BRIEF: Configures oversampling/IIR filtering and takes single-shot readings
# in forced power mode with the BMP585 sensor over I2C. Forced mode
# triggers one measurement then returns the sensor to standby
# automatically, useful for low-power applications where you only
# need occasional readings.
# WORKS WITH: BMP585 Barometric Pressure Sensor breakout: www.solde.red/333189
# LAST UPDATED: 2026-09-18
from bmp585 import (
BMP585,
BMP5_OK,
BMP5_OVERSAMPLING_1X,
BMP5_ODR_50_HZ,
BMP5_IIR_FILTER_BYPASS,
BMP5_POWERMODE_FORCED,
BMP5_INT_ASSERTED_DRDY,
)
from machine import I2C, Pin
import time
# Change these to match how your board wires I2C
i2c = I2C(0, scl=Pin(9), sda=Pin(8))
sensor = BMP585(i2c)
if sensor.status != BMP5_OK:
raise Exception("Failed to initialize BMP585: " + sensor.status_string())
print("BMP585 connected!")
# Lower the oversampling from the driver's default since forced mode is
# typically used for infrequent, quick readings. ODR is ignored in forced
# mode, but still needs to be set to a valid value
sensor.set_osr_odr_config(BMP5_OVERSAMPLING_1X, BMP5_OVERSAMPLING_1X, BMP5_ODR_50_HZ)
# Bypass the IIR filter since forced mode readings aren't continuous enough
# for the filter to settle
sensor.set_iir_config(BMP5_IIR_FILTER_BYPASS, BMP5_IIR_FILTER_BYPASS)
# Trigger the first measurement
sensor.set_mode(BMP5_POWERMODE_FORCED)
while True:
# Wait for the measurement to be ready
interrupt_status = sensor.get_interrupt_status()
if interrupt_status is not None and interrupt_status & BMP5_INT_ASSERTED_DRDY:
if sensor.get_sensor_data() == BMP5_OK:
print(
"Pressure: {:.2f} Pa\tTemperature: {:.2f} degC".format(
sensor.data.pressure, sensor.data.temperature
)
)
else:
print("Failed to read sensor data:", sensor.status_string())
# Trigger the next measurement
sensor.set_mode(BMP5_POWERMODE_FORCED)
# Only take a reading once per second
time.sleep_ms(1000)
🔗Open the complete example
Examples/bmp585-forcedModeCustomConfig.py at commit 098c1e2
Expected result:
This output was taken with the unmodified example, I2C at the 400 kHz default,
on a Qwiic cable of about 10 cm. On longer cables or a busier bus, set
freq=100000 in I2C().
BMP585 connected!
Pressure: 101320.99 Pa Temperature: 23.45 degC
Pressure: 101325.02 Pa Temperature: 23.46 degC
Pressure: 101314.15 Pa Temperature: 23.45 degC
One line arrives about every second: the pressure in pascals and the temperature in °C, each with two decimals.
Functions used
BMP585(i2c=None, address=BMP5_I2C_ADDR_SEC)returns BMP585Creates the sensor object and starts the sensor: a soft reset, a chip ID and NVM check, then temperature oversampling 64x, pressure oversampling 4x, 50 Hz with pressure enabled, and NORMAL mode. It raises an exception when the sensor cannot be reached. Every other method stores its result in sensor.status instead of raising.
ReturnsThe sensor object.
Parameters
| Type | Name | Description |
|---|---|---|
I2C | i2c | A ready machine.I2C object. When left out, the module checks uname().sysname: on the esp32 and esp8266 ports, and on one Soldered board firmware it names, it uses I2C(0, scl=Pin(22), sda=Pin(21)); on any other port it raises Board not recognized, enter I2C pins manually. |
int | address | I2C address. BMP5_I2C_ADDR_SEC (0x47) by default; pass BMP5_I2C_ADDR_PRIM (0x46) when the ADDRESS jumper (JP3) is moved, after importing it with from bmp585 import BMP5_I2C_ADDR_PRIM. |
sensor.status_string()returns strDescribes the current sensor.status code, such as Communication failure.
ReturnsThe description, or an empty string when the status is BMP5_OK.
sensor.set_osr_odr_config(osr_t, osr_p, odr, press_en=True)returns NoneSets the oversampling for temperature and pressure, the output data rate, and whether pressure is measured at all. The result goes to sensor.status.
ReturnsNothing; check sensor.status.
Parameters
| Type | Name | Description |
|---|---|---|
int | osr_t | Temperature oversampling, one of the BMP5_OVERSAMPLING_* constants. |
int | osr_p | Pressure oversampling, one of the BMP5_OVERSAMPLING_* constants. |
int | odr | Output data rate, one of the BMP5_ODR_* constants. The example comment notes that forced mode ignores it, but it must still be a valid value. |
bool | press_en | True (the default) measures pressure and temperature, False temperature only. |
sensor.set_iir_config(iir_t, iir_p)returns NoneSets the IIR low-pass filter coefficient for temperature and for pressure data. The result goes to sensor.status.
ReturnsNothing; check sensor.status.
Parameters
| Type | Name | Description |
|---|---|---|
int | iir_t | Temperature filter, one of the BMP5_IIR_FILTER_* constants; BMP5_IIR_FILTER_BYPASS turns it off. |
int | iir_p | Pressure filter, the same choices. |
sensor.set_mode(mode)returns NoneSets the power mode. Setting BMP5_POWERMODE_FORCED starts one measurement; the sensor then returns to sleep, so set it again for the next one. The result goes to sensor.status.
ReturnsNothing; check sensor.status.
Parameters
| Type | Name | Description |
|---|---|---|
int | mode | BMP5_POWERMODE_STANDBY, BMP5_POWERMODE_NORMAL, BMP5_POWERMODE_FORCED, BMP5_POWERMODE_CONTINUOUS or BMP5_POWERMODE_DEEP_STANDBY. |
sensor.get_interrupt_status()returns int or NoneReads the sensor's interrupt status bits over I2C. Works whether or not the INT pin is wired.
ReturnsA bitmask of BMP5_INT_ASSERTED_* flags (BMP5_INT_ASSERTED_DRDY is data ready), or None on a bus error.
sensor.get_sensor_data()returns intReads a new measurement into sensor.data: sensor.data.pressure in Pa and sensor.data.temperature in °C.
ReturnsBMP5_OK (0) on success, an error code otherwise.
This example also uses
I2C and
Pin from
MicroPython's machine module and
time.sleep_ms(),
which are not part of the BMP585 library and come with MicroPython itself.
I2C(id, *, scl, sda, freq=400000, timeout=50000)returns I2CFrom machine. Creates the I2C bus object that is passed to BMP585(). Which bus IDs and pins are allowed depends on your board.
ReturnsThe I2C bus object.
Parameters
| Type | Name | Description |
|---|---|---|
int | id | The I2C peripheral. The example uses 0. |
Pin | scl | The pin used for SCL. The example uses Pin(9). |
Pin | sda | The pin used for SDA. The example uses Pin(8). |
int | freq | Maximum SCL frequency in Hz, 400000 by default. The example leaves it out, so the bus is set to 400 kHz. On longer cables or a busier bus, pass freq=100000. |
int | timeout | Longest time allowed for an I2C transaction, in microseconds; 50000 by default. Some ports do not accept it. The example leaves it out. |
Pin(id, mode=-1, pull=-1, *, value=None, drive=0, alt=-1)returns PinFrom machine. Gives access to one GPIO pin. The example uses it to name the I2C pins. Settings you leave out keep their previous state.
ReturnsThe pin object.
Parameters
| Type | Name | Description |
|---|---|---|
int | id | The pin number. Which numbers are allowed depends on your board. The example uses 9 and 8. |
int | mode, pull, value, drive, alt | Pin mode, pull resistor, output value, drive strength and alternate function; not used by the example. |
time.sleep_ms(ms)returns NoneFrom time. Waits at least the given number of milliseconds; it can take longer when interrupt handlers or other work must run.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
int | ms | How long to wait, 0 or more. The example waits 1000 ms after each reading. |
Putting it together
The constructor leaves the sensor in NORMAL mode with 64x and 4x oversampling.
The script then switches to 1x oversampling with the filter bypassed and starts
the first forced measurement. Each pass of the loop polls
get_interrupt_status(). When the data-ready bit is set, it reads and prints
the result, starts the next forced measurement with set_mode(), and waits one
second.