gpiotools_blink.sh

Raspberry Pi Model B+ (2014) — Board Sheet · File : gpiotools_blink.sh · Language : Bash · Use case : Piloter une GPIO depuis un script shell ou cron, sans dépendance Python

No Python needed: gpiotools exports the pin and toggles its level, handy in cron, install scripts or systemd units. GPIO17 is pin 11 of the J8 (40-pin) connector. The trap releases the pin on exit.

Hardware

A Raspberry Pi Model B+ (BCM2835, 40-pin GPIO header, micro-USB power, 3.5 mm 4-pole audio jack). One LED, a 330-ohm resistor, no Python packages (gpiotools only).

Wiring

LED + resistor between GPIO17 (pin 11) and GND, the classic J8 LED build.

How it works

gpio-export creates /sys/class/gpio/gpio17; the script writes 1/0 to value via gpio-set/gpio-clear, direction set at export.

Running it

Copy the script to the board (scp), then run it with python3 (or bash). Install gpiozero with sudo apt install python3-gpiozero if missing. The 40-pin pinout is in the official schematic and on the Raspberry Pi website.

Variants

gpio-get reads a button; gpiomon (libgpiod) waits on edges. No built-in Wi-Fi: use Ethernet or a USB dongle; 5 V/1.2 A micro-USB supply.

gpiotools_blink.sh

#!/usr/bin/env bash
set -u
# gpiotools_blink.sh — LED clignotante sans Python, via gpiotools.
# Deps: sudo apt install gpiotools
# GPIO17 = broche 11 sur le connecteur 40 broches (J8).
# Alternative sans paquet : echo 17 > /sys/class/gpio/export a la main.
# Relancez si la broche est deja occupee par un autre service.
PIN=17
gpio-export $PIN out
trap 'gpio-unexport $PIN' EXIT

echo "LED sur GPIO$PIN, Ctrl+C pour sortir"
while true; do
    gpio-set $PIN
echo "ON"
    sleep 0.5
    gpio-clear $PIN
echo "off"
    sleep 0.5
done

← Back to the board