Main Content

Simple Multi-tasking in Arduino on Any Board

The instructable describes how to run multiple tasks on your Arduino without using an RTOS. Your ‘tasks’ are just normal methods, called directly from the loop() method. Each ‘task’ is given a chance to run each loop. You can either use a flag to skip ‘tasks’ that don’t need to be run or, more often, just return immediately from the method call if that task has nothing to do. Each task is called in a round robin manner.

As a practical application, this instructable will develop a temperature controlled, stepper motor driven damper with a user interface. The entire project can be developed and tested on just an Arduino UNO. Because this instructiable is concentrating on the software, the external thermocouple board and stepper motor driver libraries are used, but the hardware is omitted and the input temperature simulated in the software.

Finally the same project code is moved from the UNO to an ESP32 so that you can control it remotely via WiFi, BLE or Bluetooth.

If you search for ‘multitasking arduino’ you will find lots of results. Most of them deal with removing delays or with using an RTOS. This page goes beyond just removing delays, that was covered in How to code Timers and Delays in Arduino (instructable), and covers the other things you need to do for multi-tasking Arduino without going to an RTOS. This instructable also covers moving from an Arduino to an FreeRTOS enabled ESP32 board and why you may want to keep using “Simple Multi-tasking” approach even on a board that supports an RTOS.”

Link to article

Related Content