{"id":12177,"date":"2021-07-23T11:03:30","date_gmt":"2021-07-23T11:03:30","guid":{"rendered":"https:\/\/wolles-elektronikkiste.de\/programming-the-esp32-with-arduino-code"},"modified":"2024-10-29T14:37:23","modified_gmt":"2024-10-29T14:37:23","slug":"programming-the-esp32-with-arduino-code","status":"publish","type":"post","link":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code","title":{"rendered":"Programming the ESP32 with Arduino Code"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">About this post<\/h2>\n\n<p>After I reported in <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/how-to-use-the-i2c-interfaces-of-the-esp32\" target=\"_blank\" rel=\"noopener\">my penultimate post<\/a> about the I2C interfaces of the ESP32, I would like to give a complete overview of this powerful microcontroller.<\/p>\r\n\r\n<p>Everything I discuss here has basically been described more than once by someone else. So, why another article on this topic? It is an attempt to summarize the basic functions, peculiarities and stumbling blocks in a single post. In particular, I am addressing Arduino users who want to get into the ESP32. But maybe also the ESP32-experienced will find one or the other interesting information here.<\/p>\r\n\r\n<p>In my explanations and examples, I mainly refer to the widely used ESP32-WROOM-32, or the boards based on it. However, most of it can be applied to other ESP32 boards, such as the ESP32-PICO.<\/p>\n\n<p>The article has become quite long &#8211; here you can jump to the sections:<\/p>\r\n<ul>\r\n<li><a href=\"#ESP32_Boards\">ESP32 Boards<\/a><\/li>\r\n<li><a href=\"#properties\">Features of the ESP32-WROOM-32<\/a><\/li>\r\n<li><a href=\"#Arduino_IDE\">Integration of the ESP32 into the Arduino IDE<\/a><\/li>\r\n<li><a href=\"#pinout\">Pinout of the ESP32 Development Board<\/a><\/li>\r\n<li><a href=\"#digital_pins\">Digital inputs\/outputs<\/a><\/li>\r\n<li><a href=\"#analog_pins\">Analog inputs\/outputs<\/a><\/li>\r\n<li><a href=\"#PWM\">Pulse Width Modulation (PWM)<\/a><\/li>\r\n<li><a href=\"#I2C\">I2C<\/a><\/li>\r\n<li><a href=\"#SPI\">SPI<\/a><\/li>\r\n<li><a href=\"#UART\">Serial Interfaces (UART)<\/a><\/li>\r\n<li><a href=\"#touch\">Touch Pins<\/a><\/li>\r\n<li><a href=\"#hall\">Hall Sensor<\/a><\/li>\r\n<li><a href=\"#interrupts\">Interrupts<\/a><\/li>\r\n<li><a href=\"#strom\">Saving power \/ Sleep modes<\/a><\/li>\r\n<li><a href=\"#wifi\">WiFi<\/a><\/li>\r\n<li><a href=\"#bluetooth\">Bluetooth<\/a><\/li>\r\n<li><a href=\"#exotisch\">Exotic pin functions<\/a><a id=\"ESP32_Boards\"><\/a><\/li>\r\n<li><a href=\"#api\">The APIs (Application Programming Interfaces)<\/a><\/li>\r\n<\/ul>\r\n\n<h2 class=\"wp-block-heading\" id=\"ESP32_Boards\">ESP32 Boards<\/h2>\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<figure class=\"wp-block-gallery has-nested-images columns-4 wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2274\" height=\"1167\" data-id=\"12031\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32.jpg\" alt=\"\" class=\"wp-image-12031\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32.jpg 2274w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32-300x154.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32-1024x526.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32-768x394.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32-1536x788.jpg 1536w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32-2048x1051.jpg 2048w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32-1320x677.jpg 1320w\" sizes=\"auto, (max-width: 2274px) 100vw, 2274px\" \/><\/a><figcaption class=\"wp-element-caption\">Dev Module <\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_Ard_Style.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2000\" height=\"1418\" data-id=\"12033\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_Ard_Style.jpg\" alt=\"\" class=\"wp-image-12033\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_Ard_Style.jpg 2000w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_Ard_Style-300x213.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_Ard_Style-1024x726.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_Ard_Style-768x545.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_Ard_Style-1536x1089.jpg 1536w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_Ard_Style-1320x936.jpg 1320w\" sizes=\"auto, (max-width: 2000px) 100vw, 2000px\" \/><\/a><figcaption class=\"wp-element-caption\">D1 R32<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_small.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1586\" height=\"1216\" data-id=\"12035\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_small.jpg\" alt=\"\" class=\"wp-image-12035\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_small.jpg 1586w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_small-300x230.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_small-1024x785.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_small-768x589.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_small-1536x1178.jpg 1536w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_small-1320x1012.jpg 1320w\" sizes=\"auto, (max-width: 1586px) 100vw, 1586px\" \/><\/a><figcaption class=\"wp-element-caption\">Mini Board<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_pico.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2166\" height=\"960\" data-id=\"12037\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_pico.jpg\" alt=\"\" class=\"wp-image-12037\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_pico.jpg 2166w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_pico-300x133.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_pico-1024x454.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_pico-768x340.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_pico-1536x681.jpg 1536w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_pico-2048x908.jpg 2048w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_pico-1320x585.jpg 1320w\" sizes=\"auto, (max-width: 2166px) 100vw, 2166px\" \/><\/a><figcaption class=\"wp-element-caption\">Pico Kit<\/figcaption><\/figure>\n<\/figure>\n\n\n\n<p>There are various ESP32 boards. Most are based on the ESP32-WROOM-32.&nbsp; Very popular are the development boards like the model shown above left. However, it has a width that is not ideal for breadboards because you only have space left on one side for jumper cables (see below). If you place two breadboards next to each other, the modules will not be wide enough to bridge the +\/- bars. This may be a luxury problem, but it&#8217;s annoying. As a solution, I recommend multi-breadboards that have only one +\/- bar between each board.<\/p>\r\n<\/div><\/div>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_on_breadboard-1024x442.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"442\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_on_breadboard-1024x442.jpg\" alt=\"Not all ESP32 modules fit on all breadboards\" class=\"wp-image-11988\" style=\"width:768px;height:332px\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_on_breadboard-1024x442.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_on_breadboard-300x130.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_on_breadboard-768x332.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_on_breadboard-1536x663.jpg 1536w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_on_breadboard-2048x884.jpg 2048w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_on_breadboard-1320x570.jpg 1320w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Not all ESP32 modules harmonize in size with all breadboards<\/figcaption><\/figure>\n<\/div>\n<p>Alternatively, you can also use the &#8220;Arduino UNO-like&#8221; D1 R32 board. Or you can take an ESP32 Pico because it is a bit smaller.<a id=\"properties\"><\/a><\/p>\r\n\n<h2 class=\"wp-block-heading\">Features of the ESP32-WROOM-32<\/h2>\n\n<p>The performance of the ESP32 boards makes AVR-based Arduinos like the UNO look old. The four to twelve times higher clock rate and a comparatively huge flash memory are another dimension. A clear advantage for the Arduino (AVR) boards, however, is that the underlying microcontrollers can be easily operated <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/using-the-atmega328p-standalone\" target=\"_blank\" rel=\"noopener\">standalone<\/a>. This allows space and energy saving projects to be realized. Wiring a bare ESP32, on the other hand, is not necessarily what most people like.<\/p>\r\n<p>Here is an overview of the most important data of the ESP32-WROOM-32:<\/p>\r\n<ul>\r\n<li><strong>Operating voltage<\/strong>: 3.3 volts<\/li>\r\n<li><strong>Power consumption<\/strong>: 1\u03bcA (hibernation) to max ~240 mA\r\n<ul>\r\n<li>the power consumption depends on the mode and the activated components<\/li>\r\n<li>in normal operation without WiFi and Bluetooth: approx. 50-70 mA<\/li>\r\n<\/ul>\r\n<\/li>\r\n<li><strong>Clock rate<\/strong> up to 240 MHz<\/li>\r\n<li>520 kByte internal <strong>SRAM<\/strong> (for data and commands)<\/li>\r\n<li>External <strong>flash memory<\/strong> up to 16 MByte\r\n<ul>\r\n<li>most modules have 4 MByte memory, of which about 1 MByte &#8220;for free use&#8221;<\/li>\r\n<\/ul>\r\n<\/li>\r\n<li>34 <strong>inputs\/outputs<\/strong>:\r\n<ul>\r\n<li>usable: 22 GPIOs, 4 GPIs (input only)<\/li>\r\n<li>some have certain limitations<\/li>\r\n<\/ul>\r\n<\/li>\r\n<li>2 <strong>I2C<\/strong> interfaces<\/li>\r\n<li>2 usable <strong>SPI<\/strong> interfaces<\/li>\r\n<li>3 <strong>UART<\/strong> interfaces<\/li>\r\n<li><strong>Real time clock<\/strong><\/li>\r\n<li>10 <strong>touch sensors<\/strong><\/li>\r\n<li>Integrated <strong>Hall sensor<\/strong><\/li>\r\n<li>16 <strong>PWM<\/strong> channels<\/li>\r\n<li>2 &#8220;real&#8221; <strong>analog outputs<\/strong><\/li>\r\n<li>Up to 18 <strong> analog inputs<\/strong><\/li>\r\n<li><strong>WiFi:<\/strong> 802.11 b\/g\/n 2.4 GHz<\/li>\r\n<li><strong>Bluetooth<\/strong>: 4.2 \/ BLE (Bluetooth Low Energy)<a id=\"Arduino_IDE\"><\/a><\/li>\r\n<\/ul>\r\n\n<h2 class=\"wp-block-heading\">Integration of the ESP32 into the Arduino IDE<\/h2>\n\n<p>How to make the Arduino IDE ESP32-capable has been described endlessly. Therefore, I will be brief.<\/p>\r\n<ol>\r\n<li>In the Arduino IDE, go to File &#8211; &gt; Preferences.<\/li>\r\n<li>There you click on the small icon behind &#8220;Additional Boards Manager URLs&#8221;.<\/li>\r\n<li>Enter &#8220;https:\/\/dl.espressif.com\/dl\/package_esp32_index.json&#8221; as a separate line (without quotation marks).<\/li>\r\n<li>Go to Tools &#8211; &gt; Board &#8211; &gt; Boards Manager.<\/li>\r\n<li>Search for &#8220;esp32&#8221; and install &#8220;esp32 by Espressif Systems&#8221;.<\/li>\r\n<li>You may need to restart the Arduino IDE.<\/li>\r\n<\/ol>\r\n<p>After installation you will find several dozen ESP32 boards to choose from. You have to see which one fits. The &#8220;ESP32 Dev Module&#8221; is widely used. <a id=\"pinout\"><\/a><\/p>\r\n\n<h2 class=\"wp-block-heading\">Pinout of the ESP32 Development Board<\/h2>\n\n<p>There are different versions of ESP32-WROOM-32 based boards. This means that the pins on your board may be arranged differently, and some pins may also be missing. But what always matches is the multiple function of the pins. This means, for example, that GPIO4 is always HSPI_HD, ADC2_CH0, TOUCH_0 and RTC_IO 10.<\/p>\r\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ESP32_dev_board_pinout-1024x497.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"497\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ESP32_dev_board_pinout-1024x497.jpg\" alt=\"Pins of the ESP32 Development Board\" class=\"wp-image-11901\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ESP32_dev_board_pinout-1024x497.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ESP32_dev_board_pinout-300x146.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ESP32_dev_board_pinout-768x373.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ESP32_dev_board_pinout-1536x746.jpg 1536w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ESP32_dev_board_pinout-2048x994.jpg 2048w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ESP32_dev_board_pinout-1320x641.jpg 1320w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Pins of the ESP32 Development Board<\/figcaption><\/figure>\n\n<h3 class=\"wp-block-heading\">&#8220;Forbidden&#8221; \/ Restricted Pins<\/h3>\n\n<p>Some pins have certain restrictions, others should be left unconnected. The latter group includes the pins <strong>GPIO6 to GPIO11<\/strong>. They are used internally for SPI communication with the flash memory. That is why I have marked them in grey. Just ignore them.<\/p>\r\n<p>While the ESP32 boots, some of its pins send PWM signals or go into HIGH state for short time. Depending on what you attach to the pins, this can interfere, but it does not have to. These are the pins <strong>GPIO0, GPIO1, GPIO3, GPIO5, GPIO14 and GPIO15<\/strong>.<\/p>\r\n<p><strong>GPIO0, GPIO2, GPIO4, GPIO5, GPIO12 and GPIO15 <\/strong>are so-called &#8220;strapping pins&#8221; that bring the ESP32 into bootloader or flash mode while booting. If you connect something to it during boot which pull the pins into the HIGH or LOW state, this can lead to unexpected behavior. You may know this from the GPIO0 pin of the <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/esp8266-esp-01-module\" target=\"_blank\" rel=\"noopener\">ESP8266 ESP-01<\/a>.<\/p>\r\n<p>The <strong>ADC2_CHx<\/strong> pins cannot be used as analog inputs when WiFi is active.<a id=\"digital_pins\"><\/a><\/p>\r\n\n<h2 class=\"wp-block-heading\">Digital inputs\/outputs of the ESP32<\/h2>\n\n<p>Using the GPIOs as digital inputs and outputs works essentially the same as with the Arduino with the functions <code>pinMode()<\/code> , <code>digitalWrite()<\/code> and <code>digitalRead()<\/code>. If you normally work with Arduino (AVR) boards, you have to get used to the lower voltage of 3.3 volts. The maximum current should not exceed 12 mA.<\/p>\r\n<p>There is an important difference to the Arduino in the operation of the GPIOs as an input. To achieve a LOW level at a pin when using <code>pinMode(pin, INPUT)<\/code>, you must use an external pull-down resistor with the Arduino. With the ESP32, however, you can connect an internal pull-down resistor via <code>INPUT_PULLDOWN<\/code>. If you just choose <code>INPUT<\/code>, then the pin level is undefined.<\/p>\r\n<p>The pins GPIO34-39 are pure inputs, which is why the name GPI is more appropriate. In addition, there is no internal pull-up or pull-down resistor available on these pins.<a id=\"analog_pins\"><\/a><\/p>\r\n\n<h2 class=\"wp-block-heading\">Analog inputs\/outputs of the ESP32<\/h2>\n\n<h3 class=\"wp-block-heading\">Analog inputs<\/h3>\n\n<p>The ESP32 has two A\/D converters with a resolution of 12 bits. The ADC1 and ADC2 inputs each share one A\/D converter. With <code>analogRead(pin)<\/code> you read the measured values like with the Arduino. The voltage U is (theoretically):<\/p>\r\n\n<p><\/p>\r\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 40px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/ql-cache\/quicklatex.com-0cb85d05dca5b0189ddde7c120cbac41_l3.png\" height=\"40\" width=\"219\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91; &#85;&#92;&#59;&#92;&#116;&#101;&#120;&#116;&#123;&#91;&#86;&#93;&#125;&#32;&#61;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#51;&#46;&#51;&#32;&#92;&#99;&#100;&#111;&#116;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#97;&#110;&#97;&#108;&#111;&#103;&#82;&#101;&#97;&#100;&#40;&#41;&#125;&#125;&#123;&#52;&#48;&#57;&#54;&#125; &#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\r\n\n<p>As excellent as the ESP32&#8217;s performance is otherwise, the A\/D converters definitely are not:<\/p>\r\n<ol>\r\n<li>The scatter of the measured values is very high.<\/li>\r\n<li>Even worse, the results are not linear.<\/li>\r\n<\/ol>\r\n<p>The scatter is something you can get under control. Espressif recommends (<a href=\"https:\/\/docs.espressif.com\/projects\/esp-idf\/en\/v4.2-beta1\/esp32\/api-reference\/peripherals\/adc.html#minimizing-noise\" target=\"_blank\" rel=\"noopener\">here<\/a>) connecting a 0.1 \u00b5F capacitor to the input and averaging the readings. Without a capacitor, I had to average 500 &#8211; 1000 readings to get the variation below 0.01 volts.<\/p>\r\n<p>The non-linearity is a bigger problem. I have checked this out and my findings are consistent with what I have found in other articles:<\/p>\r\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ADC_ESP32_reliability-1024x626.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"626\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ADC_ESP32_reliability-1024x626.png\" alt=\"ESP32 A\/D Converter Readings vs. Actual Voltage\" class=\"wp-image-11916\" style=\"width:768px;height:470px\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ADC_ESP32_reliability-1024x626.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ADC_ESP32_reliability-300x183.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ADC_ESP32_reliability-768x469.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/ADC_ESP32_reliability.png 1265w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">ESP32 A\/D Converter Readings vs. Actual Voltage<\/figcaption><\/figure>\n<\/div>\n<p>Some people recommend using &#8220;look-up&#8221; tables to compensate for the error (e.g. <a href=\"https:\/\/github.com\/e-tinkers\/esp32-adc-calibrate\" target=\"_blank\" rel=\"noopener\">here<\/a> on GitHub), others recommend regression polynomials (e.g. <a href=\"https:\/\/hackaday.io\/project\/27511-microfluidics-control-system\/log\/69406-adc-dac-calibration\" target=\"_blank\" rel=\"noopener\">here<\/a>). If you need accurate readings, I recommend using a reasonable external A\/D converter like the <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/ads1115-a-d-converter-with-amplifier\" target=\"_blank\" rel=\"noopener\">ADS1115<\/a>.<\/p>\r\n\n<h3 class=\"wp-block-heading\">Analog outputs<\/h3>\n\n<h4 class=\"wp-block-heading\">analogWrite()<\/h4>\n\n<p>The <code>analogWrite()<\/code> function is available at all output pins. As you are used to with the Arduino, values between 0 and 255 are available. The underlying PWM frequency is 1 kHz. <\/p>\r\n\n<h4 class=\"wp-block-heading\">The dacWrite function<\/h4>\n\n<p>In addition to <code>analogWrite()<\/code>, you can use <code>dacWrite()<\/code> on the ESP32. It provides a true analog signal between 0 and 3.3 volts, which can be output at the two DAC pins. To call the function:<\/p>\r\n<p><code>dacWrite(pin, value)<\/code> with pin = 25 or 26 and value = 0, 1, 2 &#8230;. 255.<\/p>\r\n<p>Theoretically, the voltage U is:<\/p>\r\n\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 39px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/ql-cache\/quicklatex.com-39d6d09d0fe7d789cb7d4901d66b83be_l3.png\" height=\"39\" width=\"160\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91; &#85;&#92;&#59;&#92;&#116;&#101;&#120;&#116;&#123;&#91;&#86;&#93;&#125;&#61;&#92;&#102;&#114;&#97;&#99;&#123;&#51;&#46;&#51;&#125;&#123;&#50;&#53;&#53;&#125;&#92;&#99;&#100;&#111;&#116;&#32;&#118;&#97;&#108;&#117;&#101; &#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\r\n\n<p>Practically, it looks like this:<\/p>\r\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/DAC_ESP32__reliability-1024x608.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"608\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/DAC_ESP32__reliability-1024x608.png\" alt=\"Theoretical and actual voltage at the DAC pins of the ESP32\" class=\"wp-image-11922\" style=\"width:768px;height:456px\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/DAC_ESP32__reliability-1024x608.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/DAC_ESP32__reliability-300x178.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/DAC_ESP32__reliability-768x456.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/DAC_ESP32__reliability.png 1313w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Theoretical and actual voltage at the DAC pins<\/figcaption><\/figure>\n<\/div>\n<p>The minimum value in my measurements was 0.086 volts, the maximum value was 3.18 volts. After all, the slope is largely linear, so you can apply a calibration line.<a id=\"PWM\"><\/a><\/p>\r\n\n<h2 class=\"wp-block-heading\">Pulse Width Modulation (PWM)<\/h2>\n\n<p>A detailed introduction to pulse width modulation (PWM) would go beyond the scope of this article. In a nutshell: PWM is used, among other things, to control servo motors or to dim LEDs. A PWM signal is a square wave signal with a defined frequency (= 1\/period) and a defined duty cycle. Here is an example of a signal with 25% duty cycle:<\/p>\r\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/PWM_scheme_dc25-1024x416.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"416\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/PWM_scheme_dc25-1024x416.png\" alt=\"\" class=\"wp-image-11930\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/PWM_scheme_dc25-1024x416.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/PWM_scheme_dc25-300x122.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/PWM_scheme_dc25-768x312.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/PWM_scheme_dc25-1320x536.png 1320w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/06\/PWM_scheme_dc25.png 1491w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">PWM signal with 25% duty cycle<\/figcaption><\/figure>\n\n<p>The ESP32 has 16 PWM channels that can be assigned to the GPIO pins. However, the inputs GPI32 &#8211; GPI39 cannot be used for PWM. The basic setting of the PWM signal is applied with <code>edcAttach(pin, freq, res)<\/code>. <code>pin<\/code> is the GPIO-Pin, <code>freq<\/code> is the frequency and <code>res<\/code> is the resolution in bit. Alternatively, you set the channel yourself with <code>ledcAttachChannel(pin, freq, res, channel)<\/code>.<\/p>\r\n<p>You start the signal output and set the duty cycle with <code>ledcWrite(pin, dutyCycle)<\/code>. The duty cycle in percent is dutyCycle\/2<sup>res<\/sup> x 100.\r\n<\/p>\r\n<p>Here is a small example sketch that periodically dims and lights up an LED attached to GPIO18.<\/p>\r\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"ESP32_pwm_led_dim.ino\" data-enlighter-title=\"ESP32_pwm_led_dim.ino\">const int pwmPin = 18;  \/\/ = GPIO18\r\nconst int freq = 1000;\r\nconst int pwmChannel = 0; \/\/ choose 0 - 15\r\nconst int res = 8; \/\/ 2^8 = 256\r\n \r\nvoid setup(){\r\n  ledcAttach(pwmPin, freq, res); \/\/ channel is chosen automatically\r\n  \/\/ ledcAttachChannel(pwmPin, freq, res, pwmChannel); \/\/ choose channel youself\r\n}\r\n \r\nvoid loop(){\r\n  for(int dutyCycle = 0; dutyCycle &lt;= 256; dutyCycle++){   \r\n    ledcWrite(pwmPin, dutyCycle);\r\n    delay(3);\r\n  }\r\n  for(int dutyCycle = 256; dutyCycle &gt;= 0; dutyCycle--){\r\n    ledcWrite(pwmPin, dutyCycle);   \r\n    delay(3);\r\n  }\r\n}<\/pre>\r\n\n<p>Now I briefly come back to the <code>analogWrite()<\/code> function. When using an Arduino, <code>analogWrite()<\/code> generates a PWM signal of 490 Hz and a resolution of 8 bits on most pins (see <a href=\"https:\/\/www.arduino.cc\/reference\/en\/language\/functions\/analog-io\/analogwrite\/\" target=\"_blank\" rel=\"noopener\">here<\/a> on the Arduino pages). With <code>ledcAttach(pin, 490, 8)<\/code>, you can easily do the same.<\/p>\r\n\n<h3 class=\"wp-block-heading\">Maximum PWM resolution and frequency<\/h3>\n\n<p>You can select values between 1 and 15 bits as resolution. The resolution and the internal timer frequency (80 MHz) determine the maximum frequency of the PWM signal:<\/p>\r\n\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 39px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/ql-cache\/quicklatex.com-622d38fcdb10280401ecfbb0efc30c28_l3.png\" height=\"39\" width=\"652\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91; &#102;&#95;&#123;&#92;&#116;&#101;&#120;&#116;&#123;&#109;&#97;&#120;&#125;&#125;&#61;&#92;&#102;&#114;&#97;&#99;&#123;&#56;&#48;&#48;&#48;&#48;&#48;&#48;&#48;&#125;&#123;&#50;&#94;&#92;&#116;&#101;&#120;&#116;&#123;&#40;&#114;&#101;&#115;&#32;&#105;&#110;&#32;&#98;&#105;&#116;&#41;&#125;&#125;&#32;&#92;&#59;&#92;&#59;&#92;&#59;&#92;&#59;&#92;&#59;&#92;&#59;&#92;&#116;&#101;&#120;&#116;&#123;&#122;&#46;&#66;&#46;&#58;&#125;&#92;&#59;&#92;&#59;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#114;&#101;&#115;&#125;&#32;&#61;&#32;&#49;&#48;&#92;&#59;&#92;&#116;&#101;&#120;&#116;&#123;&#66;&#105;&#116;&#125;&#92;&#59;&#92;&#59;&#92;&#59;&#32;&#61;&#62;&#92;&#59;&#92;&#59;&#92;&#59;&#102;&#95;&#123;&#92;&#116;&#101;&#120;&#116;&#123;&#109;&#97;&#120;&#125;&#125;&#61;&#92;&#102;&#114;&#97;&#99;&#123;&#56;&#48;&#48;&#48;&#48;&#48;&#48;&#48;&#125;&#123;&#50;&#94;&#123;&#49;&#48;&#125;&#125;&#61;&#32;&#55;&#56;&#49;&#50;&#53;&#92;&#59;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#91;&#72;&#122;&#93;&#125; &#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\r\n\n<p>As an extreme example, you choose a resolution of one bit. This sets the duty cycle to 50% and the maximum frequency is 40 MHz. In this range, my oscilloscope is at its limit and therefore the signal is not very sharp. <\/p>\r\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/pwm_40mhz_78_125_khz-1024x324.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"324\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/pwm_40mhz_78_125_khz-1024x324.png\" alt=\"PWM with the ESP32 - left: 78125 Hz, right: 40 MHz\" class=\"wp-image-11937\" style=\"width:840px;height:265px\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/pwm_40mhz_78_125_khz-1024x324.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/pwm_40mhz_78_125_khz-300x95.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/pwm_40mhz_78_125_khz-768x243.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/pwm_40mhz_78_125_khz-1536x486.png 1536w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/pwm_40mhz_78_125_khz-1320x417.png 1320w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/pwm_40mhz_78_125_khz.png 1629w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">PWM with the ESP32 &#8211; left: 78125 Hz, right: 40 MHz, Duty Cyle: 50%<\/figcaption><\/figure>\n\n<p>A friendly reader (thanks to Stefan Gro\u00df), has measured the signal with his more professional equipment (active probe, 1 GHz, 10:1): <a id=\"I2C\"><\/a><\/p>\r\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2022\/01\/RT-ZS10L_kurzer-GND-Anschluss.png\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"520\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2022\/01\/RT-ZS10L_kurzer-GND-Anschluss.png\" alt=\"40 MHz PWM - measured with a better oscilloscope\" class=\"wp-image-13423\" style=\"width:480px;height:390px\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2022\/01\/RT-ZS10L_kurzer-GND-Anschluss.png 640w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2022\/01\/RT-ZS10L_kurzer-GND-Anschluss-300x244.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><figcaption class=\"wp-element-caption\">40 MHz PWM &#8211; measured with a better oscilloscope<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">Using the I2C interfaces of the ESP32<\/h2>\n\n<p>In contrast to the Arduino (UNO), the ESP32 has two I2C interfaces. The standard interface is assigned to GPIO21 and GPIO22. If you use the default, the operation is the same as with the Arduino. This means that you include the <code>Wire.h<\/code> library and use its functions as usual.<\/p>\r\n<p>But you have to keep in mind that the ESP32 voltage is 3.3 volts. If you connect a 5 volt device via I2C, you should apply a level shifter or voltage divider. Of course, this also applies to SPI and UART. The pins are not tolerant to 5 volts.<\/p>\r\n<p>Another difference is that you can assign the I2C interface to other GPIOs. How to do this, how to use the second I2C interface and how to pass the corresponding TwoWire objects to other objects, I have described <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/how-to-use-the-i2c-interfaces-of-the-esp32\" target=\"_blank\" rel=\"noopener\">here<\/a> in great detail. That is why I will not go into it in more detail.<a id=\"SPI\"><\/a><\/p>\r\n\n<h2 class=\"wp-block-heading\">Using the SPI interfaces of the ESP32<\/h2>\n\n<p>The ESP32 has a total of four SPI interfaces. However, only two of them are available to you, namely VSPI and HSPI. The other two SPI interfaces are used internally. VSPI is the default SPI interface. It is assigned to the GPIOs 18 (VSPI_CLK), 19 (VSPI_MISO), 23 (VSPI_MOSI) and 5 (VSPI_CS = Chip Select). If you use VSPI, it is very similar to the Arduino. You include <code>SPI.h<\/code> and use functions of this class as usual. Although the interface is called <strong>V<\/strong>SPI, the object is called SPI.<\/p>\r\n<p>If you want to use HSPI, then you first have to create the corresponding SPI object. Here is a simple little example. I attached two MPU9250 modules to HSPI and VSPI. I used Bolderflight&#8217;s MPU9250 library which can be found <a href=\"https:\/\/github.com\/bolderflight\/mpu9250-arduino\" target=\"_blank\" rel=\"noopener\">here<\/a> on GitHub. But you don&#8217;t really have to deal with it. Just look at the first lines since they show the principle. <\/p>\r\n\n<div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"ESP32_2_SPI_example_MPU9250.ino\" data-enlighter-title=\"ESP32_2_SPI_example_MPU9250.ino\">#include \"MPU9250.h\"\r\n#include \"SPI.h\"\r\n\r\nSPIClass SPI_2(HSPI); \/\/ create SPI_2 object\r\nMPU9250 IMU_1(SPI,5);  \/\/ pass standard SPI object (VSPI) and Chip Select\r\nMPU9250 IMU_2(SPI_2,15);  \/\/ pass SPI_2 object (HSPI) and Chip Select\r\n\r\nint status;\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n \r\n  status = IMU_1.begin();\r\n  if (status &lt; 0) {\r\n    Serial.println(\"IMU 1 initialization unsuccessful\");\r\n    while(1) {}\r\n  }\r\n  status = IMU_2.begin();\r\n  if (status &lt; 0) {\r\n    Serial.println(\"IMU 2 initialization unsuccessful\");\r\n    while(1) {}\r\n  } \r\n}\r\n\r\nvoid loop() {\r\n  IMU_1.readSensor();\r\n  Serial.println(\"IMU 1 Acceleration Data:\");\r\n  Serial.print(IMU_1.getAccelX_mss(),6);\r\n  Serial.print(\"\\t\");\r\n  Serial.print(IMU_1.getAccelY_mss(),6);\r\n  Serial.print(\"\\t\");\r\n  Serial.println(IMU_1.getAccelZ_mss(),6);\r\n\r\n  IMU_2.readSensor();\r\n  Serial.println(\"IMU 2 Acceleration Data:\");\r\n  Serial.print(IMU_2.getAccelX_mss(),6);\r\n  Serial.print(\"\\t\");\r\n  Serial.print(IMU_2.getAccelY_mss(),6);\r\n  Serial.print(\"\\t\");\r\n  Serial.println(IMU_2.getAccelZ_mss(),6);\r\n \r\n  delay(1000);\r\n}<\/pre>\r\n<p>&nbsp;<\/p>\r\n<\/div>\r\n\n<h3 class=\"wp-block-heading\">Changing the default SPI pins<\/h3>\n\n<p>You can also assign VSPI and HSPI to other pins. A detailed sketch can be found <a href=\"https:\/\/github.com\/espressif\/arduino-esp32\/blob\/master\/libraries\/SPI\/examples\/SPI_Multiple_Buses\/SPI_Multiple_Buses.ino\" target=\"_blank\" rel=\"noopener\">here on GitHub<\/a>.<a id=\"UART\"><\/a><\/p>\r\n\n<h2 class=\"wp-block-heading\">Using the UART (Serial) interface with the ESP32<\/h2>\n\n<p>The ESP32 has three serial interfaces called U0UXD, U1UXD and U2UXD. The three interfaces are assigned to the following pins:<\/p>\r\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/ESP32_UART_eng.png\"><img decoding=\"async\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2023\/09\/ESP32_UART_eng-1024x162.png\" alt=\"Preset for the UART pins of the ESP32\" class=\"wp-image-18704\"\/><\/a><figcaption class=\"wp-element-caption\">Preset for the UART pins of the ESP32<\/figcaption><\/figure>\n\n<p>U0UXD is the default serial interface. It is used, among other things, for output to the serial monitor. It is initialized with <code>Serial.begin(baud rate)<\/code> as usual. If you want to use U1UXD and U2UXD, then you determine its properties with <code>Serialx.begin(baud rate, protocol, RXPin, TXPin)<\/code> (with x = 1 or 2). If you call the begin function only with the baud rate parameter, the default settings apply.<\/p>\r\n<p>Very theoretical, but with the example, it should become clear:<\/p>\r\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"ESP32_UART.ino\" data-enlighter-title=\"ESP32_UART.ino\">#define RX1 16\r\n#define TX1 17\r\n#define RX2 12\r\n#define TX2 13\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  Serial1.begin(115200, SERIAL_8N1, RX1, TX1);\r\n  Serial2.begin(115200, SERIAL_8N1, RX2, TX2);\r\n  delay(100);\r\n  if(Serial1){\r\n    Serial.println(\"Serial1 successfully set up\");\r\n  }\r\n  if(Serial2){\r\n    Serial.println(\"Serial2 successfully set up\");\r\n  }\r\n}\r\n\r\nvoid loop(){}<\/pre>\r\n<p>&nbsp;<\/p>\r\n\n<p>SERIAL_8N1 means: 8 bits, no parity (N = no), 1 stop bit. That&#8217;s the standard. I found a collection of possible protocol parameters <a href=\"https:\/\/github.com\/G6EJD\/ESP32-Using-Hardware-Serial-Ports\/blob\/master\/ESP32_Using_Serial2.ino\" target=\"_blank\" rel=\"noopener\">here on GitHub<\/a>.<\/p>\r\n<p>You can also change the pins for the default interface using the same function: <code>Serial.begin(baud rate, protocoll, RXPin, TXPin)<\/code>.<a id=\"touch\"><\/a><\/p>\r\n\n<h2 class=\"wp-block-heading\">Touch Pins<\/h2>\n\n<p>The touch pins of the ESP32 are capacitance sensitive. The larger the capacitance, the smaller the measured value. Since the human body has also a capacitance, the pins react to touch. The small example sketch shows how it works:<\/p>\r\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"ESP32_touch_test.ino\" data-enlighter-title=\"ESP32_touch_test.ino\">void setup() {\r\n  Serial.begin(9600);\r\n  while(!Serial){} \r\n  Serial.println(\"ESP32 Touch Test\");\r\n}\r\n\r\nvoid loop() {\r\n  Serial.println(touchRead(4));  \/\/ get value of Touch 0 pin = GPIO 4\r\n  \/\/Serial.println(touchRead(T0)); \/\/ alternative \r\n  delay(1000);\r\n}<\/pre>\r\n<p>&nbsp;<\/p>\r\n\n<p>I connected the touch pin to a jumper cable and left the loose end of the cable untouched at first, then touched it and then connected it to a 10 \u03bcF capacitor. This is what the output looked like:<a id=\"hall\"><\/a><\/p>\r\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"766\" height=\"349\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/Touch.png\" alt=\"Output of ESP32_touch_test.ino\" class=\"wp-image-11966\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/Touch.png 766w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/Touch-300x137.png 300w\" sizes=\"auto, (max-width: 766px) 100vw, 766px\" \/><figcaption class=\"wp-element-caption\">Output of ESP32_touch_test.ino<\/figcaption><\/figure>\n\n<h2 class=\"wp-block-heading\">Hall Sensor<\/h2>\n\n<p>In case you have read somewhere about the hall sensor function <code>hallRead()<\/code> somewhere: It is no longer supported. The hall sensor wasn&#8217;t particularly good, but support didn&#8217;t necessarily have to be removed. <a id=\"interrupts\"><\/a><\/p>\r\n\n<h2 class=\"wp-block-heading\">Interrupts<\/h2>\n\n<p>As for the interrupt programming of the ESP32, I could fill an entire article. Therefore I will only deal with external GPIO interrupts.<\/p>\r\n<p>You can set up interrupts on any GPIO pin, including the input pins GPI34 &#8211; GPI39. The handling is the similar to the Arduino boards, except for one special feature. If you use the attribute IRAM_ATTR in the Interrupt Service Routine (ISR), the code is not stored in flash memory, but in RAM. This makes the execution much faster. You have to place the ISR function before <code>setup()<\/code> (at least that&#8217;s how it is in the Arduino IDE). It may sound complicated, but it&#8217;s not.<\/p>\r\n<p>In my short example, a push of a button provides a HIGH signal to GPIO4. This triggers the interrupt. First, the highly complex \ud83d\ude09 circuit:<\/p>\r\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/interrupt_test.png\"><img loading=\"lazy\" decoding=\"async\" width=\"874\" height=\"303\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/interrupt_test.png\" alt=\"ESP32 interrupt test on GPIO4\" class=\"wp-image-11972\" style=\"width:656px;height:227px\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/interrupt_test.png 874w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/interrupt_test-300x104.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/interrupt_test-768x266.png 768w\" sizes=\"auto, (max-width: 874px) 100vw, 874px\" \/><\/a><figcaption class=\"wp-element-caption\">Interrupt test on GPIO4<\/figcaption><\/figure>\n<\/div>\n<p>Here&#8217;s the sketch:<\/p>\r\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"ESP32_ext_interrupt.ino\" data-enlighter-title=\"ESP32_ext_interrupt.ino\">int interruptPin = 4; \/\/ define GPIO4 as interrupt pin\r\nvolatile bool event = false;\r\n\r\nvoid IRAM_ATTR eventISR(){\r\n  event = true;\r\n  detachInterrupt(interruptPin);\r\n}\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  while(!Serial){}\r\n  pinMode(interruptPin, INPUT_PULLDOWN);\r\n  attachInterrupt(interruptPin, eventISR, RISING);\r\n}\r\n\r\nvoid loop() {\r\n  if(event){\r\n    Serial.println(\"Interrupt!\");\r\n    delay(1000); \/\/debouncing\r\n    event = false;\r\n    attachInterrupt(interruptPin, eventISR, RISING);   \r\n  }\r\n}<\/pre>\r\n<p>&nbsp;<\/p>\r\n\n<p>You can also easily define multiple interrupts. Would be a nice exercise for you, wouldn&#8217;t it?<a id=\"strom\"><\/a><\/p>\r\n\n<h2 class=\"wp-block-heading\">Saving Power &#8211; Sleep Modes<\/h2>\n\n<p>The ESP32 is as powerful as it is power hungry. This can be a problem with battery-powered projects. However, there are ways to reduce power consumption to a fraction. First, you can turn off certain components. The biggest power consumers are WiFi and Bluetooth. If you use them, you should turn them off in between if possible. For this purpose, you can use <code>WiFi.mode(WIFI_OFF)<\/code> and <code>btStop()<\/code>. In addition, there are different sleep modes you can choose from.<\/p>\r\n<p>I want to limit the length of this article, so I will only briefly discuss light sleep and deep sleep. With <code>esp_sleep_enable_timer_wakeup()<\/code> you define a sleep phase, after which the ESP32 wakes up again. As parameter, you pass the time in microseconds. But only when you call <code>esp_deep_sleep_start()<\/code> or <code>esp_light_sleep_start()<\/code>, the sleep phase begins.<\/p>\r\n<p>After light sleep, the program continues where it stopped. After deep sleep, it restarts. You can try this out with the following sketch:<\/p>\r\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"ESP32_deep_vs_light_sleep.ino\" data-enlighter-title=\"ESP32_deep_vs_light_sleep.ino\">const int unsigned long microSecToSec = 1000000;\r\nconst int sleepTime = 5; \r\n\r\nvoid setup(){\r\n  Serial.begin(115200);\r\n  while(!Serial){}\r\n\r\n  esp_sleep_enable_timer_wakeup(sleepTime * microSecToSec);\r\n  Serial.println();\r\n  Serial.println(\"ESP32 will go to sleep for 5 seconds....\");\r\n  delay(2000);\r\n  Serial.println(\"...now\");\r\n  esp_deep_sleep_start();\r\n  \/\/esp_light_sleep_start(); \r\n  Serial.println(\"This message will only be printed after light sleep\");\r\n}\r\n\r\nvoid loop(){ \r\n}<\/pre>\r\n<p>&nbsp;<\/p>\r\n\n<h3 class=\"wp-block-heading\">Wake up via external signal<\/h3>\n\n<p>You can also wake up the ESP32 via external signals on one of the RTC_IO pins. You set that up with <code>esp_sleep_enable_ext0_wakeup(GPIO_NUM_x, HIGH\/LOW)<\/code>. The function expects the pin number in the format &#8220;GPIO_NUM_x&#8221; as the first argument. If you pass an integer instead, there will be an error message. The second parameter determines whether the wake-up signal is a HIGH or a LOW.<\/p>\r\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"ESP32_RTC_wake_up.ino\" data-enlighter-title=\"ESP32_RTC_wake_up.ino\">void setup(){\r\n  Serial.begin(115200);\r\n  while(!Serial){};\r\n  pinMode(GPIO_NUM_4, INPUT_PULLDOWN); \r\n  Serial.println();\r\n  esp_sleep_enable_ext0_wakeup(GPIO_NUM_4,1);\r\n  Serial.println(\"ESP32 will go to deep sleep...\");\r\n  delay(1000);\r\n  Serial.println(\"...now\");\r\n  esp_deep_sleep_start(); \/\/\r\n  Serial.println(\"This message will only be printed after light sleep\");\r\n}\r\n\r\nvoid loop(){ \r\n}<\/pre>\r\n<p>&nbsp;<\/p>\r\n\n<h3 class=\"wp-block-heading\">Waking up with Touch<\/h3>\n\n<p>You control waking up by touch with the <code>esp_sleep_enable_touchpad_wakeup()<\/code> function. Before that, however, you have to set up a touch interrupt. Here&#8217;s how:<\/p>\r\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"ESP32_touch_wake_up.ino\" data-enlighter-title=\"ESP32_touch_wake_up.ino\">#define THRESHOLD 40\r\nvoid callback(){}\r\n\r\nvoid setup(){\r\n  Serial.begin(115200);\r\n  delay(1000);\r\n  touchAttachInterrupt(T4, callback, THRESHOLD); \/\/T4 = GPIO13\r\n  esp_sleep_enable_touchpad_wakeup();\r\n  Serial.println(\"Going to deep sleep...\");\r\n  delay(1000);\r\n  Serial.println(\"...now\");\r\n  esp_deep_sleep_start();\r\n}\r\n\r\nvoid loop(){\r\n}<\/pre>\r\n<p>&nbsp;<\/p>\r\n\n<p>So, all you have to do is touch the GPIO13 (easiest via a jumper cable) and the ESP32 will wake up. If you want, you can add further commands to <code>callback(){}<\/code>. Of course, the touch interrupt also works without an alarm function. <a id=\"wifi\"><\/a><\/p>\r\n\n<h2 class=\"wp-block-heading\">WiFi<\/h2>\n\n<p>The use of WiFi is a quite complex topic. Therefore, I have covered this in a separate article. You find it <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/using-wifi-with-the-esp8266-and-esp32\" target=\"_blank\" rel=\"noopener\">here<\/a>.<a id=\"bluetooth\"><\/a><\/p>\r\n\n<h2 class=\"wp-block-heading\">Bluetooth<\/h2>\n\n<p>The topic of Bluetooth is also very extensive. I will show a simple example of how to switch LEDs connected to the ESP32 via smartphone or computer. To do this, you first need a Bluetooth terminal program. For the PC I suggest <a href=\"https:\/\/www.microsoft.com\/de-de\/p\/bluetooth-serial-terminal\/9wzdncrdfst8?activetab=pivot:overviewtab\" target=\"_blank\" rel=\"noopener\">Bluetooth Serial Terminal<\/a>, for Android smartphones I suggest <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=Qwerty.BluetoothTerminal&amp;hl=de\" target=\"_blank\" rel=\"noopener\">Bluetooth Terminal<\/a>.<\/p>\r\n<p>On the ESP32 side, connect two LEDs on GPIO4 and GPIO13. Of course, you can also choose other pins and expand the example as you like.<\/p>\r\n<p>Upload the following sketch, then pair the ESP32 with your smartphone or PC. The ESP32 appears under the name you give with <code>espBT.begin(\"name\")<\/code>. After pairing, you still have to connect the ESP32 in the computer program or in the smartphone app. In the app you click on the three dots, in the PC program it is obvious what to do.&nbsp;<\/p>\r\n<p>If, for example, you send &#8220;+4&#8221; to the ESP32, you switch on the LED at GPIO4. With &#8220;-4&#8221;, on the other hand, you switch it off.<\/p>\r\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"ESP32_BT_example.ino\" data-enlighter-title=\"ESP32_BT_example.ino\">#include \"BluetoothSerial.h\" \r\n\r\nBluetoothSerial espBT; \r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  pinMode(4, OUTPUT);\r\n  pinMode(13, OUTPUT);\r\n  espBT.begin(\"ESP32 Bluetooth Example\");\r\n  Serial.println(\"Pair your BT device now\");  \r\n}\r\n\r\nvoid loop(){\r\n  if(espBT.available()){\r\n    char command = espBT.read();\r\n    int state = LOW;\r\n    int pin = espBT.parseInt();\r\n    Serial.print(\"Received: \"); \r\n    Serial.print(command);\r\n    Serial.println(pin);\r\n\r\n    if((command == '+')||(command == '-')){\r\n      if(command == '+'){\r\n        state = HIGH;\r\n      }\r\n      else state = LOW;\r\n      digitalWrite(pin, state);\r\n    }\r\n    \r\n    espBT.print(\"Received: \"); \r\n    espBT.print(command);\r\n    espBT.println(pin);\r\n  }     \r\n}<\/pre>\r\n<p>&nbsp;<\/p>\r\n\n<p>And this is what the Bluetooth Serial Terminal looks like:<\/p>\r\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/BT_Serial_Terminal-1024x546.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"546\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/BT_Serial_Terminal-1024x546.png\" alt=\"Bluetooth Serial Terminal Program Window\" class=\"wp-image-12051\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/BT_Serial_Terminal-1024x546.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/BT_Serial_Terminal-300x160.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/BT_Serial_Terminal-768x409.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/BT_Serial_Terminal-1320x703.png 1320w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/BT_Serial_Terminal.png 1503w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Bluetooth Serial Terminal Program Window<\/figcaption><\/figure>\n\n<p>A few more brief explanations:<\/p>\r\n<ul>\r\n<li><code>BluetoothSerial espBT<\/code> creates the Bluetooth object.<\/li>\r\n<li><code>espBT.read()<\/code> reads the first character, i.e. &#8220;+&#8221; or &#8220;\u2013&#8221;.<\/li>\r\n<li><code>espBT.parseInt()<\/code> identifies the next sequence of digits in the incoming characters and reads them as an integer (very useful function).<\/li>\r\n<\/ul>\r\n\n<p>Everything else you should be able to understand. If not, then there is a more detailed tutorial <a href=\"https:\/\/circuitdigest.com\/microcontroller-projects\/using-classic-bluetooth-in-esp32-and-toogle-an-led\" target=\"_blank\" rel=\"noopener\">here<\/a>, for example.&nbsp;<\/p>\r\n\n<h4 class=\"wp-block-heading\">Fash hungry BluetoothSerial &#8211; enlarging the flash<\/h4>\n\n<p>After including BluetoothSerial.h, you will see that the remaining flash memory has significantly decreased. If you want to increase the flash, go to Tools \u2192 Partition Scheme and select the setting &#8220;HugeAPP (3MB NoOTA\/1 MB SPIFFS)&#8221;.<\/p>\r\n\n<h2 class=\"wp-block-heading\" id=\"exotisch\">&#8220;Exotic&#8221; pin functions<\/h2>\n\n<p>If you go back to the pinout diagram from the beginning, you will see that I have explained most of the pin functions. However, a few are still missing. Most people will probably never use them.<\/p>\r\n<ul>\r\n<li>SENS_VP \/ SENS_VN: Input for small DC signals, e.g. thermocouples. The pins are also used internally for the Hall sensor.<\/li>\r\n<li>VDET1 \/ VDT2: &#8220;<a href=\"https:\/\/esp32.com\/viewtopic.php?t=187\" target=\"_blank\" rel=\"noopener\">they belong to the RTC power domain, which means that the devices that fall under the RTC can control them. It means e.g. that they can be used as ADC pins and that the ULP coprocessor can read them.<\/a> &#8221; &#8211; no idea what that really means, but exactly this wording is quoted quite often. <\/li>\r\n<li><em>x<\/em>SPI_WP \/ <em>x<\/em>SPI_HD: required to control 4-bit SPI transactions; WP = Write Protection, HD = Hold.<\/li>\r\n<li>XTAL_P\/ XTAL_N: external oscillator input for the ULP (Ultra Low Power) processor.<\/li>\r\n<\/ul>\r\n\n<h2 class=\"wp-block-heading\" id=\"api\">The APIs (Application Programming Interfaces)<\/h2>\n\n<p>As you have seen, there are some functions such as <code>ledcAttach()<\/code> that you will not recognize from the standard repertoire of Arduino functions. These belong to the ESP32 APIs, that you can find <a href=\"https:\/\/docs.espressif.com\/projects\/arduino-esp32\/en\/latest\/libraries.html#apis\" target=\"_blank\" rel=\"noopener\">here<\/a>. It is well worth taking a look.<\/p>\r\n\n<h2 class=\"wp-block-heading\">Acknowledgement<\/h2>\n\n<p>I have found the cloud in the post image at <a href=\"https:\/\/pixabay.com\/de\/users\/clker-free-vector-images-3736\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=41256\" target=\"_blank\" rel=\"noopener\">Clker free vector images<\/a> on <a href=\"https:\/\/pixabay.com\/de\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=41256\" target=\"_blank\" rel=\"noopener\">Pixabay<\/a>.<\/p>\r\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I introduce the ESP32 and its main features. In particular, I will discuss the differences to the Arduino (AVR) boards.<\/p>\n","protected":false},"author":1,"featured_media":11984,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[543],"tags":[1498,556,1499,1506,1044,1496,2505,1500,666,1508,1497,983,882,1059,1503,1505,1502],"class_list":["post-12177","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-boards-and-microcontrollers","tag-adc-en","tag-arduino-en-2","tag-dac-en","tag-deep-sleep-en","tag-esp32-en","tag-esp32-wroom-32-en-2","tag-extending-the-flash","tag-frequency","tag-i2c-en","tag-light-sleep-en","tag-pinout-en","tag-pwm-en","tag-resolution-en-2","tag-sleep-en","tag-spi-en","tag-touch-en","tag-uart-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Programming the ESP32 with Arduino Code &#8226; Wolles Elektronikkiste<\/title>\n<meta name=\"description\" content=\"I introduce the ESP32 and its main features. In particular, I will discuss the differences to the Arduino (AVR) boards.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Programming the ESP32 with Arduino Code &#8226; Wolles Elektronikkiste\" \/>\n<meta property=\"og:description\" content=\"I introduce the ESP32 and its main features. In particular, I will discuss the differences to the Arduino (AVR) boards.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code\" \/>\n<meta property=\"og:site_name\" content=\"Wolles Elektronikkiste\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-23T11:03:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-29T14:37:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/Beitragsbild_ESP32.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"1200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Wolfgang Ewald\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Wolfgang Ewald\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code\"},\"author\":{\"name\":\"Wolfgang Ewald\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\"},\"headline\":\"Programming the ESP32 with Arduino Code\",\"datePublished\":\"2021-07-23T11:03:30+00:00\",\"dateModified\":\"2024-10-29T14:37:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code\"},\"wordCount\":3252,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\"},\"image\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/Beitragsbild_ESP32.png\",\"keywords\":[\"ADC\",\"Arduino\",\"DAC\",\"deep sleep\",\"ESP32\",\"ESP32-WROOM-32\",\"Extending the flash\",\"frequency\",\"I2C\",\"light sleep\",\"Pinout\",\"PWM\",\"resolution\",\"sleep\",\"SPI\",\"Touch\",\"UART\"],\"articleSection\":[\"Boards and Microcontrollers\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code\",\"name\":\"Programming the ESP32 with Arduino Code &#8226; Wolles Elektronikkiste\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/Beitragsbild_ESP32.png\",\"datePublished\":\"2021-07-23T11:03:30+00:00\",\"dateModified\":\"2024-10-29T14:37:23+00:00\",\"description\":\"I introduce the ESP32 and its main features. In particular, I will discuss the differences to the Arduino (AVR) boards.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code#primaryimage\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/Beitragsbild_ESP32.png\",\"contentUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/Beitragsbild_ESP32.png\",\"width\":1200,\"height\":1200},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/programming-the-esp32-with-arduino-code#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Startseite\",\"item\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Programming the ESP32 with Arduino Code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#website\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\",\"name\":\"Wolles Elektronikkiste\",\"description\":\"Die wunderbare Welt der Elektronik\",\"publisher\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\",\"name\":\"Wolfgang Ewald\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\",\"contentUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\",\"width\":512,\"height\":512,\"caption\":\"Wolfgang Ewald\"},\"logo\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Programming the ESP32 with Arduino Code &#8226; Wolles Elektronikkiste","description":"I introduce the ESP32 and its main features. In particular, I will discuss the differences to the Arduino (AVR) boards.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code","og_locale":"en_US","og_type":"article","og_title":"Programming the ESP32 with Arduino Code &#8226; Wolles Elektronikkiste","og_description":"I introduce the ESP32 and its main features. In particular, I will discuss the differences to the Arduino (AVR) boards.","og_url":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code","og_site_name":"Wolles Elektronikkiste","article_published_time":"2021-07-23T11:03:30+00:00","article_modified_time":"2024-10-29T14:37:23+00:00","og_image":[{"width":1200,"height":1200,"url":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/Beitragsbild_ESP32.png","type":"image\/png"}],"author":"Wolfgang Ewald","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Wolfgang Ewald","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code#article","isPartOf":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code"},"author":{"name":"Wolfgang Ewald","@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46"},"headline":"Programming the ESP32 with Arduino Code","datePublished":"2021-07-23T11:03:30+00:00","dateModified":"2024-10-29T14:37:23+00:00","mainEntityOfPage":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code"},"wordCount":3252,"commentCount":0,"publisher":{"@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46"},"image":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code#primaryimage"},"thumbnailUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/Beitragsbild_ESP32.png","keywords":["ADC","Arduino","DAC","deep sleep","ESP32","ESP32-WROOM-32","Extending the flash","frequency","I2C","light sleep","Pinout","PWM","resolution","sleep","SPI","Touch","UART"],"articleSection":["Boards and Microcontrollers"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code#respond"]}]},{"@type":"WebPage","@id":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code","url":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code","name":"Programming the ESP32 with Arduino Code &#8226; Wolles Elektronikkiste","isPartOf":{"@id":"https:\/\/wolles-elektronikkiste.de\/en#website"},"primaryImageOfPage":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code#primaryimage"},"image":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code#primaryimage"},"thumbnailUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/Beitragsbild_ESP32.png","datePublished":"2021-07-23T11:03:30+00:00","dateModified":"2024-10-29T14:37:23+00:00","description":"I introduce the ESP32 and its main features. In particular, I will discuss the differences to the Arduino (AVR) boards.","breadcrumb":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code#primaryimage","url":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/Beitragsbild_ESP32.png","contentUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2021\/07\/Beitragsbild_ESP32.png","width":1200,"height":1200},{"@type":"BreadcrumbList","@id":"https:\/\/wolles-elektronikkiste.de\/en\/programming-the-esp32-with-arduino-code#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Startseite","item":"https:\/\/wolles-elektronikkiste.de\/en"},{"@type":"ListItem","position":2,"name":"Programming the ESP32 with Arduino Code"}]},{"@type":"WebSite","@id":"https:\/\/wolles-elektronikkiste.de\/en#website","url":"https:\/\/wolles-elektronikkiste.de\/en","name":"Wolles Elektronikkiste","description":"Die wunderbare Welt der Elektronik","publisher":{"@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wolles-elektronikkiste.de\/en?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46","name":"Wolfgang Ewald","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png","url":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png","contentUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png","width":512,"height":512,"caption":"Wolfgang Ewald"},"logo":{"@id":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png"}}]}},"_links":{"self":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts\/12177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/comments?post=12177"}],"version-history":[{"count":0,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts\/12177\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/media\/11984"}],"wp:attachment":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/media?parent=12177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/categories?post=12177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/tags?post=12177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}