Microbaroms - Fun with a BME280 - From old forum.

Place your projects here
Post Reply
AndyGadget
Posts: 63
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 24 times
Been thanked: 54 times

Microbaroms - Fun with a BME280 - From old forum.

Post by AndyGadget »

Not a full project; just a diversion from a garden / greenhouse monitor I'm making as I had a BME280 to hand.
Just 4 wires to connect to an ESP32 or ESP8266 and a couple of hours fiddling around with it :-)

When I was logging the BME280 pressure output, I was seeing what looked like cyclic variations in the readings so decided to investigate further.
The program below takes a short and a long moving average of rapidly sampled data and displays the difference on an IL9341 LCD. This allows the enormous overall atmospheric pressure offset to be cancelled and plots a graph of the small variations. Just to make sure I wasn't seeing some effect of the sensor itself I've had 2 of these running side by side and the waveshapes are the same.
As an idea of the magnitude of the values, moving the device by about 6 foot (2m) vertically will give a full screen deflection.

Googling around a bit I learned that pressure fluctuations at the earth’s surface are caused by a variety of atmospheric phenomena. Examples include low frequency barometric pressure variations, high frequency atmospheric turbulence, atmospheric gravity waves, and quasi-static pressure fields created as wind blows over or around topographic features, like buildings, hills, wind breaks, etc

There is also a phenomena called microbaroms, which are caused by interaction of ocean waves with the atmosphere which are lower amplitude and may only show up as a slight variation on the display.

The program allows you to alter the long and short average periods and the sample rate which will emphasise different frequencies in the pressure variation.

Code: [Local Link Removed for Guests]

' Initialise I2C bus and display.
I2C.SETUP 17,16
TFT.INIT 1
TFT.BRIGHTNESS 255
if bme280.setup(&h76) = 0 then wlog "BME280 error"

' Play with these values
Pd1 = 40      ' Short moving average
Pd2 = 400     ' Long moving average
Mult = 1500   ' Screen scaling
Dly = 40      ' Controls sample rate (don't go below 25)

'Initialise MAs to start display at mid line.
P = bme280.qfe  
Av1 = P
Av2 = P

do
  tft.fill 0 
  for x = 0 to 319   
    P = bme280.qfe      
    Av1 = ((Av1 * (Pd1-1)) + P)/Pd1 ' Update short MA'
    Av2 = ((Av2 * (Pd2-1)) + P)/Pd2 ' Update long MA.
    y = (Av2 - Av1) * Mult          ' Take difference between MAs
    tft.line x,120,x,120+y,&HF800   ' and plot the value.
    tft.circle x,120+y,1,yellow
    pause Dly
  next x
loop
User avatar
Fernando Perez
Posts: 106
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 55 times
Been thanked: 54 times

Re: Microbaroms - Fun with a BME280 - From old forum.

Post by Fernando Perez »

You did it: I just ordered a couple of BME280s. :D
Post Reply