Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Sensors/BMP388/BMP388/Examples/bmp388-allValues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# FILE: bmp388-allValues.py
# AUTHOR: Josip Šimun Kuči @ Soldered
# BRIEF: An example for the BMP388 sensor that reads temperature, pressure
# and calculates the altitude using the pressure measurement
# WORKS WITH: Pressure & Temperature sensor BMP388 Breakout: www.solde.red/333316
# LAST UPDATED: 2025-01-XX
from machine import Pin, I2C
from bmp388 import BMP388
import time

# If you aren't using the Qwiic connector, manually enter your I2C pins
# i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# bmp388 = BMP388(i2c)

# Initialize sensor over Qwiic
bmp388 = BMP388()

# Set sea level pressure for accurate altitude readings (adjust to your local value)
bmp388.setSeaLevelPressure(1013.25)

# Start continuous measurement in normal mode
bmp388.startNormalConversion()

# Wait a bit for the first measurement to be ready
# (depends on oversampling settings, give it extra time)
time.sleep(0.5)

# Infinite loop
while 1:
# Variables for storing measurement data (matching Arduino example)
temperature, pressure, altitude = bmp388.getMeasurements()

# Check if the data is ready (matching Arduino: if (bmp388.getMeasurements(...)))
if temperature is not None:
# Print the results (matching Arduino format)
print("{:.2f}*C {:.2f}hPa {:.2f}m".format(temperature, pressure, altitude))
# Note: Arduino example doesn't print "waiting" message, it just silently waits

# Wait a little bit (matching Arduino: delay(250))
time.sleep(0.25)
34 changes: 34 additions & 0 deletions Sensors/BMP388/BMP388/Examples/bmp388-forcedMeasurement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# FILE: bmp388-forcedMeasurement.py
# AUTHOR: Josip Šimun Kuči @ Soldered
# BRIEF: Forced measurement example for the BMP388
# WORKS WITH: Pressure & Temperature sensor BMP388 Breakout: www.solde.red/333316
# LAST UPDATED: 2025-01-15

from machine import Pin, I2C
from bmp388 import BMP388
import time

# If you aren't using the Qwiic connector, manually enter your I2C pins
# i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# bmp388 = BMP388(i2c)

# Initialize sensor over Qwiic
bmp388 = BMP388()

# Set sea level pressure for accurate altitude readings
bmp388.setSeaLevelPressure(1025.0)

while True:
# Request a new measurement
bmp388.startForcedConversion()

# Wait until data is ready
while True:
temperature, pressure, altitude = bmp388.getMeasurements()
if temperature is not None:
print("{:.2f}*C {:.2f}hPa {:.2f}m".format(temperature, pressure, altitude))
break
time.sleep(0.02)

# Wait a little bit before next measurement
time.sleep(1)
47 changes: 47 additions & 0 deletions Sensors/BMP388/BMP388/Examples/bmp388-forcedModeWithInterrupt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# FILE: bmp388-forcedModeWithInterrupt.py
# AUTHOR: Josip Šimun Kuči @ Soldered
# BRIEF: Forced mode example using data-ready polling
# WORKS WITH: Pressure & Temperature sensor BMP388 Breakout: www.solde.red/333316
# LAST UPDATED: 2025-01-15

from machine import Pin, I2C
from bmp388 import BMP388
import time

dataReady = False


def interruptHandler(pin):
global dataReady
dataReady = True

# If you aren't using the Qwiic connector, manually enter your I2C pins
# i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# bmp388 = BMP388(i2c)

# Initialize sensor over Qwiic
bmp388 = BMP388()

# Set sea level pressure for accurate altitude readings
bmp388.setSeaLevelPressure(1025.0)

# Enable data-ready interrupt
bmp388.enableInterrupt()

# Connect sensor INT pin to GPIO2 (adjust for your board)
intPin = Pin(2, Pin.IN, Pin.PULL_UP)
intPin.irq(trigger=Pin.IRQ_RISING, handler=interruptHandler)

while True:
# Request a new measurement
bmp388.startForcedConversion()

# Wait for interrupt flag
while not dataReady:
time.sleep(0.005)

temperature, pressure, altitude = bmp388.getMeasurements()
if temperature is not None:
print("{:.2f}*C {:.2f}hPa {:.2f}m".format(temperature, pressure, altitude))

dataReady = False
52 changes: 52 additions & 0 deletions Sensors/BMP388/BMP388/Examples/bmp388-normalModeWithFifo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# FILE: bmp388-normalModeWithFifo.py
# AUTHOR: Josip Šimun Kuči @ Soldered
# BRIEF: Normal mode example that collects multiple samples
# WORKS WITH: Pressure & Temperature sensor BMP388 Breakout: www.solde.red/333316
# LAST UPDATED: 2025-01-15

from machine import Pin, I2C
from bmp388 import BMP388
from bmp388_constants import TIME_STANDBY_1280MS, FIFO_DATA_READY, FIFO_CONFIG_ERROR
import time

NO_OF_MEASUREMENTS = 10

# If you aren't using the Qwiic connector, manually enter your I2C pins
# i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# bmp388 = BMP388(i2c)

# Initialize sensor over Qwiic
bmp388 = BMP388()

# Set sea level pressure for accurate altitude readings
bmp388.setSeaLevelPressure(1025.0)

# Set standby time to roughly 1.3 seconds
bmp388.setTimeStandby(TIME_STANDBY_1280MS)

# Enable FIFO and set watermark
bmp388.enableFIFO()
bmp388.setFIFONoOfMeasurements(NO_OF_MEASUREMENTS)

# Start continuous measurement in normal mode
bmp388.startNormalConversion()

print("Please wait for 13 seconds...")

while True:
status, temperatures, pressures, altitudes, sensorTime = bmp388.getFIFOData()

if status == FIFO_DATA_READY:
for i in range(len(temperatures)):
altitude = altitudes[i] if i < len(altitudes) else 0.0
print("{}: {:.2f}*C {:.2f}hPa {:.2f}m".format(
i + 1, temperatures[i], pressures[i], altitude
))

print("Sensor Time: {} ms".format(sensorTime))
print()
print("Please wait for 13 seconds...")
elif status == FIFO_CONFIG_ERROR:
print("FIFO configuration error.")

time.sleep(0.05)
48 changes: 48 additions & 0 deletions Sensors/BMP388/BMP388/Examples/bmp388-normalModeWithInterrupt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# FILE: bmp388-normalModeWithInterrupt.py
# AUTHOR: Josip Šimun Kuči @ Soldered
# BRIEF: Normal mode example using data-ready polling
# WORKS WITH: Pressure & Temperature sensor BMP388 Breakout: www.solde.red/333316
# LAST UPDATED: 2025-01-15

from machine import Pin, I2C
from bmp388 import BMP388
from bmp388_constants import TIME_STANDBY_1280MS
import time

dataReady = False


def interruptHandler(pin):
global dataReady
dataReady = True

# If you aren't using the Qwiic connector, manually enter your I2C pins
# i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# bmp388 = BMP388(i2c)

# Initialize sensor over Qwiic
bmp388 = BMP388()

# Set sea level pressure for accurate altitude readings
bmp388.setSeaLevelPressure(1025.0)

# Set standby time to roughly 1.3 seconds
bmp388.setTimeStandby(TIME_STANDBY_1280MS)

# Enable data-ready interrupt
bmp388.enableInterrupt()

# Connect sensor INT pin to GPIO2 (adjust for your board)
intPin = Pin(2, Pin.IN, Pin.PULL_UP)
intPin.irq(trigger=Pin.IRQ_RISING, handler=interruptHandler)

# Start continuous measurement in normal mode
bmp388.startNormalConversion()

while True:
if dataReady:
temperature, pressure, altitude = bmp388.getMeasurements()
if temperature is not None:
print("{:.2f}*C {:.2f}hPa {:.2f}m".format(temperature, pressure, altitude))
dataReady = False
time.sleep(0.01)
Loading
Loading