Skip to content

Latest commit

 

History

History
115 lines (67 loc) · 2.32 KB

gpio.rst

File metadata and controls

115 lines (67 loc) · 2.32 KB

GPIO

About

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.

GPIOs Configuration

The GPIOs used two different configuration :

  • Input
    • Receive external digital signals
  • Output
    • Send internal digital signals

Arduino - ESP32 API

Here are description of frequently used functions for GPIOs

pinMode

Initial configuration for use pin with input or output.

void piMode(uint8_t pin, uint8_t mode);
  • pin select GPIO
  • mode sets mode operation (INPUT, OUTPUT or INPUT_PULLUP, ).

digitalWrite

Write digital signal on pin.

void digitalWrite(uint8_t pin, uint8_t val);
  • pin select a GPIO
  • val logic level write on pin (HIGH or LOW)

Warning

If pin not set to OUTPUT on pinMode(), may do not work correct.

digitalRead

Read digital pin signal picked

int digitalRead(uint8_t pin);
  • pin select GPIO

This function will be return logical state HIGH or LOW

Simulation

This application helps understand concepts using dynamic simulation provide by `Wokwi`_, test the gpio code and start.

Example Code

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);
    }
  }