Raspberry Pi Pico W Wi-Fi Weather Station: Wiring, Code and Simulator
To build this Raspberry Pi Pico W Wi-Fi Weather Station project you need a Raspberry Pi Pico W and a 16x2 LCD. The Pico W joins Wi-Fi, fetches the live temperature from the Open-Meteo API with urequests, and shows it on an I2C LCD. Make the 4 connections in the wiring table, upload the MicroPython code, and open the Network tab to watch the request go out. Change the latitude and longitude to your own city.
Open this circuit in the free Raspberry Pi Pico W simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | Raspberry Pi Pico W | the microcontroller board |
| 1 | 16x2 LCD | Character LCD (HD44780). Wiring "full": RS, E and D4–D7 to pins (LiquidCrystal). Wiring "i2c": SDA to A4, SCL to A5 (LiquidCrystal_I2C, address 0x27). |
Wiring
| # | From | To |
|---|---|---|
| 1 | Raspberry Pi Pico W GP4 | 16x2 LCD SDA |
| 2 | Raspberry Pi Pico W GP5 | 16x2 LCD SCL |
| 3 | Raspberry Pi Pico W VBUS | 16x2 LCD VCC |
| 4 | Raspberry Pi Pico W GND | 16x2 LCD GND |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Raspberry Pi Pico W. No install or account is needed.
- Add the parts. Add a 16x2 LCD from the parts palette.
- Wire 1. Connect Raspberry Pi Pico W GP4 to 16x2 LCD SDA.
- Wire 2. Connect Raspberry Pi Pico W GP5 to 16x2 LCD SCL.
- Wire 3. Connect Raspberry Pi Pico W VBUS to 16x2 LCD VCC.
- Wire 4. Connect Raspberry Pi Pico W GND to 16x2 LCD GND.
- Paste the MicroPython code. Paste the MicroPython code below into the code editor.
- Run it. Press Run. Open the Network tab to watch the request go out. Change the latitude and longitude to your own city.
MicroPython code
# Pico W weather station: join Wi-Fi, ask a real weather API, show it on the LCD.
# Open-Meteo is free and needs no key. Change the latitude/longitude to your city.
# The LCD is a 16x2 with a PCF8574 backpack on I2C0 (SDA GP4, SCL GP5).
import network, urequests, time
from machine import Pin, I2C
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=100000)
ADDR = 0x27
def nibble(v, rs):
d = (v << 4) | 0x08 | rs # 0x08 keeps the backlight on
i2c.writeto(ADDR, bytes([d | 0x04, d])) # pulse E
def send(v, rs=0):
nibble(v >> 4, rs)
nibble(v & 0x0F, rs)
def lcd_init():
time.sleep_ms(50)
for _ in range(3):
nibble(0x03, 0)
time.sleep_ms(5)
nibble(0x02, 0)
for c in (0x28, 0x0C, 0x06, 0x01):
send(c)
time.sleep_ms(2)
def write(text, row=0):
send(0x80 | (0x40 * row))
for ch in "{:<16}".format(text)[:16]:
send(ord(ch), 1)
lcd_init()
write("Joining Wi-Fi...")
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("BFB-Lab", "") # the lab's open access point
while not wlan.isconnected():
time.sleep_ms(200)
print("connected, IP", wlan.ifconfig()[0])
write(wlan.ifconfig()[0], 1)
URL = ("https://api.open-meteo.com/v1/forecast"
"?latitude=28.61&longitude=77.21¤t=temperature_2m,relative_humidity_2m")
while True:
try:
r = urequests.get(URL)
now = r.json()["current"]
r.close()
t, h = now["temperature_2m"], now["relative_humidity_2m"]
print("New Delhi:", t, "C,", h, "% humidity")
write("New Delhi")
write("%.1fC %d%%RH" % (t, h), 1)
except OSError as e:
print("request failed:", e)
write("request failed", 1)
time.sleep(30)
What to try
Open the Network tab to watch the request go out. Change the latitude and longitude to your own city.
Frequently asked questions
How do I wire the Wi-Fi Weather Station project on a Raspberry Pi Pico W?
Make 4 connections: Raspberry Pi Pico W GP4 to 16x2 LCD SDA; Raspberry Pi Pico W GP5 to 16x2 LCD SCL; Raspberry Pi Pico W VBUS to 16x2 LCD VCC; Raspberry Pi Pico W GND to 16x2 LCD GND.
What parts do I need for this Raspberry Pi Pico W project?
A Raspberry Pi Pico W and a 16x2 LCD.
Can I simulate this Raspberry Pi Pico W project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and MicroPython code in your browser for free, with no install and no hardware. The Pico W’s RP2040 is emulated and runs the official MicroPython firmware; its Wi-Fi and Bluetooth chip is stood in for by a virtual network that reaches the real internet.
What does the code do?
The Pico W joins Wi-Fi, fetches the live temperature from the Open-Meteo API with urequests, and shows it on an I2C LCD.