pi_weather.core.sensors.bmp390.handler module

Logic to handle and remotely-manage the BMP390 sensor

class pi_weather.core.sensors.bmp390.handler.BMP3XX[source]

Bases: object

BMP3XX base class

__init__()[source]

Class c-tor func

Return type:

None

begin()[source]

Function to initialize the sensor

Returns:

Initialization status (boolean := True indicates initialization succeed, False otherwise)

Return type:

bool

property get_pressure: float | int

Function to get pressure measurement value from register (working range := (300‒1250 hPa))

If the reference value is provided before, the absolute value of the current position pressure is calculated according to the calibrated sea level atmospheric pressure

Returns:

Pressure measurements (unit: Pa)

Return type:

float | int

property get_temperature: float | int

Function to get pressure measurement value from register (working range := (-40 ‒ +85 °C))

Returns:

Temperature measurements (unit: °C)

Return type:

float | int

property get_sensor_time: int

Function to get sensor time data

Returns:

Sensor time

Return type:

int

calibrated_absolute_difference(altitude)[source]

Function which takes the given current location altitude as the reference value to eliminate the absolute difference for subsequent pressure and altitude data

Parameters:

altitude (float) – Altitude in current position

Returns:

Boolean (True if the benchmark value is successful, False otherwise)

Return type:

bool

property get_altitude: float

Function to calculate and return the altitude based on the atmospheric pressure measured by the sensor

If the reference value is provided before, the absolute value of the current position pressure is calculated according to the calibrated sea level atmospheric pressure

(see formula: https://www.weather.gov/media/epz/wxcalc/pressureAltitude.pdf)

Returns:

Altitude (unit: m)

Return type:

float

set_power_mode(mode)[source]

Function to configure the measurement mode and power mode

  • SLEEP_MODE (Sleep mode): It will be in sleep mode by default after power-on reset. In this mode,no

    measurement is performed and power consumption is minimal. All registers are accessible for reading the chip ID and compensation coefficient.

  • FORCED_MODE (Forced mode): In this mode, the sensor will take a single measurement according to the selected

    measurement and filtering options. After the measurement is completed, the sensor will return to sleep mode, and the measurement result can be obtained in the register.

  • NORMAL_MODE (Normal mode): Continuously loop between the measurement period and the standby period.

    The output data rates are related to the ODR mode setting.

Parameters:

mode (int) – Measurement mode and power mode that need to be set

Returns:

Nothing

Return type:

None

enable_fifo(mode)[source]

Function to enable or disable FIFO

Parameters:

mode (bool) – Bool to enable or disable FIFO

Returns:

Nothing

Return type:

None

set_oversampling(press_osr_set, temp_osr_set)[source]

Function to set up the oversampling config for pressure + temperature measurements OSR stands for over-sampling register

There are 6 pressure oversampling modes:
  • BMP3XX_PRESS_OSR_SETTINGS[0], Pressure sampling×1, 16 bit / 2.64 Pa (Recommend temperature oversampling×1)

  • BMP3XX_PRESS_OSR_SETTINGS[1], Pressure sampling×2, 16 bit / 2.64 Pa (Recommend temperature oversampling×1)

  • BMP3XX_PRESS_OSR_SETTINGS[2], Pressure sampling×4, 18 bit / 0.66 Pa (Recommend temperature oversampling×1)

  • BMP3XX_PRESS_OSR_SETTINGS[3], Pressure sampling×8, 19 bit / 0.33 Pa (Recommend temperature oversampling×2)

  • BMP3XX_PRESS_OSR_SETTINGS[4], Pressure sampling×16, 20 bit / 0.17 Pa (Recommend temperature oversampling×2)

  • BMP3XX_PRESS_OSR_SETTINGS[5], Pressure sampling×32, 21 bit / 0.085 Pa (Recommend temperature oversampling×2)

There are 6 temperature oversampling modes:
  • BMP3XX_TEMP_OSR_SETTINGS[0], Temperature sampling×1, 16 bit / 0.0050 °C

  • BMP3XX_TEMP_OSR_SETTINGS[1], Temperature sampling×2, 16 bit / 0.0025 °C

  • BMP3XX_TEMP_OSR_SETTINGS[2], Temperature sampling×4, 18 bit / 0.0012 °C

  • BMP3XX_TEMP_OSR_SETTINGS[3], Temperature sampling×8, 19 bit / 0.0006 °C

  • BMP3XX_TEMP_OSR_SETTINGS[4], Temperature sampling×16, 20 bit / 0.0003 °C

  • BMP3XX_TEMP_OSR_SETTINGS[5], Temperature sampling×32, 21 bit / 0.00015 °C

Parameters:
  • press_osr_set (int) – Pressure oversampling mode to be set

  • temp_osr_set (int) – Temperature oversampling mode to be set

Returns:

Nothing

Return type:

None

filter_coefficient(iir_config_coef)[source]

Function to set IIR filter coefficient (IIR filtering)

Infinite impulse response (IIR)

The environmental pressure is subject to many short-term changes, caused e.g. by slamming of a door or window, or wind wing into the sensor. To suppress these disturbances in the output data without causing additional interface traffic and processor work load, the BMP390 features an internal IIR filter. It effectively reduces the bandwidth of the output signals.

Docs: https://en.wikipedia.org/wiki/Infinite_impulse_response

Configurable mode:

BMP3XX_IIR_CONFIG_COEF_0, BMP3XX_IIR_CONFIG_COEF_1, BMP3XX_IIR_CONFIG_COEF_3, BMP3XX_IIR_CONFIG_COEF_7, BMP3XX_IIR_CONFIG_COEF_15, BMP3XX_IIR_CONFIG_COEF_31, BMP3XX_IIR_CONFIG_COEF_63, BMP3XX_IIR_CONFIG_COEF_127

Parameters:

iir_config_coef (int) – IIR filter coefficient (IIR filtering)

Returns:

Nothing

Return type:

None

set_output_data_rates(odr_set)[source]

Function to set output data rate

Here are the available modes:

BMP3XX_ODR_200_HZ, BMP3XX_ODR_100_HZ, BMP3XX_ODR_50_HZ, BMP3XX_ODR_25_HZ, BMP3XX_ODR_12P5_HZ, BMP3XX_ODR_6P25_HZ, BMP3XX_ODR_3P1_HZ, BMP3XX_ODR_1P5_HZ, BMP3XX_ODR_0P78_HZ, BMP3XX_ODR_0P39_HZ, BMP3XX_ODR_0P2_HZ, BMP3XX_ODR_0P1_HZ, BMP3XX_ODR_0P05_HZ, BMP3XX_ODR_0P02_HZ, BMP3XX_ODR_0P01_HZ, BMP3XX_ODR_0P006_HZ, BMP3XX_ODR_0P003_HZ, BMP3XX_ODR_0P0015_HZ

Parameters:

odr_set (int) – Output Data Rate (ODR) to be set

Returns:

True if config was successfully set, False otherwise (it remains at the original state)

Return type:

bool

set_common_sampling_mode(mode)[source]

Function to set the sampling mode to the sensor

There are 6 commonly used sampling modes:
  • ULTRA_LOW_PRECISION: Ultra-low precision, suitable for monitoring weather (lowest power consumption), the power is mandatory mode.

  • LOW_PRECISION: Low precision, suitable for random detection, power is normal mode

  • NORMAL_PRECISION1: Normal precision 1, suitable for dynamic detection on handheld devices (e.g. on mobile phones), power is normal mode

  • NORMAL_PRECISION2: Normal precision 2, suitable for drones, power is normal mode

  • HIGH_PRECISION: High precision, suitable for low-power handled devices (e.g. mobile phones), power is normal mode

  • ULTRA_PRECISION: Ultra-high precision, suitable for indoor navigation, its acquisition rate will be extremely low, and the acquisition cycle is 1000 ms.

Parameters:

mode (int) – Mode (integer)

Returns:

Status bool (True if config was set successfully, False otherwise)

Return type:

bool

enable_data_ready_interrupt()[source]

Function to enable the interrupt for the signal triggered when data is ready :return: Nothing

Return type:

None

enable_fifo_wtm_interrupt(wtm_value)[source]

Function to enable the interrupt for the water level signal

Parameters:

wtm_value (int) – Water level value of FIFO (value range := (0-511))

Returns:

Nothing

Return type:

None

enable_fifo_full_interrupt()[source]

Function to enable the interrupt of the signal that the sensor FIFO is full

As the interrupt pin is unique, the three interrupts are set to be used separately, please note the other two interrupt functions when using

Returns:

Nothing

Return type:

None

_get_coefficients()[source]

Function to get the calibration data in the NVM register of the sensor

Returns:

Nothing

Return type:

None

_compensate_data(adc_p, adc_t)[source]

Function to compensate the original values (pressure + temperature) from the measured data (directly from registers). It uses the calibration data (from registers data) retrieved at base class init.

# Docs on computation over calib. data := Datasheet, p28, Trimming Coefficient listing in register map with size and sign attributes

Parameters:
  • adc_p (float) – Measured pressure (:= direct register value) (unit: Pa)

  • adc_t (float) – Measured temperature (:= direct register value) (unit: °C)

Returns:

Tuple of calibrated pressure + temperature data

Return type:

Tuple[float, float]

_get_reg_temp_press_data()[source]

Function to get and return raw measurement data from the registers (uncompensated and calibrated pressure + temperature)

Returns:

Raw measurements data (pressure + temperature)

Return type:

Tuple[int, int]

_get_sensor_time()[source]

Function to get and return sensor time from registers

Returns:

Sensor time data

Return type:

int

get_fifo_temp_press_data()[source]

Function to get and return cached data from the FIFO (pressure + temperature)

Returns:

Calibrated pressure + temperature data

Return type:

Tuple[float, float]

get_fifo_length()[source]

Function to return the FIFO cached data size (range of return value is := (0-511))

Returns:

FIFO cached data size

Return type:

int

empty_fifo()[source]

Function to clear cached data in the FIFO without changing its settings

Returns:

Nothing

Return type:

None

reset()[source]

Function to reset and restart the sensor, then restoring the sensor configuration to the default configuration

Returns:

Nothing

Return type:

None

_write_reg(reg, data)[source]

Function to write data to a register

Parameters:
  • reg (int) – Reg address

  • data (int | Sequence[int]) – Data to write in the register

Returns:

Nothing

Return type:

None

_read_reg(reg, length)[source]

Function to read data from a register

Parameters:
  • reg (int) – Reg address

  • length (int) – Data length to read

Returns:

Read data list

Return type:

List[int]

class pi_weather.core.sensors.bmp390.handler.BMP3XXI2C(i2c_addr=119, bus=1)[source]

Bases: BMP3XX

BMP3XXI2C class Use the I2C protocol to drive the pressure sensor

Parameters:
__init__(i2c_addr=119, bus=1)[source]

C-tor init function for BMP3XXI2C

Parameters:
  • i2c_addr (int) – I2C device communication address

  • bus (int) – I2C bus number

_write_reg(reg, data)[source]

Function to write data to a register

Parameters:
  • reg (int) – Reg address

  • data (int | Sequence[int]) – Data to write in the register

Returns:

Nothing

Return type:

None

_read_reg(reg, length)[source]

Function to read data from a register

Parameters:
  • reg (int) – Reg address

  • length (int) – Data length to read

Returns:

Read data list

Return type:

List[int]