import RPi.GPIO as GPIOfrom time import sleepLED = 17GPIO.setmode(GPIO.BCM)GPIO.setup(LED, GPIO.OUT, initial=GPIO.LOW)try: for i in range(10): GPIO.output(LED, GPIO.HIGH) sleep(1.0) GPIO.output(LED, GPIO.LOW) sleep(0.5)finally: GPIO.cleanup()
Example only. Do not copy this code as it is: read it, learn from it, then write your own.
The LED still switches fully on and off. At sufficiently high frequency, vision blends the flashes. Flicker visibility depends on brightness, motion, and the observer.
Both traces have 25% duty and the same ideal average. Doubling frequency halves the period and on-time. Duty sets average light. Frequency affects visible flicker.
Use ← → to move, Home / End to jump, and F for fullscreen.
Figure descriptions
Slide 1 · Raspberry Pi 5: a computer on one board
Official photograph of the Raspberry Pi 5 board, with the processor, GPIO header, USB connectors, Ethernet jack, and display connectors visible.
Slide 2 · The Pi 5 ports and connectors
Freenove diagram of Raspberry Pi 5 connectors: GPIO header, PCIe, power button, USB-C power, RTC battery, UART, micro HDMI, camera and display, fan, USB and Ethernet. The microSD slot is underneath the board.
Slide 3 · Why use a Pi in an instrumentation lab?
Raspberry Pi Foundation illustration of an LED with a resistor in series on the blue anode lead, and a black cathode return lead.
Slide 4 · What can we build with it?
Adafruit photograph of a clear through-hole LED showing its lens and two unequal-length leads.
Photograph of an MCP9808 digital temperature-sensor breakout board used for temperature measurements.
NEMA 17 stepper motor with a square body, output shaft, mounting holes, and four coil leads. Photo: Adafruit.
Windmills on the riverbank at Zaandam, the Netherlands, under an overcast sky.
Slide 5 · Raspberry Pi OS runs on Linux
Raspberry Pi OS desktop on a monitor, showing the taskbar and desktop interface.
Slide 7 · GPIO switches between two voltage levels
Ideal digital output alternating between 3.3 volts HIGH and 0 volts LOW. For the illustrated sourcing circuit, HIGH turns the LED on and LOW turns it off.
Slide 8 · BCM 17 means physical pin 11
Raspberry Pi 40-pin header map distinguishing physical pin positions from BCM GPIO numbers and marking 3.3 V, 5 V, ground, I²C, UART, and SPI connections. Power pins are not GPIO inputs.
Slide 9 · An LED conducts in one direction
Adafruit photograph of a clear through-hole LED showing its lens and two unequal-length leads.
Adafruit LED symbol: conventional current flows from the anode toward the cathode, with arrows indicating emitted light.
Slide 10 · The LED driver is one complete current path
Raspberry Pi Foundation wiring illustration: BCM 17, physical pin 11, connects through a resistor to the LED anode. The cathode connects to GND, physical pin 6. The source depicts 330 ohms; the course uses 470 ohms.
Slide 11 · The resistor sets the on-current
Voltage-budget bar: a 3.3 volt output is split into a 2.0 volt LED forward drop and a 1.3 volt drop across the series resistor.
Slide 12 · The same circuit on a breadboard
Raspberry Pi Foundation breadboard diagram: GPIO 17 connects via the blue wire and a series resistor to the red LED anode. The LED cathode connects via the black wire to GND. An older Pi is shown with the same header positions used on Pi 5. The course uses 470 ohms in place of the illustrated 330 ohms.
Slide 13 · The GPIO controls a small load
Raspberry Pi Foundation illustration showing an LED and a resistor connected in series between GPIO 17 and ground on a Raspberry Pi header.
Slide 16 · The blink period includes both delays
Ideal blink waveform: one second HIGH, half a second LOW, giving a period of 1.5 seconds and frequency of two thirds of a hertz.
Slide 17 · Fast switching can look like steady light
Two ideal signals at equal 50 percent duty cycle: slow switching at 1 hertz over a two-second window and faster switching at 100 hertz over a 50-millisecond window. The fast trace expands the time scale to show individual pulses. Flicker visibility varies with the observer and conditions.
Slide 18 · PWM controls the fraction of time on
Ideal PWM waveform: HIGH for 3 milliseconds in each 10-millisecond period. Duty is 30 percent and frequency is 100 hertz.
Slide 19 · More on-time gives more average light
Three ideal PWM waveforms at 20, 50, and 80 percent duty and a common 10-millisecond period. Dashed average voltages are 0.66, 1.65, and 2.64 volts. Each instantaneous output still switches between 0 and 3.3 volts.
Slide 20 · Duty and frequency are separate controls
Two ideal PWM waveforms both at 25 percent duty: 100 hertz with 2.5-millisecond pulses, and 200 hertz with 1.25-millisecond pulses. Frequency changes without changing the ideal average.
Slide 21 · The PWM library schedules the switching
Requested regular PWM edges compared with illustrative late, irregular software-timed edges. These are teaching plots, not measured data.
Slide 23 · Live demo: the Pi, LED, and oscilloscope
Raspberry Pi Foundation breadboard diagram: GPIO 17 connects via the blue wire and a series resistor to the red LED anode. The LED cathode connects via the black wire to GND. An older Pi is shown with the same header positions used on Pi 5. The course uses 470 ohms in place of the illustrated 330 ohms.