[image] mseddougui: specifically functions that connect to the wifi and to an mqtt server require the use of delay() while they're waiting for a connection and thus the program blocks in certain areas. [image] mseddougui: Another solution would be to monitor the connection status without … Answer from J-M-L on forum.arduino.cc
🌐
Random Nerd Tutorials
randomnerdtutorials.com › home › project › esp32 › how to use esp32 dual core with arduino ide
ESP32 Dual Core with Arduino IDE | Random Nerd Tutorials
November 26, 2025 - For my project I currently use Arduino (controls etc) and ESP8266 (Wifi) with RX/TX links but would like to investigate the 2 x core ESP32 option Reply · Hi Bob. We don’t go deep into that subject in our course. As Tony mentioned in a previous comment “both tasks can use the same variables declared in the sketch, so this is the easiest way to communicate between the cores.”. I hope this helps. Regards, Sara Reply · Sharing global variables between multiple threads ...
Discussions

std::thread implementation for ESP32 to Arduino API/IDE
wishful IMO for Arduino: a std::thread implementation for ESP32, like meanwhile already available for Teensy (TeensyThread): https://github.com/ftrias/TeensyThreads or perhaps native C++ More on github.com
🌐 github.com
99
May 23, 2019
Multithreading on Arduino/esp
Hi, I want to know if it's possible to run two or more different program loops concurrently on an arduino? I've implemented an event-based system that deals with several different tasks using specific durations for each event. The system works fine but one issue I have is that certain functions, ... More on forum.arduino.cc
🌐 forum.arduino.cc
12
0
April 5, 2023
Multi-threading with the ESP32 - Projects made with Blynk - Blynk Community
Saw this project Three LEDs with Dirty Delay (ESP32) - #21 by Gunner on multi-threading with the ESP32 and thought I have a crack at a non-blocking second thread reading analog and digital inputs The only trap I found is that ADC1 uses CORE1 and ADC2 uses CORE0. More on community.blynk.cc
🌐 community.blynk.cc
1
4
December 7, 2021
Multithreading avec un ESP32
Bonjour à toutes et à tous, Dans l'application que je souhaite réaliser : un routeur photovoltaïque, il y a plusieurs fonctions : acquisition de données, fonction de régulation, enregistrement/lecture de données. transfert de données par WiFi. Faire du multithreading me semble approprié. More on forum.arduino.cc
🌐 forum.arduino.cc
19
0
December 22, 2024
🌐
Espressif
docs.espressif.com › projects › arduino-esp32 › en › latest › openthread › openthread.html
OpenThread - - — Arduino ESP32 latest documentation
Arduino OpenThread sketches read ESP-IDF sdkconfig symbols (CONFIG_OPENTHREAD_*). The ESP-IDF OpenThread port maps many of them to OpenThread core macros (OPENTHREAD_CONFIG_*) in openthread-core-esp32x-ftd-config.h. Some library features also depend on macros that are not direct menu toggles and must be set in a custom OpenThread header when using Arduino as an ESP-IDF component. CoAPS builds: enable Thread Extensioned Features → Use a header file defined by customer, define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 1 in that header, and enable mbedtls PSK ciphers — see README.md.
🌐
GitHub
github.com › espressif › arduino-esp32 › issues › 2814
std::thread implementation for ESP32 to Arduino API/IDE · Issue #2814 · espressif/arduino-esp32
May 23, 2019 - wishful IMO for Arduino: a std::thread implementation for ESP32, like meanwhile already available for Teensy (TeensyThread): https://github.com/ftrias/TeensyThreads or perhaps native C++ <thread>
Author   espressif
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Multithreading on Arduino/esp - Programming - Arduino Forum
April 5, 2023 - Hi, I want to know if it's possible to run two or more different program loops concurrently on an arduino? I've implemented an event-based system that deals with several different tasks using specific durations for each event. The system works fine but one issue I have is that certain functions, specifically functions that connect to the wifi and to an mqtt server require the use of delay() while they're waiting for a connection and thus the program blocks in certain areas.
🌐
TechTutorialsX
techtutorialsx.com › 2017 › 12 › 30 › esp32-arduino-using-the-pthreads-library
ESP32 Arduino: Using the pthreads library
TechTutorialsX — directory of Android apps with desktop guides for Windows PC and Mac via the NoxPlayer emulator. Plus a deep archive of programming and microcontroller tutorials.
🌐
Blynk Community
community.blynk.cc › projects made with blynk
Multi-threading with the ESP32 - Projects made with Blynk - Blynk Community
December 7, 2021 - Saw this project Three LEDs with Dirty Delay (ESP32) - #21 by Gunner on multi-threading with the ESP32 and thought I have a crack at a non-blocking second thread reading analog and digital inputs The only trap I found is that ADC1 uses CORE1 and ADC2 uses CORE0.
Find elsewhere
🌐
Arduino Forum
forum.arduino.cc › international › français
Multithreading avec un ESP32 - Français - Arduino Forum
December 22, 2024 - Bonjour à toutes et à tous, Dans l'application que je souhaite réaliser : un routeur photovoltaïque, il y a plusieurs fonctions : acquisition de données, fonction de régulation, enregistrement/lecture de données. transfert de données par WiFi. Faire du multithreading me semble approprié.
🌐
TutorialsPoint
tutorialspoint.com › esp32_for_iot › esp32_for_iot_setting_up_rtos_for_dual_core_and_multi_threaded_operation.htm
Setting up RTOS for dual-core and multi-threaded operation
On a single core, often, one thread has to wait for the other to pause before it can begin execution. On two cores, parallel execution is literally parallel, because they are literally occupying different processors. Sounds exciting? Let's get started with a real example, that demonstrates how to create two tasks and assign them to specific cores within ESP32. ... To use FreeRTOS within the Arduino ...
🌐
Arduino Forum
forum.arduino.cc › other hardware › home automation
Creating threads in an C++ library for ESP32 - Home Automation - Arduino Forum
February 21, 2020 - Hi, In an university project I need to implement a package resending for the CoAP-simple library for arduino. Theoretically, I would consider this an easy task, since it only envolves a few lines of code. As I am more of a Java programmer and not very well versed in C++ and arduino stuff I ...
🌐
GitHub
github.com › espressif › arduino-esp32 › discussions › 11777
Matter Over Thread on ESP 32 C6 Xiao by Seeed Studio in Arduino IDE · espressif/arduino-esp32 · Discussion #11777
ESP32-C6: OpenThread init fails in Arduino Core 3.3.0 (IDF 5.5) due to missing eventfd/select in core build ... -DCHIP_DEVICE_CONFIG_ENABLE_WIFI=0 -DCHIP_DEVICE_CONFIG_SOC_WIFI_SUPPORTED=0 -DCHIP_DEVICE_CONFIG_ENABLE_THREAD=1 -DCONFIG_ENABLE_CHIPOBLE=1 -DINET_CONFIG_ENABLE_IPV4=0 -DINET_CONFIG_ENABLE_IPV6=1
Author   espressif
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Arduino ESP32 multi threading shared memory - Programming - Arduino Forum
February 8, 2021 - The ESP32 is ideal for a portable device because of its price and its low power consumption. The problem with a single-thread solution is that while the FFT is running, the audio signal cannot ...
🌐
YouTube
youtube.com › kind spirit technology
ESP32 & ESP8266 - Multithreading, simple example with ESP32 - YouTube
#esp32project #arduino #programming In this episode, we are going to talk about multi-threding with esp32 and arduino. The first episode will provide basic e...
Published   June 26, 2024
Views   84
🌐
Arduino
docs.arduino.cc › tutorials › nano-matter › open-thread-border-router
Open Thread Border Router with Nano Matter & ESP32 | Arduino Documentation
The Nano Matter is the RCP, connected to the Nano ESP32 (the Matter Controller) via serial port. ... This tutorial's main objective is to guide you through the build and configuration of an OpenThread Border Router. This router will allow you to deploy a Matter network over Thread and integrate Matter devices into your Smart Home system. Create an OTBR using Arduino products.
🌐
Reddit
reddit.com › r/esp32 › easy threading on the esp32
r/esp32 on Reddit: Easy threading on the ESP32
July 29, 2022 -

It's really difficult to chase down race conditions, even with a debugger.

Because of that, you may hesitate to use the secondary core on applicable ESP32s.

I've created a PlatformIO library to make it almost foolproof to write code that targets the secondary core or just a secondary thread on the primary core.

The library is easy to use and examples are included.

Add this to your platformio.ini

lib_ldf_mode = deep
lib_deps = codewitch-honey-crisis/htcw_freertos_thread_pack

Or visit this link to download the code manually (necessary if using Arduino IDE)

https://github.com/codewitch-honey-crisis/htcw_freertos_thread_pack

Included is a thread class, a thread pool class, a thread safe message queue class, and something called a "synchronization_context". The latter was a concept I "borrowed" from .NET that allows you to dispatch code on a waiting thread. Basically you feed it a lambda from the primary thread and it will run whatever code was inside of it on the thread that's waiting. It often makes it unnecessary to roll your own synchronization.

Examples are included under /examples

🌐
ESP32 Forum
esp32.com › viewtopic.php
ESP32 Threading - ESP32 Forum
To create a "thread", which is a "task" in FreeRTOS lingo, you use one of the API calls described here: https://docs.espressif.com/projects/esp ... ertos.html Either: ... Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.
🌐
DFRobot
dfrobot.com › home › blog
ESP32 Arduino Tutorial: Using the pthreads library - DFRobot
January 4, 2018 - TUTORIALS ESP32 · DFRobot Jan 04 2018 263036 · #include <pthread.h> Serial.begin(115200); pthread_t threads[4]; int returnValue; void setup() { Serial.begin(115200); pthread_t threads[4]; int returnValue; for( int i = 0; i< 4; i++ ) { returnValue = pthread_create(&threads[i], NULL, printThreadId, (void *)i); if (returnValue) { Serial.println("An error has occurred"); } } } void *printThreadId(void *threadid) { Serial.println((int)threadid); } #include <pthread.h> void *printThreadId(void *threadid) { Serial.println((int)threadid); } void setup() { Serial.begin(115200); pthread_t threads[4]; int returnValue; for( int i = 0; i< 4; i++ ) { returnValue = pthread_create(&threads[i], NULL, printThreadId, (void *)i); if (returnValue) { Serial.println("An error has occurred"); } } } void loop() {} ESP32 / ESP8266 ProjectsESP32 / ESP8266 Products ·
🌐
Espressif
components.espressif.com › components › espressif › arduino-esp32 › versions › 3.3.6 › examples › Arduino_ESP_Matter_over_OpenThread
espressif/arduino-esp32 - 3.3.6 - Example Arduino_ESP_Matter_over_OpenThread • ESP Component Registry
| Supported Targets | ESP32-C5 | ESP32-C6 | ESP32-H2 | | ----------------- | -------- | -------- | -------- | # Arduino ESP-Matter over Thread example using ESP32-C5, ESP32-C6 and ESP32-H2 (any SoC with Thread radio) This is an Arduino as IDF Project to build an ESP-Matter over Thread RGB Light using ESP32-C5/C6/H2 and ESP-Matter Arduino API \ This example shall work with Arduino 3.3.2+ and also IDF 5.5.1+\ It is necessary to make sure that the IDF version matches with the one used to release the Arduino Core version.\ This can be done looking into release information in https://github.com/esp
🌐
Reddit
reddit.com › r/esp32 › esp32 arduino tutorial: using the pthreads library
r/esp32 on Reddit: ESP32 Arduino Tutorial: Using the pthreads library
February 1, 2019 -

In this ESP32 tutorial, we will check how to use the pthreads library on the Arduino core and create a simple testing program. The tests of this ESP32 tutorial were performed using a DFRobot’s ESP-WROOM-32 device integrated in a ESP32 development board.

Introduction

In this ESP32 tutorial, we will check how to use the pthreads library on the Arduino core and create a simple testing program. You can read more about pthreads here.

The header file for this library on the Arduino core can be found here. The implementation of the pthreads library can be seen here on the GitHub page of the IDF framework.

From the analysis of the .c implementation file, we can check that this pthreads library is implemented on top of FreeRTOS. Besides that, it is also mentioned that not all the original routines of the library are implemented and some of the functions available don’t implement all of the functionality.

For a list of tutorials about FreeRTOS, please check the related posts section at the end of this tutorial.

The tests of this ESP32 tutorial were performed using a DFRobot’s ESP-WROOM-32 device integrated in a ESP32 FireBeetle board.

The code

We will start our code by importing the pthread.h library, so we can then use the thread functions.

#include <pthread.h>

In the setup function, we will start by opening a serial connection, to print the results of running the program.

Serial.begin(115200);

As we will see later in the function call to create a thread, we will need a variable of type pthread_t, which works like a handle to the created thread [1]. Thus, it can be later used by functions that require a thread identifier [2].

For this tutorial we will be launching 4 threads, so we will create an array of pthread_t variables with size 4.

pthread_t threads[4];

We will also declare an int variable to store the result of the thread creation function and check if any error has occurred during its execution.

int returnValue;

In order to create a thread using the pthreads API, we simply need to call the pthread_create function.

As first input, this function receives a pointer to a pthread_t variable, in which the thread handle will be stored [1].

The second argument is a pointer to a pthread_attr_t structure whose contents are used at thread creation time to determine attributes for the new thread [1]. Nonetheless, in the ESP32 pthreads implementation, using this argument is not supported [3] and thus we should pass NULL here.

As third argument, we pass the thread function, which is the one that will be executed. This thread has a fixed prototype, more precisely it needs to return a pointer to void and receive as input also a pointer to void (void *).

We will call our thread function printThreadId and define it later. This function will simply print a numeric identifier of the thread, which it will receive as input parameter.

The final input parameter of the pthread_create function is an argument that can be passed to our thread function. Thus, it needs to always be of type pointer to void (void *), which is the same type defined in the thread function prototype.

This is a generic type that we need to cast back to our argument data type inside the thread function. Thus, we can use this fourth argument of the pthread_create function to pass a pointer to a more complex data structure that holds all the parameters needed for the thread function.

If our thread function doesn’t need any input argument, we can simply pass NULL here.

In our case, we will pass an integer with the thread number, starting in 0 and finishing in 3 (we will create our threads in a for loop and this value will be the current iteration index).

Note that although our variable is an integer, we will need to cast it to (void*) when passing it to the pthread_create function, which is the data type it receives, as we have mentioned before.Although typically we use this argument to pass pointers to variables, we can actually pass an integer by value since an integer has the same size as a pointer to void (4 bytes). You can confirm this by calling the sizeof function in both data types.

Thus, as long as in the thread function we cast the variable back to int, we can correctly obtain its value. Note however that this cannot be done if the size of the variable we want to pass to the thread is greater than 4 bytes (for example, a struct) and in that case we need to pass a pointer to our data structure.

If the thread is successfully created, the pthread_create function will return zero. Thus, we will store its value in the previously declared variable and check for errors.

You can check the full setup function below, which already includes the loop where the threads are created and the error checking.

void setup() {
 
   Serial.begin(115200);
 
   pthread_t threads[4];
   int returnValue;
 
   for( int i = 0; i< 4; i++ ) {
 
      returnValue = pthread_create(&threads[i], NULL, printThreadId, (void *)i);
 
      if (returnValue) {
         Serial.println("An error has occurred");
      }
   }
 
}

To finalize, we will create our printThreadId function. As mentioned, it needs to respect a defined prototype, which corresponds to returning a pointer to void and receiving as input also a pointer to void.

Since we passed as fourth input of the pthread_create function an integer with the thread index, we will cast it back to int and print it to the serial port.

void *printThreadId(void *threadid) {   
 Serial.println((int)threadid);
 }

Note that the lower level UART functions (implementation file here) write the content inside a critical zone protected by a mutex, so they should be thread safe.

Since we are launching threads, we don’t need the Arduino main loop function. Thus, it can be left empty. The final source code can be seen below.

#include <pthread.h>
 
void *printThreadId(void *threadid) {
   Serial.println((int)threadid);
}
 
void setup() {
 
   Serial.begin(115200);
 
   pthread_t threads[4];
   int returnValue;
 
   for( int i = 0; i< 4; i++ ) {
 
      returnValue = pthread_create(&threads[i], NULL, printThreadId, (void *)i);
 
      if (returnValue) {
         Serial.println("An error has occurred");
      }
   }
 
}
 
void loop() {}

Testing the code

To test the code, simply compile it and upload it to your ESP32 device. After that, open the IDE serial monitor and check the results.

You should get an output similar to figure 1, which shows the indexes of the 4 threads getting printed to the serial monitor.

Figure 1 – Output of the program.

DFRobot supply lots of esp32 arduino tutorials and esp32 projects for makers to learn.