Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Arduino support threading?

Tags:

I have a couple of tasks to do with arduino but one of them takes very long time, so I was thinking to use threads to run them simultaneously. I have an Arduino Mega

[Update] Finally after four years I can install FreeRTOS in my arduino mega. Here is a link

like image 493
Snake Sanders Avatar asked Dec 22 '12 12:12

Snake Sanders


People also ask

How many threads can Arduino run?

Using the ThreadHandler library to run 57 hard real-time threads on an Arduino Uno with only 2048 bytes of memory.

Does Arduino Mega support multithreading?

The Arduino has a single core, it can't do multithreading. But if you write non-blocking code you can make things appear to happen at the same time. I imagine the problem with your code now is that you have probably used the delay function. That function blocks, so nothing else can happen while the delay is running.

Do microcontrollers have threads?

Yes, most microcontrollers have enough hardware support so that threading is possible. If the hardware call/return mechanism is stack based, then all you really need is arbitrary access to the stack.

Can Arduino do multitasking?

The Arduino is a very simple processor with no operating system and can only run one program at a time. Unlike your personal computer or a Raspberry Pi, the Arduino has no way to load and run multiple programs. That doesn't mean that we can't manage multiple tasks on an Arduino.


2 Answers

In short: NO. But you may give it a shot at: http://www.kwartzlab.ca/2010/09/arduino-multi-threading-librar/

(Archived version: https://web.archive.org/web/20160505034337/http://www.kwartzlab.ca/2010/09/arduino-multi-threading-librar

Github: https://github.com/jlamothe/mthread

like image 151
Filipe YaBa Polido Avatar answered Sep 18 '22 18:09

Filipe YaBa Polido


Not yet, but I always use this Library with big projects: https://github.com/ivanseidel/ArduinoThread

I place the callback within a Timer interrupt, and voilá! You have pseudo-threads running on the Arduino...

like image 36
Ivan Seidel Avatar answered Sep 21 '22 18:09

Ivan Seidel