Projects / Raspberry Pi 5 terminal weather desk

Raspberry Pi 5 terminal weather desk

Beginner1.8 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. Pi 5

    Shut down

    Power off the Pi before wiring.

  2. Pi 5

    Wire the sensor

    VIN to pin 1, GND to pin 6, SDA to pin 3, SCL to pin 5.

  3. Pi 5

    Switch on I2C

    raspi-config, Interface Options, I2C, then reboot.

  4. Pi 5

    Check the address

    Run i2cdetect -y 1 and look for 76 or 77.

  5. Pi 5

    Install the packages

    In a virtual environment with pip.

  6. Pi 5

    Run the program

    A small weather panel appears and updates every five seconds.

  7. Pi 5

    Wait ten minutes

    The trend line moves on from collecting data.

In short

How do you build a raspberry Pi 5 terminal weather desk?

A Raspberry Pi 5 reads a BME280 over I2C and shows temperature, humidity and pressure in the terminal with a one-line pressure trend, for a quick desk weather display. You need Raspberry Pi 5 (8 GB), BME280 Environmental Sensor and Breadboard 830 Tie Points. It takes 7 steps and about 110 minutes.

Level
Beginner
Time
About 110 min
Parts
3

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
BME280 VINPi 5 3V3 pin 1Power at 3.3 V
BME280 GNDPi 5 GND pin 6Common ground
BME280 SDAPi 5 GPIO2 pin 3I2C data
BME280 SCLPi 5 GPIO3 pin 5I2C clock

Code

The BME280 measures temperature, humidity and air pressure and sends them over I2C. Each chip has its own correction numbers stored at the factory, and the library reads them once and uses them to turn the raw counts into real values. The Pi 5 has I2C on GPIO2 and GPIO3, which must be switched on in raspi-config, and the sensor sits at address 0x76 or 0x77 depending on the module, so the program tries both. Every five seconds it redraws a small panel in the terminal. Once a minute it keeps a pressure reading for the last three hours. The trend line compares the pressure now with the oldest reading kept and reports the change per hour. A steady rise often goes with settling, fine weather and a steady fall with wetter weather, but this is only a rough hint and not a forecast. Readings are indicative only. The board warms itself and the sensor, so keep the sensor on a short lead away from the Pi 5. Shut the Pi down before changing wires.

import time
from collections import deque

import smbus2
import bme280

bus = smbus2.SMBus(1)
ADDRESS = None
for candidate in (0x76, 0x77):                      # the usual two addresses of a BME280 module
    try:
        calibration = bme280.load_calibration_params(bus, candidate)
        ADDRESS = candidate
        break
    except OSError:
        pass
if ADDRESS is None:
    raise SystemExit("No BME280 found, check the wiring and that I2C is switched on")

history = deque(maxlen=180)                         # one reading a minute, three hours
last_save = 0.0

def trend(pressure_now):
    if not history:
        return "collecting data"
    then_time, then_pressure = history[0]
    hours = (time.time() - then_time) / 3600
    if hours < 0.17:                                # wait about ten minutes before judging
        return "collecting data"
    rate = (pressure_now - then_pressure) / hours   # hectopascals per hour
    if rate > 0.3:
        return "rising  ^  (%+.1f hPa per hour)" % rate
    if rate < -0.3:
        return "falling v  (%+.1f hPa per hour)" % rate
    return "steady  -  (%+.1f hPa per hour)" % rate

while True:
    data = bme280.sample(bus, ADDRESS, calibration)
    now = time.time()
    if now - last_save >= 60:
        history.append((now, data.pressure))
        last_save = now
    print("\033[2J\033[H", end="")                  # clear the screen and go to the top
    print("ElectroLark desk weather")
    print("------------------------")
    print("Temperature : %5.1f C" % data.temperature)
    print("Humidity    : %5.1f %%" % data.humidity)
    print("Pressure    : %6.1f hPa" % data.pressure)
    print("Trend       : " + trend(data.pressure))
    print()
    print("Press Ctrl+C to stop")
    time.sleep(5)

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
StartTemperature, humidity, pressure
Breathe on the sensorHumidity rises
Warm it with your hands near itTemperature rises a little
Wait ten minutesA trend word and a rate
Press Ctrl+CThe program stops

If it does not work

No BME280 found

Check the four wires, and that I2C is on after a reboot.

ModuleNotFoundError

Run the program from the virtual environment with its own python.

Temperature too high

Move the sensor away from the Pi 5 on longer leads.

Trend never appears

It needs about ten minutes of readings.

Garbled screen

Use a terminal that understands ANSI codes, such as the Pi's own.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the raspberry Pi 5 terminal weather desk?

Raspberry Pi 5 (8 GB), BME280 Environmental Sensor and Breadboard 830 Tie Points.

How long does the raspberry Pi 5 terminal weather desk take to build?

About 110 minutes for a beginner maker, in 7 steps.

How do I know the raspberry Pi 5 terminal weather desk works?

Start: Temperature, humidity, pressure. Breathe on the sensor: Humidity rises. Warm it with your hands near it: Temperature rises a little.

No BME280 found: what should I check?

Check the four wires, and that I2C is on after a reboot.

ModuleNotFoundError: what should I check?

Run the program from the virtual environment with its own python.

Temperature too high: what should I check?

Move the sensor away from the Pi 5 on longer leads.

Trend never appears: what should I check?

It needs about ten minutes of readings.