Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsMicroPython has a built-in driver for the DHT22, so the whole program fits on one screen. It reads every three seconds, shows temperature and humidity, and keeps the minimum and maximum, the same as a garden max-min thermometer. If a read fails, it simply tries again.
Tick anything you already have and the total updates.
Measures air temperature (±0.5 °C) and relative humidity (±2–5 %) on a single data wire.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico room climate display with a DHT22 and OLED (MicroPython)
from machine import Pin, I2C
import dht, ssd1306, time
sensor = dht.DHT22(Pin(15))
oled = ssd1306.SSD1306_I2C(128, 64, I2C(0, sda=Pin(4), scl=Pin(5)))
lo = hi = None
while True:
try:
sensor.measure()
t, h = sensor.temperature(), sensor.humidity()
except OSError:
print("Sensor read failed, retrying")
time.sleep(2)
continue
lo = t if lo is None or t < lo else lo
hi = t if hi is None or t > hi else hi
oled.fill(0)
oled.text("Room climate", 0, 0)
oled.text("Temp {:.1f} C".format(t), 0, 18)
oled.text("Hum {:.0f} %".format(h), 0, 32)
oled.text("Min {:.0f} Max {:.0f}".format(lo, hi), 0, 52)
oled.show()
print(t, h)
time.sleep(3)
Check the DATA wire and the pull-up. The DHT22 needs at least 2 seconds between reads, so do not poll it faster.
Check SDA/SCL and try address 0x3D. Run an I²C scanner to confirm.
5 parts: DHT22 Temperature & Humidity Sensor, 0.96" OLED Display 128x64 (I2C), Raspberry Pi Pico, Solderless Breadboard (830 points) and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 45 minutes. The build on this page has 4 steps.
No. This page has the complete, tested code (main.py). Install this library first: ssd1306 (micropython-lib).
About ₹762 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Drawing text on an I²C display; Single-wire digital sensors and why some sensors need slow polling.
Ideas that reuse this build: Arduino desk climate and Pico weather OLED. 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.