简体   繁体   English

Arduino Uno上的Protothreading / Multithreading

[英]Protothreading/ Multithreading on Arduino Uno

I am trying to use protothreads on Arduino Uno. 我试图在Arduino Uno上使用protothreads。 I am following https://techtutorialsx.com/2017/12/30/esp32-arduino-using-the-pthreads-library/ . 我正在关注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. 我已经下载了pthread.h头文件并将其放在与我的.ino文件相同的目录中。

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. 我已将教程中的#include语句更改为#include“pthread.h”,因为该文件与我的.ino文件位于同一目录中。

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? 1) Arduino上是否有更好的原始阅读教程来源?

2) I need to read data from multiple sensors and process separately. 2)我需要从多个传感器读取数据并单独处理。 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. 由于Arduino不支持硬件级别的多线程,我已经做了另一个实现来循环使用带有计时器的函数指针数组。 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. 您提到的教程适用于ESP32,它具有与Arduino Uno本身不同的Arduino核心。 Primarily it contains FreeRTOS, which supplies the underlying mechanisms for this library. 它主要包含FreeRTOS,它为该库提供底层机制。 It will not work with Arduino Uno as is. 它不适用于Arduino Uno。

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 . 向并发的一步是使用简单的调度程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM