Read pressure and temperature
What this example shows
The constructor starts the sensor in NORMAL mode: it measures on its own at 50 Hz and keeps the newest result ready. The script fetches that result ten times a second and prints pressure in pascals and temperature in °C.
The example opens I2C bus 0 with SCL on pin 9 and SDA on pin 8. Wire those
pins (plus 3V3 and GND), or change them to match your board. Leave the
ADDRESS jumper (JP3) at its default, 0x47.
The example code
# FILE: bmp585-basicReadings.py
# AUTHOR: Soldered Electronics
# BRIEF: Reads pressure and temperature from the BMP585 sensor over I2C
# WORKS WITH: BMP585 Barometric Pressure Sensor breakout: www.solde.red/333189
# LAST UPDATED: 2026-09-18
from bmp585 import BMP585, BMP5_OK
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!")
while True:
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())
time.sleep_ms(100)
🔗Open the complete example
Examples/bmp585-basicReadings.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: 101319.65 Pa Temperature: 23.42 degC
Pressure: 101317.75 Pa Temperature: 23.43 degC
Pressure: 101318.14 Pa Temperature: 23.43 degC
Pressure: 101315.54 Pa Temperature: 23.43 degC
A new line arrives every 100 ms: the pressure in pascals and the temperature in
°C, each with two decimals. A failed read prints Failed to read sensor data:
and the reason.
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 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.get_sensor_data()returns intReads a new measurement into sensor.data: sensor.data.pressure in Pa and sensor.data.temperature in °C. Pressure is 0.0 when pressure measurement is disabled.
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 100 ms between readings. |
Putting it together
BMP585(i2c) does all the setup, so the script only checks sensor.status
once before the loop. Inside the loop, every successful get_sensor_data()
refreshes sensor.data, and the script prints both values with two decimals.