GPIO (General Purpouse Input Output) is peripheral responsible to controls reception and deliver digital signals by means of easy interface acess with world, physical pins.
A fetures of this peripheral relates with largely quantity pins available on chip, also being this programmable and configurable. An example of interaction happen when turn on LED or pulse control a button.
Note
There are some GPIOs with special functions and not all the is accessible in all development board. For more information strong suggest acess datasheet.
The GPIOs used two different configuration :
- Input
- Receive external digital signals
- Output
- Send internal digital signals
Here are description of frequently used functions for GPIOs
Initial configuration for use pin with input or output.
void piMode(uint8_t pin, uint8_t mode);
pin
select GPIOmode
sets mode operation (INPUT
,OUTPUT
orINPUT_PULLUP
, ).
Write digital signal on pin.
void digitalWrite(uint8_t pin, uint8_t val);
pin
select a GPIOval
logic level write on pin (HIGH
orLOW
)
Warning
If pin not set to OUTPUT
on pinMode(), may do not work correct.
Read digital pin signal picked
int digitalRead(uint8_t pin);
pin
select GPIO
This function will be return logical state HIGH
or LOW
This application helps understand concepts using dynamic simulation provide by `Wokwi`_, test the gpio code and start.
Here is full code for example application of GPIOs
#define LED 12 #define BUTTON 2 uint8_t stateLED = 0; void setup() { pinMode(LED, OUTPUT); pinMode(BUTTON,INPUT_PULLUP); } void loop() { if(!digitalRead(BUTTON)){ stateLED = stateLED^1; digitalWrite(LED,stateLED); } }