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 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
import board
import bmp581
i2c = board.I2C()
bmp = bmp581.BMP581(i2c)
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
import board
import bmp581
i2c = board.I2C() # uses board.SCL and board.SDA
bmp = bmp581.BMP581(i2c)
while True:
print(f"Temperature {bmp.temperature:.2f}°C")
print()
time.sleep(1)
|
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
import board
import bmp581
i2c = board.I2C()
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
import board
import bmp581
i2c = board.I2C()
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 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
import board
import bmp581
i2c = board.I2C()
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):
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
20
21 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
import board
import bmp581
i2c = board.I2C()
bmp = bmp581.BMP581(i2c)
bmp.output_data_rate = bmp581.ODR240
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
|