GPIO - General Purpose Input Output

GPIO's, General Purpose Input Outputs are the simplest interface to the outside world from a MCU, they are designated pins which can be programmed to function as an Input, Output or Alternate Function (utilise features of a peripheral connected to the pin such as UART which is commonly used for debugging - more on this later!).

The drive strength of some GPIO pins can also be set permitting a higher current which could be used to drive high power LEDs directly for example instead of needing to connect a low current output to a transistor to amplify the current.

A very common use case for input pins is connection to a push button or switch to change the state of the system.

Button Debouncing

When a button is pressed, the output connected to the button does not settle to the closed state immediately, this is to say if we connect the button up so that pressing it brings the button input to 0V (GND) it will not go straight to 0V from the supply voltage, rather it will oscillate, bounce, between the two states several times before settling to 0V.

What does this mean? It means for a single press software will detect multiple press events. In general this is not what you want, we may want to toggle an LED on/off per button press in which case this setup as-is will not work, it will flicker on and off several times before finishing at an on or off state depending how many times it bounced.

Fortunately this is a common problem which can be easily solved in either software or hardware.