clignotante.py

RP2040 (generic board / chip) · 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 generic RP2040 (dual Cortex-M0+) board programmed with MicroPython. 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

Flash MicroPython via BOOTSEL (.uf2 file), then copy the script to the board drive. Check your board's user LED pin (often GP25) and adapt if needed.

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