Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsMusic students need a steady beat. The Pico clicks the piezo at the chosen tempo, with a higher click on the first beat of every four, and shows the beats per minute and a moving block on the OLED. The next beat is timed from the last one rather than after a delay, so it does not drift.
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 metronome with tempo buttons and an OLED (MicroPython)
from machine import Pin, PWM, I2C
import ssd1306, time
oled = ssd1306.SSD1306_I2C(128, 64, I2C(0, sda=Pin(4), scl=Pin(5)))
up = Pin(16, Pin.IN, Pin.PULL_UP)
down = Pin(17, Pin.IN, Pin.PULL_UP)
buzzer = PWM(Pin(15))
bpm = 90
beat = 0
def show():
oled.fill(0)
oled.text("METRONOME", 20, 0)
oled.text("{} BPM".format(bpm), 36, 28)
oled.fill_rect(8 + (beat % 4) * 30, 52, 20, 8, 1) # moving block shows the beat
oled.show()
def tick(accent):
buzzer.freq(1200 if accent else 800)
buzzer.duty_u16(20000)
time.sleep_ms(40)
buzzer.duty_u16(0)
show()
next_beat = time.ticks_ms()
while True:
if up.value() == 0:
bpm = min(220, bpm + 2); show(); time.sleep_ms(120)
if down.value() == 0:
bpm = max(30, bpm - 2); show(); time.sleep_ms(120)
if time.ticks_diff(time.ticks_ms(), next_beat) >= 0:
tick(beat % 4 == 0) # first beat of the bar is higher
beat += 1
show()
next_beat = time.ticks_add(next_beat, 60000 // bpm)
Normal for a bare piezo; mount it on a small box to resonate.
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.
6 parts: Piezo Buzzer (passive), 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 ₹654 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; Generating musical notes with tone(); Pull-ups and debouncing.
Ideas that reuse this build: Stage metronome and Pico melody player. 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.