🛠 Première LED sur GPIO17 : banques, courants et broches réservées
Objectives
Turn on an LED from a CM1 GPIO while understanding the pin mapping: GPIOs are divided into bank 0 (GPIO 0 to 27) and bank 1 (GPIO 28 to 45). The GPIO46 and GPIO47 lines are reserved for the system (SD/eMMC ID) and must not be repurposed. The BCM2835 allows 16 mA per pin and a total of 50 mA per bank: an LED with a 330-ohm resistor is well within limits, but a direct relay is not. We control it via sysfs, then via gpiod.
Hardware
- A Compute Module 1 on an IO Board
- 1 LED + 330-ohm resistor
- Dupont wires (the IO Board GPIOs come out of connector J6)
Complete code
# Méthode sysfs (simple)
echo 17 | sudo tee /sys/class/gpio/export
echo out > /sys/class/gpio/gpio17/direction
while true; do
echo 1 > /sys/class/gpio/gpio17/value; sleep 0.5
echo 0 > /sys/class/gpio/gpio17/value; sleep 0.5
done
# Méthode gpiod (moderne)
gpiodetect
gpioset gpiochip0 17=1 # allume
gpioset gpiochip0 17=0 # éteint
# Rappel des limites : 16 mA/broche, 50 mA/banque, broches 46/47 interdites
Expected verification
The LED blinks at 1 Hz. cat /sys/class/gpio/gpio17/direction returns out. Trying echo 46 > export fails (line reserved for the system) — this is the expected behavior, not a failure. The resistor calculation: (3.3 V - 2 V LED drop) / ~13 mA gives approximately 100 ohms minimum; 330 ohms provide a clearly visible LED with a very safe current.
Common errors
- Using GPIO46/47 as outputs: reserved lines (SD card detection), the kernel refuses or the system becomes unstable.
- Exceeding 50 mA cumulative on bank 0 by driving multiple loads: the SoC heats up and voltage levels collapse; add a transistor/driver.
- Confusing the BCM number with the physical connector number: the IO Board schematic is authoritative; use
pinctrlorgpio readall. - Forgetting the resistor: the LED burns out, or worse, the pin. Always use 330 to 1k ohms.
- Leaving a sysfs export active between scripts:
write error: Device or resource busy; remember tounexport.
Other tutorials for this board
- Flasher l'eMMC du CM1 avec rpiboot et le jumper J4
- Premier boot : Bullseye legacy, rails 3,3 V et ordre des alimentations
- Servo moteur sur PWM0 (GPIO18) : 50 Hz et 2,5 à 12,5 %
- BME280 sur I2C0 (GPIO2/3) : activer i2c_arm et lire l'ID 0x60
- Caméra officielle sur le connecteur FPC CSI du CM1
- Boot sans EEPROM : fallback USB et bootcode.bin sur eMMC
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash