clignotante.py

Raspberry Pi Pico · File : clignotante.py · Language : Python · Use case : Faire clignoter une LED avec MicroPython

The first MicroPython program: the LED blinks once per second with serial console tracing. It shows Pin as output, value() and time.sleep, the basis of every embedded script on the board.

Hardware

A Raspberry Pi Pico (RP2040 dual Cortex-M0+ @ 133 MHz) with MicroPython installed, powered over USB. No external part (external LED + 330 Ω resistor only if the user LED is unavailable).

Wiring

Nothing to wire: the user LED sits on GP25. For an external LED: any GP pin through a 330 Ω resistor to GND.

How it works

Pin(LED_PIN, Pin.OUT) sets the pin as output. The infinite loop alternates value(1)/value(0) with a one-second pause; print() goes to the USB serial (Thonny).

Running it

Install MicroPython if needed (hold BOOTSEL, plug USB, drop the .uf2 file), then copy the script to the board drive or via Thonny. The script auto-starts when named main.py.

Variants

Save as main.py for auto-start, or replace sleep(1) with sleep_ms(100) for fast blinking.

clignotante.py

# Clignotement d'une LED avec MicroPython (module machine.Pin).
# LED utilisateur integree (GP25 sur la majorite des cartes)
from machine import Pin
import time

LED_PIN = 25

led = Pin(LED_PIN, Pin.OUT)   # broche en sortie numerique

print("Clignotement demarre sur GP" + str(LED_PIN))
compteur = 0

while True:
    led.value(1)              # LED allumee
    compteur += 1
    print("LED ON  (cycle %d)" % compteur)
    time.sleep(1)             # 1 seconde

    led.value(0)              # LED eteinte
    print("LED OFF")
    time.sleep(1)

# Pour arreter : bouton Stop dans Thonny (le script tourne aussi
# tout seul s'il est enregistre sous main.py sur la carte).

← Back to the board