Simple test
Ensure your device works with this simple test.
examples/bmp581_simpletest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
from machine import Pin, I2C
from micropython_bmp581 import bmp581
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bmp = bmp581.BMP581(i2c)
# Oddly first pressure measure after power-on return wrong value.
# so we "burn" one measure
_ = bmp.pressure
while True:
print(f"Pressure: {bmp.pressure:.2f}kPa")
print()
time.sleep(0.5)
|
Temperature test
Example showing how to get the temperature from the sensor
examples/bmp581_temperature.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
from machine import Pin, I2C
from micropython_bmp581 import bmp581
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bmp = bmp581.BMP581(i2c)
while True:
print(f"Temperature: {bmp.temperature:.2f}°C")
print()
time.sleep(0.5)
|
Pressure oversample rate settings
Example showing the Pressure oversample rate setting
examples/bmp581_pressure_oversample_rate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
from machine import Pin, I2C
from micropython_bmp581 import bmp581
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bmp = bmp581.BMP581(i2c)
bmp.pressure_oversample_rate = bmp581.OSR16
while True:
for pressure_oversample_rate in bmp581.pressure_oversample_rate_values:
print(
"Current Pressure oversample rate setting: ", bmp.pressure_oversample_rate
)
for _ in range(10):
print(f"Pressure: {bmp.pressure:.2f}kPa")
print()
time.sleep(0.5)
bmp.pressure_oversample_rate = pressure_oversample_rate
|
Power Mode settings
Example showing the Power Mode setting
examples/bmp581_power_mode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
from machine import Pin, I2C
from micropython_bmp581 import bmp581
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bmp = bmp581.BMP581(i2c)
bmp.power_mode = bmp581.NORMAL
while True:
for power_mode in bmp581.power_mode_values:
print("Current Power mode setting: ", bmp.power_mode)
for _ in range(10):
print(f"Pressure: {bmp.pressure:.2f}kPa")
print()
time.sleep(0.5)
bmp.power_mode = power_mode
|
Temperature oversample rate settings
Example showing the Temperature oversample rate setting
examples/bmp581_temperature_oversample_rate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
from machine import Pin, I2C
from micropython_bmp581 import bmp581
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bmp = bmp581.BMP581(i2c)
bmp.temperature_oversample_rate = bmp581.OSR4
while True:
for temperature_oversample_rate in bmp581.temperature_oversample_rate_values:
print(
"Current Temperature oversample rate setting: ",
bmp.temperature_oversample_rate,
)
for _ in range(10):
temp = bmp.temperature
print(f"Temperature: {bmp.temperature:.2f}°C")
print()
time.sleep(0.5)
bmp.temperature_oversample_rate = temperature_oversample_rate
|
Output data rate settings
Example showing the Output data rate setting
examples/bmp581_output_data_rate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
from machine import Pin, I2C
from micropython_bmp581 import bmp581
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bmp = bmp581.BMP581(i2c)
while True:
for output_data_rate in range(0, 32, 1):
print("Current Output data rate setting: ", bmp.output_data_rate)
for _ in range(10):
print(f"Pressure: {bmp.pressure:.2f}kPa")
print()
time.sleep(0.5)
bmp.output_data_rate = output_data_rate
|
Altitude example
Example showing the Output data rate setting
examples/bmp581_altitude.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
from machine import Pin, I2C
from micropython_bmp581 import bmp581
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bmp = bmp581.BMP581(i2c)
# Oddly first pressure measure after power-on return wrong value.
# so we "burn" one measure
_ = bmp.pressure
print(f"Pressure: {bmp.pressure:.2f}kPa")
print(f"Current altitude: {bmp.altitude:.1f}mts")
|