led_blink.py
The classic first GPIO build: an LED with a 330-ohm resistor blinks once per second via gpiozero. The script imports LED, targets GPIO17 (pin 11) and toggles it in a loop. Ideal to check the power supply (puce I/O RP1, USB-C 5 V/5 A (27 W), deux ports CSI, connecteur JST pour caméra/ventilateur) before a bigger project.
Hardware
A Raspberry Pi 5 (quad-core BCM2712 at 2.4 GHz, RP1 I/O chip, 40-pin GPIO, recommended 5 V/5 A USB-C power, two CSI camera ports). One red LED, a 330-ohm resistor, dupont wires (40-pin header).
Wiring
LED anode (long leg) to GPIO17 through the resistor, cathode to any GND pin of the J8 connector.
How it works
gpiozero sets the pin as output; led.on/off drive it to 3.3 V or 0 V. KeyboardInterrupt cleans up on exit.
Running it
Copy the script to the board (scp), then run it with python3. On Bookworm, gpiozero 2.x drives the pins through the RP1 chip; keep gpiozero and python3-rpi.gpio updated (sudo apt full-upgrade). A 5 V/5 A supply is advised.
Variants
Use led.blink(0.2, 0.8) for an asymmetric pattern; chain several LEDs for a scroller. A 27 W (5 V/5 A) supply is recommended; without it USB output is capped at 600 mA total.
led_blink.py
# led_blink.py — fait clignoter une LED via gpiozero.
# Deps: sudo apt install python3-gpiozero
# Montage : LED + resistance 330 ohms sur GPIO17 (broche 11), GND sur GND.
from gpiozero import LED
from time import sleep
LED_PIN = 17 # numero GPIO, pas numero de broche
ON_TIME = 0.5
OFF_TIME = 0.5
led = LED(LED_PIN)
print(f"Clignotement GPIO{LED_PIN}, Ctrl+C pour terminer")
try:
while True:
led.on()
sleep(ON_TIME)
led.off()
sleep(OFF_TIME)
except KeyboardInterrupt:
print("Arret propre")
led.off()