|
| 1 | +# FILE: bmp388-normalModeWithFifo.py |
| 2 | +# AUTHOR: Josip Šimun Kuči @ Soldered |
| 3 | +# BRIEF: Normal mode example that collects multiple samples |
| 4 | +# WORKS WITH: Pressure & Temperature sensor BMP388 Breakout: www.solde.red/333316 |
| 5 | +# LAST UPDATED: 2025-01-15 |
| 6 | + |
| 7 | +from machine import Pin, I2C |
| 8 | +from bmp388 import BMP388 |
| 9 | +from bmp388_constants import TIME_STANDBY_1280MS, FIFO_DATA_READY, FIFO_CONFIG_ERROR |
| 10 | +import time |
| 11 | + |
| 12 | +NO_OF_MEASUREMENTS = 10 |
| 13 | + |
| 14 | +# If you aren't using the Qwiic connector, manually enter your I2C pins |
| 15 | +# i2c = I2C(0, scl=Pin(22), sda=Pin(21)) |
| 16 | +# bmp388 = BMP388(i2c) |
| 17 | + |
| 18 | +# Initialize sensor over Qwiic |
| 19 | +bmp388 = BMP388() |
| 20 | + |
| 21 | +# Set sea level pressure for accurate altitude readings |
| 22 | +bmp388.setSeaLevelPressure(1025.0) |
| 23 | + |
| 24 | +# Set standby time to roughly 1.3 seconds |
| 25 | +bmp388.setTimeStandby(TIME_STANDBY_1280MS) |
| 26 | + |
| 27 | +# Enable FIFO and set watermark |
| 28 | +bmp388.enableFIFO() |
| 29 | +bmp388.setFIFONoOfMeasurements(NO_OF_MEASUREMENTS) |
| 30 | + |
| 31 | +# Start continuous measurement in normal mode |
| 32 | +bmp388.startNormalConversion() |
| 33 | + |
| 34 | +print("Please wait for 13 seconds...") |
| 35 | + |
| 36 | +while True: |
| 37 | + status, temperatures, pressures, altitudes, sensorTime = bmp388.getFIFOData() |
| 38 | + |
| 39 | + if status == FIFO_DATA_READY: |
| 40 | + for i in range(len(temperatures)): |
| 41 | + altitude = altitudes[i] if i < len(altitudes) else 0.0 |
| 42 | + print("{}: {:.2f}*C {:.2f}hPa {:.2f}m".format( |
| 43 | + i + 1, temperatures[i], pressures[i], altitude |
| 44 | + )) |
| 45 | + |
| 46 | + print("Sensor Time: {} ms".format(sensorTime)) |
| 47 | + print() |
| 48 | + print("Please wait for 13 seconds...") |
| 49 | + elif status == FIFO_CONFIG_ERROR: |
| 50 | + print("FIFO configuration error.") |
| 51 | + |
| 52 | + time.sleep(0.05) |
0 commit comments