What is GPIO?
General-purpose input/output: microcontroller pins that software can configure as inputs or outputs, used for reading switches, lighting LEDs and so on.
Field: Embedded Systems & Firmware
Read the beginner explainer: What Is a Microcontroller? Tiny Computers in Everyday Things
Japanese name: GPIO
GPIO controller registers
GPIO pins are controlled by a GPIO controller inside the microcontroller or SoC. The basic registers are a direction register that sets each pin as input or output, an output data register that holds the value to drive, and an input data register for reading the pin voltage. Other registers select internal pull-up or pull-down resistors, the output type (push-pull or open-drain), and output drive strength and slew rate. On many microcontrollers you can also choose whether a pin acts as GPIO or as a pin of another peripheral such as a UART or SPI. Some controllers provide set and reset registers that force only specific bits to 1 or 0, so bits can be changed safely without reading back the others.
Using a pin as an input
Input pins often use noise-tolerant Schmitt triggers, and the controller synchronizes the value to its clock before reading it. A pin connected to nothing has no defined voltage, so its value can change randomly and short-circuit current can flow; a pull-up or pull-down fixes its level. Mechanical switch contacts bounce, flipping between 0 and 1 several times (contact bounce), which is removed by waiting a set time in software or by filtering. Most GPIO controllers can raise interrupts on rising or falling edges or on levels, which can also wake the chip from low-power states.
Limits when driving outputs
A push-pull output actively drives the pin both toward the supply and toward ground, while an open-drain output drives only low and relies on a pull-up resistor for high. GPIO pins can supply only small currents, and the datasheet sets limits both per pin and for all pins combined. LEDs are connected with a series resistor to limit current. Loads needing large currents, such as motors and relays, and inductive loads such as coils are driven through a transistor or driver IC, with a diode to protect against back EMF. Applying a voltage above the supply to a pin forces current through its protection diodes, which can cause malfunction or damage.
GPIO under an operating system
On SoCs running Linux and similar systems, a pin controller assigns pin functions and the GPIO controller driver handles GPIO input and output, with pin usage described in a device tree or similar. From Linux applications, the standard approach is a library such as libgpiod that uses the GPIO character device; the sysfs interface is deprecated. When pins run short, GPIO expanders connected over I2C or SPI add more. Because going through the OS adds response delay, signals that need precise timing are usually generated by dedicated peripherals.
Try it: questions about GPIO
- AWhether the pin is used as an input or an output (its direction)
- BThe color of the pin
- CThe name of the programmer who wrote the code
Show answer and explanation
Answer: A. Whether the pin is used as an input or an output (its direction)
A GPIO pin can be used as either an input or an output under software control. Configured as an output through the direction register, the value written to the output register becomes the pin voltage; configured as an input, the pin voltage can be read from the input register. Most microcontrollers also let you set pull-ups, the output type (push-pull or open-drain) and whether the pin serves another peripheral. On some microcontrollers, the clock supply to the GPIO block must be enabled before these settings.
FAQ
What is GPIO?
GPIO stands for general-purpose input/output: pins that software can configure as either inputs or outputs. They are widely used for signals without a fixed purpose, such as reading switch states, lighting LEDs, or sending reset or select signals to other ICs.
What is a GPIO controller?
It is the circuit that controls a group of GPIO pins, with registers setting each pin's direction, output value, input value, pull-up or pull-down and interrupt conditions. The CPU operates the pins by reading and writing these registers. GPIO expanders attached over I2C or SPI are also treated as a kind of GPIO controller.
Can a GPIO pin drive a motor directly?
Generally no. GPIO pins can supply only small currents, while motors need large currents and produce back EMF when they stop, which can damage the pin. Drive them through a transistor or motor driver IC, adding a protection diode where needed.
Books on Embedded Systems & Firmware Ad
Learn hands-on: parts and kits
Building real circuits is a good way to check what you learned in the questions.
As an Amazon Associate I earn from qualifying purchases.
Comparisons that include this term
- I2C vs SPI vs UART: Differences and When to Use EachI2C vs SPI vs UART compared in a table: number of wires, clock, speed, topology, addressing, error checking a…
- MCU vs MPU: Microcontroller vs Microprocessor ComparedMCU vs MPU compared in a table: integration, clock speed, memory, operating system, real-time behavior, power…
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.
Back to the glossary