I am trying to use protothreads on Arduino Uno. I am following https://techtutorialsx.com/2017/12/30/esp32-arduino-using-the-pthreads-library/ .
I have downloaded the pthread.h header file and put it in the same directory as my .ino file.
I have changed the #include statement from the tutorial to #include "pthread.h" as the file is present in the same directory as my .ino file.
I am getting the following error:
Protothreading_example:11:4: error: 'pthread_t' was not declared in this scope
pthread_t threads[4];
^
Protothreading_example:16:37: error: 'threads' was not declared in this scope
returnValue = pthread_create(&threads[i], NULL, printThreadId, (void *)i);
^
Protothreading_example:16:79: error: 'pthread_create' was not declared in this scope
returnValue = pthread_create(&threads[i], NULL, printThreadId, (void *)i);
^
exit status 1
'pthread_t' was not declared in this scope
I have two follow up questions:
1) Is there a better tutorial source for protothreading on Arduino?
2) I need to read data from multiple sensors and process separately. Since Arduino does not support multithreading at the hardware level, I have made another implementation to loop through an array of function pointers with a timer. Is this approach the same as protothreading?
The tutorial you mentioned is intended for ESP32, which has a different Arduino core than the Arduino Uno itself. Primarily it contains FreeRTOS, which supplies the underlying mechanisms for this library. It will not work with Arduino Uno as is.
I believe that you do not need multithreading for your application. You can just loop through the sensor readings and process it in the end of your loop. A step forward to concurrency would be to use a simple scheduler .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.