Multitasking for arduino

For information

There is a GitHub entry for discussion of the proposed API

Aha. Well, I've thought along similar lines - a "non-blocking code generator". This will be worth a look. The difficulty is - it's hard to make things generic. We know how easy it is to make a non-blocking API for specific applications, e.g. timing.

An average Arduino user doesn't even know how to use millis()
Arduino: it is time we add threads!

1 Like

I don't believe you could start beginners on an RTOS without dumbing it down so much, it would be hard to make a lot of things work.

Also a straightforward RTOS requires a kernel, albeit a minimal one at least. The 328 doesn't have much memory for stuff like that.

What about the libraries? No more, "here is a TM1637 display. To use, just download TM1637.h" (I wouldn't, this is just what I've seen on places like AliE).

How long would it take the community to build up a library support base?

Well, judging by how much hype was put in Nano Connect and what piece of sh*t support it got, I wouldn’t even consider anything as complicated as multitasking from Arduino

Another way to say that, it would require a really high level of community support. Of course there is a chicken and egg problem there...


Then there is resource allocation...

That's why I wrote a Task Macro library once and don't have to touch it any more. It runs even on the smallest Arduino.

Maybe a more accurate statement would be, "it requires both community support and and commitment from Arduino team".

To get new people using it, it has to be one of the first things they see.

I guess it is time to have a look there


This library makes it easy to use the multi-threading capability of Arduino boards that use an Mbed OS-based core library. Additionally this library provides thread-safe access to Wire , SPI and Serial which is relevant when creating multi-threaded sketches in order to avoid common pitfalls such as race-conditions and invalid state. ​

Yes they don’t.

I think the idea is to abstract that with a new .inot (the t Suffix is for thread) Extension that the IDE knows about which include their own setup and loop and you will be able to fork those as tasks. (Having multiple loops is a very frequent request)

There is support for shared variables with automatic hidden protection for concurrent access

A Shared variable is a global variable accessible to all threads. It can be declared within a header file named SharedVariables.h which is automatically included at the top of each *.inot -file

There will be a lot of files in a simple project!

For the wrong reasons. So providing multiple loop()s might fix the wrong problem....

To beginners in the programming world that does not sound a bad request. I don’t think it’s unreasonable or there is a wrong reason.

Multi-tasking and Arduino, need to be bought into context.

Multi-tasking and Arduino IDE is more appropriate.

Just Arduino brings to memory 8bit AVR basic but very versatile and useful ground level controllers.

Exactly, before looking at multi-tasking, look at the hardware available.

Tom... :smiley: :+1: :coffee: :australia:

Sure but they target hardware with more resources than an UNO

Which request are you referring to ?

To beginners in the programming world everything seems complicated and I can't help feeling that adding multitasking makes it even more complicated

Multiple loops

Multitasking is something we commonly do day to day. The difficulty comes from the need of sync points or unicity of some hardware resources (SPI, I2C,…) which they (arduino team) seem to have made provision for

I think it's much easier to start: i.e., using a FreeRTOS thead is a simpler concept than multitasking with millis(). However, it will still get complex quickly.

In the end, the root of the problem is if people don't want to understand software development. You won't go very far with arduino if you only stick to the very basics of programming.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.