Bring forward what you already know
This deck assumes you completed Raspberry Pi Basics first. You already know how to start the Pi, use File Manager, open Terminal, save Python in Thonny, and shut down safely.
Power off means two things
Before changing any GPIO wiring:
- Use the Raspberry Pi menu → Shutdown → Shutdown.
- Wait for the Pi to finish shutting down.
- Disconnect the power cable.
- Only now move wires or components.
Changing the wiring while the Pi is powered makes accidental shorts much easier.
Three ideas are enough to begin
Voltage
The electrical push between two points. Raspberry Pi GPIO logic uses 3.3 V.
Current
The flow of electrical charge through a circuit.
Resistance
Resistance limits current. An LED needs a resistor so too much current does not flow through it.
What is connected inside a breadboard?
- Look at your real breadboard.
- Find the long centre gap.
- On one side of the gap, choose a short row of five holes. Those five holes are electrically joined underneath.
- Choose the matching-looking row across the centre gap. It is not joined to the first row.
These pins connect software to hardware
The 40-pin header contains several kinds of pin:
- 3.3 V power pins.
- 5 V power pins.
- GND (ground) pins.
- GPIO pins that Python can read or control.
A pin can have two useful names
Physical pin number tells you where the pin is on the 40-pin header. GPIO number is the name Python usually uses.
Use the Pi to check
- Start the Pi if it is not already running.
- Open Terminal.
- Type
pinoutand press Enter. - Find GPIO17 in the diagram. Notice that it sits at physical pin 11.
Which direction is the information going?
INPUT
The physical world tells the Pi something.
Button pressed · motion detected · distance measured.
OUTPUT
The Pi tells a physical thing to do something.
LED on · buzzer sound · servo move.
Make a GPIO practice folder
- Open File Manager.
- Open Home →
pi-projects. - Right-click an empty area → New Folder.
- Name it
gpio-basicsand press Enter. - Double-click it so you know the folder opens.
pi-projects → gpio-basics.Wire an LED while the Pi is unplugged
- Push the LED into the breadboard with its two legs in different rows. Keep track of the long leg and short leg.
- Put one end of the 330 Ω resistor in the same row as the LED's long leg.
- Put the other end of the resistor in a different empty row.
- Connect a jumper wire from physical pin 11 (GPIO17) on the Pi to the resistor's free row.
- Connect another jumper wire from the LED's short-leg row to physical pin 9 (GND).
- Trace the circuit with your finger: GPIO17 → resistor → LED long leg → LED short leg → GND.
Python gets a hardware toolbox
GPIO Zero is a Python library included with Raspberry Pi OS. A library is ready-made code you can use instead of writing every low-level hardware instruction yourself.
from gpiozero import LED
This line means: “From the GPIO Zero toolbox, give my program the LED tool.”
LED(17). The 17 means GPIO17, not physical pin 17.Make gpio-led.py before you run it
- Open Thonny.
- Choose File → New.
- Type this code:
from gpiozero import LED
from time import sleep
led = LED(17)
while True:
led.on()
sleep(1)
led.off()
sleep(1)from gpiozero import LED gets the LED tool. from time import sleep gets a pause tool. LED(17) means the LED is connected to GPIO17. while True: means “repeat forever”. The four indented lines are the instructions that repeat: on, wait, off, wait.- Choose File → Save As….
- Go to Home →
pi-projects→gpio-basics. - Save the file as
gpio-led.py. - Only now click Run.
If the LED does not blink
- Click Thonny's red Stop button if the program is still running.
- Shut the Pi down and disconnect power.
- Check the LED direction: long leg toward the resistor/GPIO side, short leg toward GND.
- Check the resistor and LED really share one breadboard row.
- Check the jumper to the Pi is on physical pin 11 / GPIO17.
- Check the ground jumper is on a GND pin, such as physical pin 9.
- Reconnect power, boot, open
gpio-led.pyin Thonny and Run again.
Meet the pushbutton
A pushbutton is an input. When you press it, two sides become electrically connected.
Replace the LED circuit with the button circuit
- Remove the LED and resistor circuit.
- Place the pushbutton so it straddles the breadboard's centre gap.
- Connect a jumper from physical pin 13 (GPIO27) to a row connected to one side of the button.
- Connect a jumper from a row connected to the opposite side of the button to physical pin 14 (GND).
- Trace it: GPIO27 → button → GND.
- Have the circuit checked, then reconnect power and boot.
Save and run gpio-button.py
- Open Thonny → File → New.
- Type:
from gpiozero import Button
button = Button(27)
print("Waiting for a press...")
button.wait_for_press()
print("Button pressed")Button(27) tells GPIO Zero that the button is on GPIO27. wait_for_press() makes Python stop at that line until the button is actually pressed. Only then does the final print run.- Save it in Home →
pi-projects→gpio-basicsasgpio-button.py. - Click Run.
- Look in the Shell: it should say
Waiting for a press.... - Press the physical button once.
Button pressed.If the button does nothing
- Check the Shell first. If there is red error text, fix Python before touching wiring.
- If Python is waiting normally, shut down and disconnect power.
- Check the button really straddles the breadboard gap.
- Check your two wires go to opposite sides of the button, not two legs that are already joined.
- Check GPIO27 is physical pin 13 and GND is physical pin 14 (or another GND pin you deliberately chose).
- Reconnect power and test again.
You now have the pattern
- I know to shut down and unplug before changing GPIO wiring.
- I know GPIO logic is 3.3 V and 5 V must not be fed into a GPIO input.
- I know the breadboard's centre gap separates connections.
- I can tell a physical pin number from a GPIO number.
- I used an LED as an output.
- I used a button as an input.
- I know GPIO Zero gives Python friendly tools for hardware.