NewsIntroducing multitasking to Arduino

Introducing multitasking to Arduino

Category articles

With the increasing abilities that are available on Arduino and other microcontroller boards, such as more powerful clocks, or perhaps multiple processors, the requirement to manage multiple tasks at once is more frequent than it did in the past. For instance, you might require control of motors or update a display, and monitor user interaction at the same time or complete tasks with distinct timings or require external events.

The usual method to accomplish it is write code that is non-blocking to ensure that loop() function will be run as fast as it is possible by updating state variables while running millis() function to ensure the proper timing (see this “Blink without delay” example for more information). This method results in bloated code that is difficult to troubleshoot or maintain. Furthermore, it doesn’t allow for multiple cores.

The Scheduler library lets you write code in a simpler method by dividing the sketch into multiple loops to ensure that each can be focused on a specific task. This method is known as cooperative multitasking that means that you have to be aware of blocking commands. Additionally, it doesn’t support multiple cores , and even if it did , it does not protect you from using the same variable across multiple threads. Not to mention, it’s built on the classic “busy loop” paradigm, which isn’t very helpful for applications with low power in which you need to let threads idle for as long as they can in anticipation of an event or the incoming data.

How do I add multitasking functionality to the Arduino?

The objective is to create a standard API that is able to be used across all platforms and conforms to the Arduino concept, will make complex things simple for everyone. Multitasking is a difficult idea, therefore there is plenty of room to apply the Arduino approach to make it accessible to all.

We’re inviting our technical community to participate in the discussion on GitHub and we’re offering our API suggestion as well as a fully functioning implementation. Please let us know what you think and let’s collaborate to finish this feature!

The community discussion is hosted by the new repository which is the latest location for the development of Arduino language.

Michal Pukala
Electronics and Telecommunications engineer with Electro-energetics Master degree graduation. Lightning designer experienced engineer. Currently working in IT industry.