Raspberry Pi Pico 2 W LED example

Learn MicroPython GPIO output and timing by toggling the Pico 2 W onboard LED once per second.

Repository standards Read the documentation

This is one introductory board example for learners starting with machine.Pin and time.sleep. It uses the named onboard LED and needs no external wiring, Wi-Fi setup or service.

Quick start

  1. Connect a Raspberry Pi Pico 2 W using a USB data cable.
  2. Install MicroPython firmware matching the board, following the official RP2 setup guide.
  3. Open the board in a compatible MicroPython editor or REPL tool.
  4. Transfer and run PiPico2W/FirstLed/main.py. The LED should change state approximately once per second.

The step-by-step program guide explains each line. The machine module belongs to MicroPython on the board; ordinary desktop Python cannot execute the program as written.

Requirements and usage

You need the board, matching firmware, a USB data cable and a tool that can access its filesystem and REPL. The repository provides the program, not firmware or a desktop installer.

from machine import Pin
from time import sleep

led = Pin("LED", Pin.OUT)

while True:
    led.toggle()
    sleep(1)

One state change per second gives an approximately two-second on/off cycle. Run the script interactively while experimenting. Saving it as main.py on the board makes it a startup program; interrupt the loop through the connected tool before editing. It has no command-line options or shutdown handler.

Development and verification

The source and its guide live in PiPico2W/FirstLed/. Its .micropico marker identifies a project folder; it does not install firmware, select a serial port or transfer the program. The remaining website files support the documentation site.

There is no application build or automated hardware test suite. Verify on the board that the LED toggles and that you can stop execution. Documentation/source inspection does not establish a successful physical-board run. The Repository standards workflow checks metadata only.

Troubleshooting

Symptom Check
No module named machine Run on the MicroPython board rather than desktop Python.
Named LED pin unavailable Confirm the board model and firmware expose the LED alias.
Script runs again after restart Check whether the board has a startup file named main.py; interrupt it through the REPL.

Contributing, support and license

Use repository issues for reproducible problems. New examples should state the board, firmware, wiring, expected behavior and actual hardware checks. Follow CONTRIBUTING.md and the repository standards.

Keep wireless credentials and other secrets out of examples and reports; use the security policy for sensitive findings. This repository has an MIT license. The documentation index provides further source navigation.