{"id":74416,"date":"2018-10-04T10:10:08","date_gmt":"2018-10-04T10:10:08","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=74416"},"modified":"2019-04-22T13:53:34","modified_gmt":"2019-04-22T13:53:34","slug":"esp32-dual-core-arduino-ide","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-dual-core-arduino-ide\/","title":{"rendered":"How to use ESP32 Dual Core with Arduino IDE"},"content":{"rendered":"\n<p>The ESP32 comes with&nbsp;2 Xtensa 32-bit LX6 microprocessors: core 0 and core 1. So, it is dual core.&nbsp;When we run code on Arduino IDE, by default, it runs on core 1.&nbsp;In this post we\u2019ll show you how to run code on the ESP32 second core by creating tasks. You can run pieces of code simultaneously on both cores, and make your ESP32 multitasking.<\/p>\n\n\n\n<p><strong>Note:<\/strong>&nbsp;you don&#8217;t necessarily need to run dual core to achieve multitasking.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/ESP32-dual-core.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-74468\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/ESP32-dual-core.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/ESP32-dual-core.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/ESP32-dual-core.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/ESP32-dual-core.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>The ESP32 comes with&nbsp;2 Xtensa 32-bit LX6 microprocessors, so it&#8217;s dual core:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Core 0<\/li><li>Core 1<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"452\" height=\"376\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/esp32-block-diagram.png?resize=452%2C376&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-74421\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/esp32-block-diagram.png?w=452&amp;quality=100&amp;strip=all&amp;ssl=1 452w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/esp32-block-diagram.png?resize=300%2C250&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 452px) 100vw, 452px\" \/><\/figure><\/div>\n\n\n\n<p>When we upload code to the ESP32 using the Arduino IDE, it just runs &#8211; we don\u2019t have to worry which core executes the code.<\/p>\n\n\n\n<p>There&#8217;s a function that you can use to identify in which core the code is running:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>xPortGetCoreID()<\/code><\/pre>\n\n\n\n<p>If you use that function in an Arduino sketch, you&#8217;ll see that both the <span class=\"rnthl rntliteral\">setup()<\/span> and <span class=\"rnthl rntliteral\">loop()<\/span> are running on core 1. Test it yourself by uploading the following sketch to your ESP32.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos\n  Complete project details at http:\/\/randomnerdtutorials.com  \n*********\/\n\nvoid setup() {\n  Serial.begin(115200);\n  Serial.print(&quot;setup() running on core &quot;);\n  Serial.println(xPortGetCoreID());\n}\n\nvoid loop() {\n  Serial.print(&quot;loop() running on core &quot;);\n  Serial.println(xPortGetCoreID());\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-Course\/raw\/master\/code\/Dual_Core\/Get_Core_ID\/Get_Core_ID.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Open the Serial Monitor at a baud rate of 115200 and check the core the Arduino sketch is running on.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"624\" height=\"370\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/arduino-sketch-core-1.png?resize=624%2C370&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-74419\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/arduino-sketch-core-1.png?w=624&amp;quality=100&amp;strip=all&amp;ssl=1 624w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/arduino-sketch-core-1.png?resize=300%2C178&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Create Tasks<\/h2>\n\n\n\n<p>The Arduino IDE supports FreeRTOS for the ESP32, which is a Real Time Operating system. This allows us to handle several tasks in parallel that run independently.<\/p>\n\n\n\n<p>Tasks are pieces of code that execute something. For example, it can be blinking an LED, making a network request, measuring sensor readings, publishing sensor readings, etc&#8230;<\/p>\n\n\n\n<p>To assign specific parts of code to a specific core, you need to create tasks. When creating a task you can chose in which core it will run, as well as its priority.&nbsp;Priority values start at 0, in which 0 is the lowest priority. The processor will run the tasks with higher priority first.<\/p>\n\n\n\n<p>To create tasks you need to follow the next steps:<\/p>\n\n\n\n<p><strong>1. <\/strong>Create a task handle. An example for Task1:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>TaskHandle_t Task1;<\/code><\/pre>\n\n\n\n<p><strong>2. <\/strong>In the <span class=\"rnthl rntliteral\">setup()<\/span> create a a task assigned to a specific core using the <span class=\"rnthl rntliteral\">xTaskCreatePinnedToCore<\/span> function. That function takes several arguments, including the priority and the core where the task should run (the last parameter).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>xTaskCreatePinnedToCore(\n      Task1code, \/* Function to implement the task *\/\n      \"Task1\", \/* Name of the task *\/\n      10000,  \/* Stack size in words *\/\n      NULL,  \/* Task input parameter *\/\n      0,  \/* Priority of the task *\/\n      &amp;Task1,  \/* Task handle. *\/\n      0); \/* Core where the task should run *\/<\/code><\/pre>\n\n\n\n<p><strong>3. <\/strong>After creating the task, you should create a function that contains the code for the created task. In this example you need to create the <span class=\"rnthl rntliteral\">Task1code()<\/span> function. Here&#8217;s how the task function looks like:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Void Task1code( void * parameter) {\n  for(;;) {\n    Code for task 1 - infinite loop\n    (...)\n  }\n}<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">for(;;)<\/span> creates an infinite loop. So, this function runs similarly to the <span class=\"rnthl rntliteral\">loop()<\/span> function. You can use it as a second loop in your code, for example.<\/p>\n\n\n\n<p>If during your code execution you want to delete the created task, you can use the <span class=\"rnthl rntliteral\">vTaskDelete()<\/span>function, that accepts the task handle (<span class=\"rnthl rntliteral\">Task1<\/span>) as argument:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>vTaskDelete(Task1);<\/code><\/pre>\n\n\n\n<p>Let&#8217;s see how these concepts work with a simple example.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create Tasks in Different Cores &#8211; Example<\/h2>\n\n\n\n<p>To follow this example, you need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESP32 DOIT DEVKIT V1 Board<\/a><\/li><li>2x <a href=\"https:\/\/makeradvisor.com\/tools\/3mm-5mm-leds-kit-storage-box\/\" target=\"_blank\" rel=\"noreferrer noopener\">5mm LED<\/a><\/li><li>2x <a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noreferrer noopener\">330 Ohm resistor<\/a><\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noreferrer noopener\">Breadboard<\/a><\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper wires<\/a><\/li><\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<p>To create different tasks running&nbsp;on different cores we&#8217;ll create two tasks that blink LEDs with different delay times. Start by wiring two LEDs to the ESP32 as shown in the following diagram:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1010\" height=\"733\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/esp32-two-leds_bb.png?resize=1010%2C733&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-74422\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/esp32-two-leds_bb.png?w=1010&amp;quality=100&amp;strip=all&amp;ssl=1 1010w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/esp32-two-leds_bb.png?resize=300%2C218&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/esp32-two-leds_bb.png?resize=768%2C557&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1010px) 100vw, 1010px\" \/><\/figure><\/div>\n\n\n\n<p>We&#8217;ll create two tasks running on different cores:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Task1 runs on core 0;<\/li><li>Task2 runs on core 1;<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"510\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/Dual-core-example-768x510.png?resize=768%2C510&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-74420\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/Dual-core-example-768x510.png?resize=768%2C510&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/Dual-core-example-768x510.png?resize=300%2C199&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure><\/div>\n\n\n\n<p>Upload the next sketch to your ESP32 to blink each LED in a different core:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos\n  Complete project details at http:\/\/randomnerdtutorials.com  \n*********\/\n\nTaskHandle_t Task1;\nTaskHandle_t Task2;\n\n\/\/ LED pins\nconst int led1 = 2;\nconst int led2 = 4;\n\nvoid setup() {\n  Serial.begin(115200); \n  pinMode(led1, OUTPUT);\n  pinMode(led2, OUTPUT);\n\n  \/\/create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0\n  xTaskCreatePinnedToCore(\n                    Task1code,   \/* Task function. *\/\n                    &quot;Task1&quot;,     \/* name of task. *\/\n                    10000,       \/* Stack size of task *\/\n                    NULL,        \/* parameter of the task *\/\n                    1,           \/* priority of the task *\/\n                    &amp;Task1,      \/* Task handle to keep track of created task *\/\n                    0);          \/* pin task to core 0 *\/                  \n  delay(500); \n\n  \/\/create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1\n  xTaskCreatePinnedToCore(\n                    Task2code,   \/* Task function. *\/\n                    &quot;Task2&quot;,     \/* name of task. *\/\n                    10000,       \/* Stack size of task *\/\n                    NULL,        \/* parameter of the task *\/\n                    1,           \/* priority of the task *\/\n                    &amp;Task2,      \/* Task handle to keep track of created task *\/\n                    1);          \/* pin task to core 1 *\/\n    delay(500); \n}\n\n\/\/Task1code: blinks an LED every 1000 ms\nvoid Task1code( void * pvParameters ){\n  Serial.print(&quot;Task1 running on core &quot;);\n  Serial.println(xPortGetCoreID());\n\n  for(;;){\n    digitalWrite(led1, HIGH);\n    delay(1000);\n    digitalWrite(led1, LOW);\n    delay(1000);\n  } \n}\n\n\/\/Task2code: blinks an LED every 700 ms\nvoid Task2code( void * pvParameters ){\n  Serial.print(&quot;Task2 running on core &quot;);\n  Serial.println(xPortGetCoreID());\n\n  for(;;){\n    digitalWrite(led2, HIGH);\n    delay(700);\n    digitalWrite(led2, LOW);\n    delay(700);\n  }\n}\n\nvoid loop() {\n  \n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-Course\/raw\/master\/code\/Dual_Core\/Dual_Core_Blinking_LEDs\/Dual_Core_Blinking_LEDs.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Code Works<\/h2>\n\n\n\n<p><strong>Note:<\/strong> in the code we create two tasks and assign one task to core 0 and another to core 1. Arduino sketches run on core 1 by default. So, you could write the code for Task2 in the <span class=\"rnthl rntliteral\">loop()<\/span> (there was no need to create another task). In this case we create two different tasks for learning purposes.<\/p>\n\n\n\n<p>However, depending on your project requirements, it may be more practical to organize your code in tasks as demonstrated in this example.<\/p>\n\n\n\n<p>The code starts by creating a task handle for Task1 and Task2 called <span class=\"rnthl rntliteral\">Task1<\/span> and <span class=\"rnthl rntliteral\">Task2<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>TaskHandle_t Task1;\nTaskHandle_t Task2;<\/code><\/pre>\n\n\n\n<p>Assign GPIO 2 and GPIO 4 to the LEDs:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const int led1 = 2; \nconst int led2 = 4;<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor at a baud rate of 115200:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<p>Declare the LEDs as outputs:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(led1, OUTPUT); \npinMode(led2, OUTPUT);<\/code><\/pre>\n\n\n\n<p>Then, create Task1 using the<strong>&nbsp;xTaskCreatePinnedToCore()<\/strong> function:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>xTaskCreatePinnedToCore(\n             Task1code, \/* Task function. *\/\n             \"Task1\",   \/* name of task. *\/\n             10000,     \/* Stack size of task *\/\n             NULL,      \/* parameter of the task *\/\n             1,         \/* priority of the task *\/\n             &amp;Task1,    \/* Task handle to keep track of created task *\/\n             0);        \/* pin task to core 0 *\/<\/code><\/pre>\n\n\n\n<p>Task1 will be implemented with the <span class=\"rnthl rntliteral\">Task1code()<\/span> function. So, we need to create that function later on the code. We give the task priority 1, and pinned it to core 0.<\/p>\n\n\n\n<p>We create Task2 using the same method:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>xTaskCreatePinnedToCore(\n             Task2code,  \/* Task function. *\/\n             \"Task2\",    \/* name of task. *\/\n             10000,      \/* Stack size of task *\/\n             NULL,       \/* parameter of the task *\/\n             1,          \/* priority of the task *\/\n             &amp;Task2,     \/* Task handle to keep track of created task *\/\n             1);         \/* pin task to core 0 *\/<\/code><\/pre>\n\n\n\n<p>After creating the tasks, we need to create the functions that will execute those tasks.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void Task1code( void * pvParameters ){\n  Serial.print(\"Task1 running on core \");\n  Serial.println(xPortGetCoreID());\n\n  for(;;){\n    digitalWrite(led1, HIGH);\n    delay(1000);\n    digitalWrite(led1, LOW);\n    delay(1000);\n  }\n}<\/code><\/pre>\n\n\n\n<p>The function to Task1 is called <span class=\"rnthl rntliteral\">Task1code()<\/span> (you can call it whatever you want). For debugging purposes, we first print the core in which the task is running:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.print(\"Task1 running on core \");\nSerial.println(xPortGetCoreID());<\/code><\/pre>\n\n\n\n<p>Then, we have an infinite loop similar to the <span class=\"rnthl rntliteral\">loop()<\/span> on the Arduino sketch. In that loop, we blink LED1 every one second.<\/p>\n\n\n\n<p>The same thing happens for Task2, but we blink the LED with a different delay time.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void Task2code( void * pvParameters ){\n  Serial.print(\"Task2 running on core \");\n  Serial.println(xPortGetCoreID());\n\n  for(;;){\n    digitalWrite(led2, HIGH);\n    delay(700);\n    digitalWrite(led2, LOW);\n    delay(700);\n  }\n}<\/code><\/pre>\n\n\n\n<p>Finally, the <span class=\"rnthl rntliteral\">loop()<\/span> function is empty:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void loop() { }<\/code><\/pre>\n\n\n\n<p><strong>Note:<\/strong> as mentioned previously, the Arduino <span class=\"rnthl rntliteral\">loop()<\/span> runs on core 1. So, instead of creating a task to run on core 1, you can simply write your code inside the <span class=\"rnthl rntliteral\">loop()<\/span>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>Upload the code to your ESP32. Make sure you have the right board and COM port selected.<\/p>\n\n\n\n<p>Open the Serial Monitor at a baud rate of 115200. You should get the following messages:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"370\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/tasks-on-different-cores-esp32-Copy.png?resize=624%2C370&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-74424\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/tasks-on-different-cores-esp32-Copy.png?w=624&amp;quality=100&amp;strip=all&amp;ssl=1 624w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/tasks-on-different-cores-esp32-Copy.png?resize=300%2C178&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/figure><\/div>\n\n\n\n<p>As expected Task1 is running on core 0, while Task2 is running on core 1.<\/p>\n\n\n\n<p>In your circuit, one LED should be blinking every 1 second, and the other should be blinking every 700 milliseconds.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"510\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/featured-image-red-led-on-esp32.jpg?resize=750%2C510&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-74423\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/featured-image-red-led-on-esp32.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/featured-image-red-led-on-esp32.jpg?resize=300%2C204&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In summary:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The ESP32 is dual core;<\/li><li>Arduino sketches run on core 1 by default;<\/li><li>To use core 0 you need to create tasks;<\/li><li>You can use the <span class=\"rnthl rntliteral\">xTaskCreatePinnedToCore()<\/span> function to pin a specific task to a specific core;<\/li><li>Using this method you can run two different tasks independently and simultaneously using the two cores.<\/li><\/ul>\n\n\n\n<p>In this tutorial we&#8217;ve provided a simple example with LEDs. The idea is to use this method with more advanced projects with real world applications. For example, it may be useful to use one core to take sensor readings and other to publish those readings on a home automation system.<\/p>\n\n\n\n<p>If you want to learn more about ESP32, make sure you take a look at our course: <a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\" target=\"_blank\" rel=\"noreferrer noopener\">Learn ESP32 with Arduino IDE<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The ESP32 comes with&nbsp;2 Xtensa 32-bit LX6 microprocessors: core 0 and core 1. So, it is dual core.&nbsp;When we run code on Arduino IDE, by default, it runs on core &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to use ESP32 Dual Core with Arduino IDE\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-dual-core-arduino-ide\/#more-74416\" aria-label=\"Read more about How to use ESP32 Dual Core with Arduino IDE\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":74468,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[281,276,277,299,264],"tags":[],"class_list":["post-74416","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp32","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/ESP32-dual-core.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/74416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=74416"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/74416\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/74468"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=74416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=74416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=74416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}