5.5.2 · D1Embedded Systems & Real-Time Software

Foundations — GPIO — input - output, pull-up - pull-down, interrupt on pin change

2,388 words11 min readBack to topic

This is the D1 foundations page. The parent note (GPIO topic) throws a lot of symbols at you: , , HIGH/LOW, , , "Hi-Z", "edge", volatile. Below we build every one from absolute zero — plain words first, then the picture, then why the topic can't live without it.


1. Voltage — the "height" of a wire

The picture: imagine every wire as a water tank at some height. Water (charge) flows from a tall tank to a short one. Voltage is how tall the tank is compared to the floor.

We always measure height relative to something. That reference floor is called ground.

Why the topic needs these two: every single sentence about a pin being "HIGH" or "LOW" secretly means "close to " or "close to ". Without a floor () and a ceiling (), the words HIGH and LOW are meaningless.


2. HIGH / LOW and logic 1 / 0

The picture: a light switch has only up and down. There is no "half-on" that the digital world respects.

Why the topic needs it: reading a button, driving an LED, firing an interrupt — all of it is the CPU deciding "is this wire a 1 or a 0?"


3. Input vs Output — feel vs push

Why the topic needs it: the entire note splits into "output half" (push-pull, open-drain) and "input half" (pull resistors, floating, interrupts). This is the root fork.


4. Resistance , current , and Ohm's Law

Why the topic needs it: choosing a pull resistor value is nothing but this equation.


5. High-impedance (Hi-Z) — the "disconnected" state

The picture: a pipe with a valve shut so tight that no water moves. The pipe is there, but electrically it's as if you snipped it.


6. Floating and the pull resistor

Why the topic needs it: this is the fix for the "#1 beginner bug" — a button that reads pressed when untouched.


7. Active-LOW — why "pressed" often means 0

The picture: the "alarm" is the wire dropping to the floor, not rising to the ceiling.

Why the topic needs it: because internal pull-ups are common and grounding is electrically clean, real hardware reads "pressed = 0", which surprises beginners. Naming it removes the surprise.


8. Edges — a change in height over time

The picture: the wire's height plotted against time looks like a staircase. The vertical step is the edge — that instant of jump.

Why the topic needs it: interrupts fire on edges. No concept of "edge", no concept of "interrupt on pin change".


9. Interrupt & ISR — the tap on the shoulder

Why the topic needs it: the whole "interrupt on pin change" half of the note is this idea. The rule "keep the ISR tiny, clear the flag" all flows from here.


10. volatile — "do not trust your memory of this"

Why the topic needs it: without it, an optimized build caches the shared flag and the main loop never sees the ISR's update — the parent's "works in debug, breaks with -O2" bug.


How these feed the topic

Voltage and Ground

HIGH LOW logic 1 0

Supply VDD

Input vs Output

Ohms Law V equals I R

Pull-up Pull-down

High impedance Hi-Z

Floating problem

Active-LOW wiring

Rising Falling edge

Interrupt and ISR

volatile flag

GPIO topic


Equipment checklist

Cover the right side and answer each before reading the parent note:

What is voltage, in one picture?
The height of a wire's electrical push, measured relative to ground (the floor).
What does mean and what is its voltage?
Ground — the agreed zero-height reference, defined as V.
What does represent?
The chip's supply voltage — the top rail / ceiling (e.g. 3.3 V or 5 V).
HIGH and LOW correspond to which logic values and which heights?
HIGH = logic 1 = near ; LOW = logic 0 = near .
What is the difference between an input pin and an output pin?
Output drives (pushes) the wire to a chosen level; input senses (feels) the wire without forcing it.
State Ohm's Law and the rearranged form the topic uses.
, rearranged to .
For a 3.3 V pin capped at 100 µA, what pull-up value do you get?
.
What does high-impedance (Hi-Z) mean?
Resistance so huge that essentially no current flows — the wire acts disconnected.
What is a floating pin and why is it bad?
An undriven input that picks up noise and reads a random 1 or 0.
Pull-up vs pull-down: what idle level does each give?
Pull-up → idle HIGH (1); pull-down → idle LOW (0).
What does "active-LOW" mean for a button?
Idle reads 1; the pressed event drives the pin to 0.
Define rising edge and falling edge.
Rising = ; falling = — the instant the level changes.
What is an ISR?
Interrupt Service Routine — the function the CPU jumps to when an interrupt fires.
Why must an ISR-shared flag be volatile?
So the compiler re-reads it from memory each time instead of caching a stale copy.