Arduino and other microcontroller boards' enhanced capabilities, such as faster clocks or even multiple cores, the requirement to manage numerous activities at once is more frequent than in the past. For instance, you frequently need to manage motors, update a display, and detect user inputs all at once, as well as handle operations with various timings or wait for outside events.
To update state variables and call the millis() function to ensure accurate timing, the loop() function is typically written in a non-blocking manner (for more information, see the "Blink without delay" example). However, this method results in bloated code that is difficult to debug and maintain and does not support many cores.
The Scheduler library already enables better code development by dividing the sketch into numerous loop functions, each of which may concentrate on a different job. However, as this method is known as cooperative multitasking, you must still refrain from blocking orders on your own. Additionally, even if it did, it wouldn't prevent you from accessing the same variables from different threads because it doesn't allow many cores. Not to mention that it is built on the conventional "busy loop" paradigm, which is not very helpful for low-power applications where you want threads to rest as much as possible as you wait for an event or incoming data.
How can add multitasking to Arduino?
The objective is to design a standardized API that can be used in any architecture and that, in keeping with the Arduino ethos, will make difficult tasks simple for everyone. Since the idea of multitasking is difficult, we have lots of room to use the Arduino method to make it accessible to everyone.
We invite the technical community to participate in the conversation on GitHub and provide our proposed API along with an actual, fully functional implementation. Let us know what you think, and let's work together to make this new feature a reality!
The brand-new repository, which serves as the new base for the development of the Arduino language, is where this community conversation is being housed.
Original Post - Blog Arduino