Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe Pico counts milliseconds with ticks_ms and shows minutes, seconds and hundredths on the OLED. The first button starts and stops the clock; the second records a lap while running and resets when stopped. Use it for races on sports day or timing experiments in the lab.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico stopwatch with lap and reset on an OLED (MicroPython)
from machine import Pin, I2C
import ssd1306, time
oled = ssd1306.SSD1306_I2C(128, 64, I2C(0, sda=Pin(4), scl=Pin(5)))
go = Pin(16, Pin.IN, Pin.PULL_UP) # start / stop
lap = Pin(17, Pin.IN, Pin.PULL_UP) # lap while running, reset while stopped
running = False
start = 0
elapsed = 0 # ms counted before the latest start
last_lap = None
def fmt(ms):
return "{:02d}:{:02d}.{:02d}".format(ms // 60000, (ms // 1000) % 60, (ms // 10) % 100)
def pressed(pin):
if pin.value() == 0:
time.sleep_ms(20)
while pin.value() == 0:
time.sleep_ms(5)
return True
return False
while True:
now = elapsed + (time.ticks_diff(time.ticks_ms(), start) if running else 0)
if pressed(go):
if running:
elapsed = now
else:
start = time.ticks_ms()
running = not running
if pressed(lap):
if running:
last_lap = now
else:
elapsed, last_lap = 0, None
oled.fill(0)
oled.text("STOPWATCH" if running else "STOPPED", 0, 0)
oled.text(fmt(now), 24, 24)
if last_lap is not None:
oled.text("Lap " + fmt(last_lap), 0, 50)
oled.show()
time.sleep_ms(30)
Check SDA/SCL and try address 0x3D. Run an I²C scanner to confirm.
The button is rotated 90°; legs on the same side are already connected. Turn it.
5 parts: 0.96" OLED Display 128x64 (I2C), Tactile Push Button Switch, 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 ₹640 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; Pull-ups and debouncing.
Ideas that reuse this build: Seven-segment stopwatch and Pico reaction game. 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.