You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/api/gpio.rst
+84-37Lines changed: 84 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,91 +5,140 @@ GPIO
5
5
About
6
6
-----
7
7
8
-
GPIO (General Purpouse Input Output) is peripheral responsible to controls reception and
9
-
deliver digital signals by means of easy interface acess with world, physical pins.
8
+
One of the most used and versatile peripheral in a microcontroller is the GPIO. The GPIO is commonly used to write and read the pin state.
10
9
11
-
Fetures of this peripheral relates with largely quantity pins available on chip, also being
12
-
this programmable and configurable. An example of interaction happen when turn on LED or pulse control a button.
10
+
GPIO stands to General Purpose Input Output, and is responsible to control or read the state of a specific pin in the digital world. For example, this peripheral is widely used to create the LED blinking or to read a simple button.
13
11
14
-
.. note::
15
-
There are some GPIOs with special functions and not all the is accessible in all development board. For more information strong suggest acess datasheet_.
12
+
.. note:: There are some GPIOs with special restrictions, and not all GPIOs are accessible through the developemnt board. For more information about it, see the corresponding board pin layout information.
16
13
17
-
GPIOs Configuration
18
-
*******************
14
+
GPIOs Modes
15
+
***********
19
16
20
-
The GPIOs used two different configuration :
17
+
There are two different modes in the GPIO configuration:
21
18
22
-
- **Input**
19
+
- **Input Mode**
23
20
24
-
- Receive external digital signals
25
-
21
+
In this mode, the GPIO will receive the digital state from a specific device. This device could be a button or a switch.
26
22
27
-
- **Output**
23
+
- **Output Mode**
28
24
29
-
- Send internal digital signals
25
+
For the output mode, the GPIO will change the GPIO digital state to a specific device. You can drive an LED for example.
30
26
27
+
GPIO API
28
+
--------
31
29
32
-
Arduino - ESP32 API
33
-
-------------------------
34
-
Here are description of frequently used functions for GPIOs
30
+
Here is the common functions used for the GPIO peripheral.
35
31
36
32
pinMode
37
-
***********
38
-
39
-
Initial configuration for use pin with input or output.
33
+
*******
40
34
35
+
The ``pinMode`` function is used to define the GPIO operation mode for a specific pin.
41
36
42
37
.. code-block:: arduino
43
38
44
39
void pinMode(uint8_t pin, uint8_t mode);
45
40
46
-
* ``pin`` select GPIO
47
-
* ``mode`` sets mode operation (``INPUT``, ``OUTPUT`` or ``INPUT_PULLUP``, ).
41
+
* ``pin`` defines the GPIO pin number.
42
+
* ``mode`` sets operation mode.
43
+
44
+
The following modes are supported for the basic `input` and `output`:
45
+
46
+
* **INPUT** sets the GPIO as input without pullup or pulldown (high impedance).
47
+
* **OUTPUT** sets the GPIO as output/read mode.
48
+
* **INPUT_PULLDOWN** sets the GPIO as input with the internal pulldown.
49
+
* **INPUT_PULLUP** sets the GPIO as input with the internal pullup.
50
+
51
+
Internal Pullup and Pulldown
52
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53
+
54
+
The ESP32 SoC families supports the internal pullup and pulldown throught a 45kR resistor, that can be enabled when configuring the GPIO mode as ``INPUT`` mode.
55
+
If the pullup or pulldown mode is not defined, the pin will stay in the high impedance mode.
48
56
49
57
digitalWrite
50
58
*************
51
59
52
-
Write digital signal on pin.
60
+
The function ``digitalWrite`` sets the state of the selected GPIO to ``HIGH`` or ``LOW``. This function is only used if the ``pinMode`` was configured as ``OUTPUT``.
53
61
54
62
.. code-block:: arduino
55
63
56
64
void digitalWrite(uint8_t pin, uint8_t val);
57
65
58
-
* ``pin`` select a GPIO
59
-
* ``val`` logic level write on pin (``HIGH`` or ``LOW``)
60
-
61
-
.. warning::
62
-
If pin not set to ``OUTPUT`` on pinMode(), may not work correct.
66
+
* ``pin`` defines the GPIO pin number.
67
+
* ``val`` set the output digital state to ``HIGH`` or ``LOW``.
63
68
64
69
digitalRead
65
70
***********
66
71
67
-
Read digital pin signal picked
72
+
To read the state of a given pin configured as ``INPUT``, the function ``digitalRead`` is used.
68
73
69
74
.. code-block:: arduino
70
75
71
76
int digitalRead(uint8_t pin);
72
77
73
78
* ``pin`` select GPIO
74
79
75
-
This function will be return logical state ``HIGH`` or ``LOW``
80
+
This function will return the logical state of the selecetd pin as ``HIGH`` or ``LOW``.
76
81
77
-
Simulation
82
+
Interrupts
78
83
----------
79
84
80
-
This application helps understand concepts using dynamic simulation provide by `Wokwi`_, test the gpio code and start.
85
+
The GPIO peripheral on the ESP32 supports interruptions.
86
+
87
+
attachInterrupt
88
+
***************
89
+
90
+
The function ``attachInterruptArg`` is used to attach the interrupt to the defined pin.
91
+
92
+
.. code-block:: arduino
93
+
94
+
attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode);
0 commit comments