Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe Raspberry Pi Camera Module 3 has autofocus and a good sensor, and Picamera2 is the Python library for it on current Raspberry Pi OS. This project runs a tiny web server that streams the camera as MJPEG, so any phone or computer on your network can watch by opening the Pi's address and port. It is the base for a baby-room camera, a pet camera or a workshop monitor. Keep it on a trusted network only: this simple stream has no password.
Use cameras only where you have the right to, and tell people who live in the house.
Turn the Pi off before plugging the camera cable in or out.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
Official 27 W supply. Switch the Pi off before connecting or removing the camera cable.
stream.pyimport io, socketserver
from http import server
from threading import Condition
from picamera2 import Picamera2
from picamera2.encoders import MJPEGEncoder
from picamera2.outputs import FileOutput
PAGE = b"<html><body style='margin:0;background:#000'><img src='stream.mjpg' style='width:100%'></body></html>"
class Output(io.BufferedIOBase):
def __init__(self):
self.frame = None
self.condition = Condition()
def write(self, buf):
with self.condition:
self.frame = buf
self.condition.notify_all()
class Handler(server.BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/":
self.send_response(200); self.send_header("Content-Type", "text/html"); self.end_headers()
self.wfile.write(PAGE)
elif self.path == "/stream.mjpg":
self.send_response(200)
self.send_header("Content-Type", "multipart/x-mixed-replace; boundary=FRAME")
self.end_headers()
try:
while True:
with output.condition:
output.condition.wait()
frame = output.frame
self.wfile.write(b"--FRAME\r\nContent-Type: image/jpeg\r\nContent-Length: %d\r\n\r\n" % len(frame))
self.wfile.write(frame); self.wfile.write(b"\r\n")
except Exception:
pass
else:
self.send_error(404)
class Server(socketserver.ThreadingMixIn, server.HTTPServer):
allow_reuse_address = True
daemon_threads = True
cam = Picamera2()
cam.configure(cam.create_video_configuration(main={"size": (1280, 720)}))
output = Output()
cam.start_recording(MJPEGEncoder(), FileOutput(output))
try:
Server(("", 8000), Handler).serve_forever()
finally:
cam.stop_recording()
Power off, reseat the ribbon cable the right way round, and check that the connector latch is closed.
Lower the size to 640 by 480, or use a wired network.
Use current Raspberry Pi OS and run `sudo apt install python3-picamera2`.
Not in this script. Put it behind a VPN or a reverse proxy with a login for any real use.
Yes. Add a second encoder that writes to a file.
Yes, with the cable that suits its camera connector.
4 parts: Raspberry Pi 5 with 4GB RAM, Raspberry Pi Camera Module 3 Standard, Official 27W USB-C PD Power Supply for Raspberry Pi 5 – IN Plug and Official Raspberry Pi 32GB A2 Class Micro SD Card. 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 (stream.py).
About ₹19,656 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Capturing frames with Picamera2; Serving an MJPEG stream with Python's http.server; Connecting the CSI ribbon cable safely.
Use cameras only where you have the right to, and tell people who live in the house. Turn the Pi off before plugging the camera cable in or out.
Ideas that reuse this build: Time-lapse camera with a Raspberry Pi Camera Module 3. 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.