UNIT 07 · INTERACTING WITH HARDWARE

Digital Input and Output

Pins that read, drive and survive the real world.

6 lessons24 guided experiments43 min full read

A general-purpose I/O pin looks like the simplest thing on a microcontroller: write a 1, the LED lights; read a 0, the button is pressed. In practice every pin is a small configurable circuit with a multiplexer, an output driver that can push or only pull, an input buffer with pulls and hysteresis, and protection diodes, and the firmware around it decides whether a press is seen once, twice or not at all.

Start with lesson 1 →

The unit in six ideas

  1. 1A pin is a multiplexer (who owns it: software GPIO or a peripheral) in front of a pad (input buffer, pulls, Schmitt trigger, drive strength, slew, protection).
  2. 2Push-pull drives both levels hard with two transistors; open-drain only pulls low, and a pull-up makes the high level.
  3. 3Every input needs a driver or a pull; use a pull-up with a button to GND (active low) and a pull-down with a button to VDD.
  4. 4Contacts bounce for milliseconds; sample the input periodically and decide from its history instead of reacting to edges.
  5. 5Budget both per-pin and total chip current; anything more than a few milliamps, or a sum near the limit, needs a driver transistor.
  6. 6delay() blocks the whole loop; an input shorter than the delay can be missed entirely.

Lessons

  1. LESSON 01 · 4 EXPERIMENTS · 7 MIN

    Pin Modes and Alternate Functions

    Who decides which peripheral owns a pin, and how do you tell the chip?

  2. LESSON 02 · 4 EXPERIMENTS · 7 MIN

    Push-Pull and Open-Drain Outputs

    What is different about those pins?

  3. LESSON 03 · 4 EXPERIMENTS · 7 MIN

    Reading Inputs and Handling Floating Pins

    What else does a reliable input need?

  4. LESSON 04 · 4 EXPERIMENTS · 7 MIN

    Debouncing Buttons and Switches

    How do you turn that burst into exactly one event, and what does it cost?

  5. LESSON 05 · 4 EXPERIMENTS · 8 MIN

    Driving Loads and Protecting Pins

    What does a pin need around it to drive real loads safely, and to survive the outside world?

  6. LESSON 06 · 4 EXPERIMENTS · 7 MIN

    Designing a Nonblocking Input-Output Loop

    How should a loop be structured so that inputs are never missed and one new feature cannot break the others?