What is a GPIO? Microcontroller basics

What is a GPIO? Microcontroller basics explained simply

Whether Arduino, ESP32 or STM32 - they all have one thing in common: GPIOs. But what does GPIO actually mean?
And how do you use these pins wisely?

GPIO - this stands for General Purpose Input/Output

A GPIO is a universally usable input/output pin. You can use it on the software side as Input or Output – and therefore Read or control signals.

Typical applications:

  • Read in push-button

  • Switch LEDs or relays

  • Connect sensors or displays

  • Exchange data via I2C or SPI

GPIOs make microcontrollers interactive - they connect your circuit to the outside world.

GPIO as input

A GPIO reads a voltage:

  • High (e.g. 3.3 V or 5 V)

  • Low (0 V, i.e. ground)

A push-button can pull the input to GND, for example. To ensure that the level remains stable when the button is open, you need a Pull-Up- or Pull-Down-Resistor.

Special feature of the STM32:

Many pins can be used as interrupt inputs. This is how the microcontroller immediately reacts to signal changes, instead of constantly querying the pin (polling).
This saves computing power and energy - e.g. in battery operation.

GPIO as output

In output mode, you can switch an LED or a relay, for example. Example (Arduino):


pinMode(13, OUTPUT);
digitalWrite(13, HIGH); // LED on

Note: GPIOs are often only designed for low currents (e.g. 20 mA for Arduino). For higher loads → connect a transistor or MOSFET in between!

Differences between Arduino, ESP32 and STM32

FeatureArduino UNOESP32STM32 (e.g. Blue Pill)
Level voltage5 V3.3 Vmeist 3.3 V
Internal pull-upYesYesYes
Internal pull-downNoTeilsYes
PWM capabilityFew pinsMany pins, flexibleMany pins, depending on the timer
InterruptsLimited pinsMany pins possibleAlmost any pin possible

For the article on pull-down resistors click here.

For the article on pull-up resistors click here.

GPIO for serial interfaces

GPIOs can often be converted - e.g. for:

  • I2C (e.g. sensors, displays)

  • SPI (fast data transmission)

  • UART (Serial communication)

  • PWM (for dimming, motor control)

With the STM32, the pin assignment is often very flexible. A GPIO pin can take on many different functions via so-called alternate functions

Conclusion

A GPIO is the foundation of every microcontroller project.
Whether LED, button, sensor or display - GPIOs are your connection to the circuit.
There are differences depending on the platform, but the basic principle remains the same: Simple, flexible and powerful.