Skip to content

Commit b5f3d6c

Browse files
authored
Update doc: Arduino as IDF component; fixes #5833 (#6299)
Summary Updated documentation describing the usage of Arduino-esp32 core as ESP-IDF component. Impact Removed confusing mentions of advanced menuconfig options. Extended process of installation, setup, and usage. Related links Closes #5833
1 parent d5e8c9d commit b5f3d6c

File tree

1 file changed

+71
-32
lines changed

1 file changed

+71
-32
lines changed

Diff for: docs/source/esp-idf_component.rst

+71-32
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1-
##############################
2-
Arduino as a ESP-IDF component
3-
##############################
1+
###############################
2+
Arduino as an ESP-IDF component
3+
###############################
4+
5+
This method is recommended for advanced users. To use this method, you will need to have the ESP-IDF toolchain installed.
6+
7+
For a simplified method, see `Installing using Boards Manager <https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html#installing-using-boards-manager>`_.
48

59
ESP32 Arduino lib-builder
610
-------------------------
711

8-
For a simplified method, see `lib-builder <https://github.com/espressif/esp32-arduino-lib-builder>`_.
12+
If you don't need any modifications in the default Arduino ESP32 core, we recommend you to install using the Boards Manager.
13+
14+
Arduino Lib Builder is the tool that integrates ESP-IDF into Arduino. It allows you to customize the default settings used by Espressif and try them in Arduino IDE.
15+
16+
For more information see `Arduino lib builder <https://github.com/espressif/esp32-arduino-lib-builder>`_
17+
918

1019
Installation
1120
------------
1221

13-
.. note:: Latest Arduino Core ESP32 version is now compatible with `ESP-IDF v4.4 <https://github.com/espressif/esp-idf/tree/release/v4.4>`_. Please consider this compability when using Arduino as component in ESP-IDF.
22+
.. note:: Latest Arduino Core ESP32 version is now compatible with `ESP-IDF v4.4 <https://github.com/espressif/esp-idf/tree/release/v4.4>`_. Please consider this compatibility when using Arduino as a component in ESP-IDF.
23+
24+
#. Download and install `ESP-IDF <https://github.com/espressif/esp-idf>`_.
1425

15-
- Download and install `ESP-IDF <https://github.com/espressif/esp-idf>`_.
16-
- Create blank ESP-IDF project (use sample_project from /examples/get-started) or choose one of the examples.
17-
- In the project folder, create a new folder called `components` and clone this repository inside the new created folder.
26+
* For more information see `Get Started <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html#installation-step-by-step>`_.
27+
#. Create a blank ESP-IDF project (use sample_project from /examples/get-started) or choose one of the examples.
28+
#. In the project folder, create a new folder called ``components`` and clone this repository inside the newly created folder.
1829

1930
.. code-block:: bash
2031
@@ -26,27 +37,44 @@ Installation
2637
cd ../.. && \
2738
idf.py menuconfig
2839
40+
Configuration
41+
-------------
42+
43+
Depending on one of the two following options, in the menuconfig set the appropriate settings.
44+
45+
Go to the section ``Arduino Configuration --->``
46+
47+
1. For usage of ``app_main()`` function - Turn off ``Autostart Arduino setup and loop on boot``
48+
2. For usage of ``setup()`` and ``loop()`` functions - Turn on ``Autostart Arduino setup and loop on boot``
49+
50+
Experienced users can explore other options in the Arduino section.
51+
52+
After the setup you can save and exit:
53+
54+
- Save [S]
55+
- Confirm default filename [Enter]
56+
- Close confirmation window [Enter] or [Space] or [Esc]
57+
- Quit [Q]
58+
2959
Option 1. Using Arduino setup() and loop()
3060
******************************************
3161

32-
- The `idf.py menuconfig` has some Arduino options.
33-
- Turn on `Autostart Arduino setup and loop on boot`.
34-
- In main folder rename file `main.c` to `main.cpp`.
35-
- In main folder open file `CMakeList.txt` and change `main.c` to `main.cpp` as described below.
36-
37-
.. code-block:: bash
62+
- In main folder rename file `main.c` to `main.cpp`.
3863

39-
idf_component_register(SRCS "main.cpp" INCLUDE_DIRS ".")
64+
- In main folder open file `CMakeList.txt` and change `main.c` to `main.cpp` as described below.
4065

41-
- Your main.cpp should be formated like any other sketch.
66+
- Your main.cpp should be formatted like any other sketch.
4267

4368
.. code-block:: c
4469
4570
//file: main.cpp
4671
#include "Arduino.h"
4772
4873
void setup(){
49-
Serial.begin(115200);
74+
Serial.begin(115200);
75+
while(!Serial){
76+
; // wait for serial port to connect
77+
}
5078
}
5179
5280
void loop(){
@@ -57,10 +85,10 @@ Option 1. Using Arduino setup() and loop()
5785
Option 2. Using ESP-IDF appmain()
5886
*********************************
5987

60-
- You need to implement ``app_main()`` and call ``initArduino();`` in it.
88+
In main.c or main.cpp you need to implement ``app_main()`` and call ``initArduino();`` in it.
6189

6290
Keep in mind that setup() and loop() will not be called in this case.
63-
If you plan to base your code on examples provided in `examples <https://github.com/espressif/esp-idf/tree/master/examples>`_, please make sure to move the app_main() function in main.cpp from the files in the example.
91+
Furthermore the ``app_main()`` is single execution as a normal function so if you need an infinite loop as in Arduino place it there.
6492

6593
.. code-block:: cpp
6694
@@ -69,28 +97,39 @@ If you plan to base your code on examples provided in `examples <https://github.
6997
7098
extern "C" void app_main()
7199
{
72-
initArduino();
73-
pinMode(4, OUTPUT);
74-
digitalWrite(4, HIGH);
75-
//do your own thing
76-
}
100+
initArduino();
101+
102+
// Arduino-like setup()
103+
Serial.begin(115200);
104+
while(!Serial){
105+
; // wait for serial port to connect
106+
}
107+
108+
// Arduino-like loop()
109+
while(true){
110+
Serial.println("loop");
111+
}
77112
78-
- "Disable mutex locks for HAL"
79-
- If enabled, there will be no protection on the drivers from concurently accessing them from another thread/interrupt/core
80-
- "Autoconnect WiFi on boot"
81-
- If enabled, WiFi will start with the last known configuration
82-
- Otherwise it will wait for WiFi.begin
113+
// WARNING: if program reaches end of function app_main() the MCU will restart.
114+
}
83115
84116
Build, flash and monitor
85117
************************
86118

87119
- For both options use command ``idf.py -p <your-board-serial-port> flash monitor``
88-
- It will build, upload and open serial monitor to your board.
120+
121+
- The project will build, upload and open the serial monitor to your board
122+
123+
- Some boards require button combo press on the board: press-and-hold Boot button + press-and-release RST button, release Boot button
124+
125+
- After a successful flash, you may need to press the RST button again
126+
127+
- To terminate the serial monitor press [Ctrl] + [ ] ]
89128

90129
Logging To Serial
91130
-----------------
92131

93-
If you are writing code that does not require Arduino to compile and you want your `ESP_LOGx` macros to work in Arduino IDE, you can enable the compatibility by adding the following lines after:
132+
If you are writing code that does not require Arduino to compile and you want your `ESP_LOGx` macros to work in Arduino IDE, you can enable the compatibility by adding the following lines:
94133

95134
.. code-block:: c
96135
@@ -107,4 +146,4 @@ To fix that behavior, you need to set FreeRTOS tick rate to 1000Hz in `make menu
107146
Compilation Errors
108147
------------------
109148

110-
As commits are made to esp-idf and submodules, the codebases can develop incompatibilities which cause compilation errors. If you have problems compiling, follow the instructions in `Issue #1142 <https://github.com/espressif/arduino-esp32/issues/1142>`_ to roll esp-idf back to a different version.
149+
As commits are made to esp-idf and submodules, the codebases can develop incompatibilities that cause compilation errors. If you have problems compiling, follow the instructions in `Issue #1142 <https://github.com/espressif/arduino-esp32/issues/1142>`_ to roll esp-idf back to a different version.

0 commit comments

Comments
 (0)