Skip to content

Commit 317be68

Browse files
authored
Merge pull request #5685 from pedrominatel/docs/integration_with_wokwi
Docs integration with Wokwi - Blink Tutorial
2 parents 9f827a6 + 1f4dd7f commit 317be68

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

Diff for: docs/source/tutorials/blink.rst

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
##########################
2+
Blink Interactive Tutorial
3+
##########################
4+
5+
Introduction
6+
------------
7+
8+
This is the interactive blink tutorial using `Wokwi`_. For this tutorial, you don't need the ESP32 board or the Arduino toolchain.
9+
10+
.. note:: If you don't want to use this tutorial with the simulation, you can copy and paste the :ref:`blink_example_code` from `Wokwi`_ editor and use it on the `Arduino IDE`_ or `PlatformIO`_.
11+
12+
About this Tutorial
13+
-------------------
14+
15+
This tutorial is the most basic for any get started. In this tutorial, we will show how to set a GPIO pin as an output to drive a LED to blink each 1 second.
16+
17+
Step by step
18+
------------
19+
20+
In order to make this simple blink tutorial, you'll need to do the following steps.
21+
22+
1. **Define the GPIO for the LED.**
23+
24+
.. code-block::
25+
26+
#define LED 2
27+
28+
This ``#define LED 2`` will be used to set the GPIO2 as the ``LED`` output pin.
29+
30+
2. **Setup.**
31+
32+
Inside the ``setup()`` function, we need to add all things we want to run once during the startup.
33+
Here we'll add the ``pinMode`` function to set the pin as output.
34+
35+
.. code-block::
36+
37+
void setup() {
38+
pinMode(LED, OUTPUT);
39+
}
40+
41+
The first argument is the GPIO number, already defined and the second is the mode, here defined as an output.
42+
43+
3. **Main Loop.**
44+
45+
After the ``setup``, the code runs the ``loop`` function infinitely. Here we will handle the GPIO in order to get the LED blinking.
46+
47+
.. code-block::
48+
49+
void loop() {
50+
digitalWrite(LED, HIGH);
51+
delay(100);
52+
digitalWrite(LED, LOW);
53+
delay(100);
54+
}
55+
56+
The first function is the ``digitalWrite()`` with two arguments:
57+
58+
* GPIO: Set the GPIO pin. Here defined by our ``LED`` connected to the GPIO2.
59+
* State: Set the GPIO state as HIGH (ON) or LOW (OFF).
60+
61+
This first ``digitalWrite`` we will set the LED ON.
62+
63+
After the ``digitalWrite``, we will set a ``delay`` function in order to wait for some time, defined in milliseconds.
64+
65+
Now we can set the GPIO to ``LOW`` to turn the LED off and ``delay`` for more few milliseconds to get the LED blinking.
66+
67+
4. **Run the code.**
68+
69+
To run this code, you'll need a development board and the Arduino toolchain installed on your computer. If you don't have both, you can use the simulator to test and edit the code.
70+
71+
Simulation
72+
----------
73+
74+
This simulator is provided by `Wokwi`_ and you can test the blink code and play with some modifications to learn more about this example.
75+
76+
.. raw:: html
77+
78+
<iframe src="https://wokwi.com/arduino/projects/305566932847821378?embed=1" width="100%" height="400" border="0"></iframe>
79+
80+
Change the parameters, like the delay period, to test the code right on your browser. You can add more LEDs, change the GPIO, and more.
81+
82+
.. _blink_example_code:
83+
84+
Example Code
85+
------------
86+
87+
Here is the full blink code.
88+
89+
.. code-block::
90+
91+
#define LED 2
92+
93+
void setup() {
94+
pinMode(LED, OUTPUT);
95+
}
96+
97+
void loop() {
98+
digitalWrite(LED, HIGH);
99+
delay(100);
100+
digitalWrite(LED, LOW);
101+
delay(100);
102+
}
103+
104+
Resources
105+
---------
106+
107+
* `ESP32 Datasheet`_ (Datasheet)
108+
* `Wokwi`_ (Wokwi Website)
109+
110+
.. _ESP32 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf
111+
.. _Wokwi: https://wokwi.com/
112+
.. _PlatformIO: https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html#platformio
113+
.. _Arduino IDE: https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html#installing-using-boards-manager

Diff for: docs/source/tutorials/tutorials.rst

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Tutorials
66
:maxdepth: 2
77
:caption: Tutorials:
88

9+
Blink <blink>
910
Basic <basic>
1011
DFU <dfu>
1112
GPIO Matrix and Pin Mux <io_mux>

0 commit comments

Comments
 (0)