-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[DOCS] Writing a new Arduino documentation about GPIO #5894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
493f516
add new documation GPIO
halyssonJr 89275ee
Merge branch 'master' into master
halyssonJr 67e0370
[Docs] Removed the build folders
pedrominatel cc2321e
[Docs] Removed the unused folders
pedrominatel cbe23fe
[Docs] Removed the build folders again
pedrominatel 31b2cdf
change piMode() to pinMode and remove 'do' on warning sentence
halyssonJr a41ef07
Remove 'A'before fetures
halyssonJr 8ec5acb
add files gpios
halyssonJr ba3f718
Fix reference link and add a line after the title.
halyssonJr cb60a76
[Docs] Removed build folders
pedrominatel dfbf36a
[Docs] Added new sections to the docs and fixed issues
pedrominatel 7c219d3
[Docs] Reverted the changes on the conf.py file
pedrominatel 3a27643
[Docs] Added interrupt example and fixed code style on GPIO example
pedrominatel d899666
Merge branch 'master' into master
pedrominatel c62e73a
[Docs] Fixed typo
pedrominatel 8c7748c
Merge branch 'master' of github.com:halyssonJr/arduino-esp32
pedrominatel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,170 @@ | ||
#### | ||
GPIO | ||
#### | ||
|
||
About | ||
----- | ||
|
||
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. | ||
|
||
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. | ||
|
||
.. 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. | ||
|
||
GPIOs Modes | ||
*********** | ||
|
||
There are two different modes in the GPIO configuration: | ||
|
||
- **Input Mode** | ||
|
||
In this mode, the GPIO will receive the digital state from a specific device. This device could be a button or a switch. | ||
|
||
- **Output Mode** | ||
|
||
For the output mode, the GPIO will change the GPIO digital state to a specific device. You can drive an LED for example. | ||
|
||
GPIO API | ||
-------- | ||
|
||
Here is the common functions used for the GPIO peripheral. | ||
|
||
pinMode | ||
******* | ||
|
||
The ``pinMode`` function is used to define the GPIO operation mode for a specific pin. | ||
|
||
.. code-block:: arduino | ||
|
||
void pinMode(uint8_t pin, uint8_t mode); | ||
|
||
* ``pin`` defines the GPIO pin number. | ||
* ``mode`` sets operation mode. | ||
|
||
The following modes are supported for the basic `input` and `output`: | ||
|
||
* **INPUT** sets the GPIO as input without pullup or pulldown (high impedance). | ||
* **OUTPUT** sets the GPIO as output/read mode. | ||
* **INPUT_PULLDOWN** sets the GPIO as input with the internal pulldown. | ||
* **INPUT_PULLUP** sets the GPIO as input with the internal pullup. | ||
|
||
Internal Pullup and Pulldown | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
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. | ||
If the pullup or pulldown mode is not defined, the pin will stay in the high impedance mode. | ||
|
||
digitalWrite | ||
************* | ||
|
||
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``. | ||
|
||
.. code-block:: arduino | ||
|
||
void digitalWrite(uint8_t pin, uint8_t val); | ||
|
||
* ``pin`` defines the GPIO pin number. | ||
* ``val`` set the output digital state to ``HIGH`` or ``LOW``. | ||
|
||
digitalRead | ||
*********** | ||
|
||
To read the state of a given pin configured as ``INPUT``, the function ``digitalRead`` is used. | ||
|
||
.. code-block:: arduino | ||
|
||
int digitalRead(uint8_t pin); | ||
|
||
* ``pin`` select GPIO | ||
|
||
This function will return the logical state of the selected pin as ``HIGH`` or ``LOW``. | ||
|
||
Interrupts | ||
---------- | ||
|
||
The GPIO peripheral on the ESP32 supports interruptions. | ||
|
||
attachInterrupt | ||
*************** | ||
|
||
The function ``attachInterruptArg`` is used to attach the interrupt to the defined pin. | ||
|
||
.. code-block:: arduino | ||
|
||
attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode); | ||
|
||
* ``pin`` defines the GPIO pin number. | ||
* ``handler`` set the handler function. | ||
* ``mode`` set the interrupt mode. | ||
|
||
Here are the supported interrupt modes: | ||
|
||
* **DISABLED** | ||
* **RISING** | ||
* **FALLING** | ||
* **CHANGE** | ||
* **ONLOW** | ||
* **ONHIGH** | ||
* **ONLOW_WE** | ||
* **ONHIGH_WE** | ||
|
||
attachInterruptArg | ||
****************** | ||
|
||
The function ``attachInterruptArg`` is used to attach the interrupt to the defined pin using arguments. | ||
|
||
.. code-block:: arduino | ||
|
||
attachInterruptArg(uint8_t pin, voidFuncPtrArg handler, void * arg, int mode); | ||
|
||
* ``pin`` defines the GPIO pin number. | ||
* ``handler`` set the handler function. | ||
* ``arg`` pointer to the interrupt arguments. | ||
* ``mode`` set the interrupt mode. | ||
|
||
detachInterrupt | ||
*************** | ||
|
||
To detach the interruption from a specific pin, use the ``detachInterrupt`` function giving the GPIO to be detached. | ||
|
||
.. code-block:: arduino | ||
|
||
detachInterrupt(uint8_t pin); | ||
|
||
* ``pin`` defines the GPIO pin number. | ||
|
||
.. _gpio_example_code: | ||
|
||
Example Code | ||
------------ | ||
|
||
GPIO Input and Output Modes | ||
*************************** | ||
|
||
.. code-block:: arduino | ||
|
||
#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); | ||
} | ||
} | ||
|
||
GPIO Interrupt | ||
************** | ||
|
||
.. literalinclude:: ../../../libraries/ESP32/examples/GPIO/GPIOInterrupt/GPIOInterrupt.ino | ||
:language: arduino | ||
|
||
.. _datasheet: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.