Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe BMP280 sits on the Pi's I2C bus and gives temperature and air pressure. The Python script stores the last few hours of pressure readings and tells you whether pressure is rising, steady or falling, the simplest hint at weather change. A Flask page shows the current values and the trend. This is a hobby indicator, not a forecast: falling pressure only suggests that weather may turn unsettled.
Tick anything you already have and the total updates.
microSD card for the operating system
Pressure and temperature sensor
Follow the colours: red is power, dark grey is ground, blue is a signal.
Official Pi 4 power supply.
weather.pyimport time, threading
from collections import deque
import board, busio, adafruit_bmp280
from flask import Flask, jsonify
i2c = busio.I2C(board.SCL, board.SDA)
bmp = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76) # use 0x77 if needed
history = deque(maxlen=36) # one reading every 10 minutes = 6 hours
app = Flask(__name__)
def logger():
while True:
history.append(bmp.pressure)
time.sleep(600)
threading.Thread(target=logger, daemon=True).start()
def trend():
if len(history) < 7:
return "collecting data"
diff = history[-1] - history[-7] # change over about an hour
if diff > 1.0:
return "rising"
if diff < -1.0:
return "falling"
return "steady"
PAGE = '''<meta name="viewport" content="width=device-width"><meta http-equiv="refresh" content="30">
<h1>Weather</h1><div id="v"></div>
<script>fetch('/data').then(r => r.json()).then(d => {
document.getElementById('v').innerHTML = '<h2>' + d.t.toFixed(1) + ' C</h2><h2>' + d.p.toFixed(1) + ' hPa</h2><h3>Pressure ' + d.trend + '</h3>';
});</script>'''
@app.route("/")
def index():
return PAGE
@app.route("/data")
def data():
return jsonify(t=bmp.temperature, p=bmp.pressure, trend=trend())
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
I2C is not enabled or the SDA and SCL wires are swapped.
Change the address between 0x76 and 0x77.
The Pi warms the air around the sensor. Mount it on a short cable away from the board.
No. Use a BME280 for that, or add a DHT22 as in the other Flask dashboard.
A drop of several hectopascals over a few hours often comes before wind or rain.
No, history lives in memory. Write it to a file if you want to keep it.
6 parts: Raspberry Pi 4 Model B 2GB RAM Single Board Computer, Official Raspberry Pi 4 USB-C Power Supply – 15.3W, Official Raspberry Pi 32GB A2 Class Micro SD Card, BMP280-5V Temperature and Barometric Pressure Sensor Module, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 1.5 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (weather.py).
About ₹8,551 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Enabling I2C on the Pi; Reading a BMP280 with the Adafruit library; Showing a pressure trend.
Ideas that reuse this build: Raspberry Pi DHT22 Flask dashboard. They are listed under Take it further on this page.
Your first MicroPython project: temperature and humidity on an OLED.
A web page with ON and OFF buttons that switches a relay over Wi-Fi.
A warm ring light that fades up at dusk and down at dawn.
Turn a Pi and a touchscreen into a home command centre with a clock and to-do list.
Learning project. Check every circuit and the datasheet of each part before you power it up.