Arduino programming guide series

A real-time OS for the Arduino

A real-time operating system is optimized so that processing is completed within tight time bounds, and execution is consistent and predictable. It is the preferred operating system for critical applications. And a version of it works on the Arduino Uno.

In a previous article in this series, I discussed a simple approach for implementing multitasking on the Arduino. This approach is based on the finite state machine paradigm. It is good enough if your program has relatively few states, for example controlling "simultaneously" two or three devices.

However, as an application becomes more complicated, the state machine approach becomes harder to handle and more prone to defects.

When that happens, it is time to turn your attention to something more robust. One such solution is FreeRTOS, or "Free Real-Time Operating System".

FreeRTOS is not a solution specific to the Arduino.

It is software that runs on many microcontrollers and microprocessors. It is a commercially developed product, with an open-source license that allows people to integrate it into their designs, free of charge, for open-source and even commercial closed source projects.

It is recognized as a high-quality, well tested, documented and supported real-time operating system.

Most people are used to general-purpose operating systems, like Windows and Mac OS. These OSs manage the resources of the host computer so that the various processes that are running on top of it get their "fair" share. The OS is responsible for allocating resources (like memory and CPU time). The OS will make a best-effort attempt to allocate resources to a process but will give no guaranty that it will.

A scheduler is a special service within the OS that makes such decisions based on various scheduling algorithms. In general-purpose operating systems, the scheduler tries to be fair to all processes but can make no guarantees.

A real-time OS, on the other hand, is designed so that each process will get the resources it needs in a predictable way.

Critical applications, such as medical, avionics, and industrial automation, depend on predictable patterns in the way that the scheduler allocates resources to a process. Therefore, a general-purpose OS is not suitable, and a real-time OS takes over. 

A real-time OS is not meant to work on the type of processors that we find in a personal computer, but usually on microcontrollers used in embedded applications.

Unlike in general-purpose computing, the applications in which a microcontroller is used are very specific: they are only designed to do a particular set of functions, reliably, and predictably. The real-time OS ensures the scheduling, inter-process communication, and synchronization of the processes that make up the firmware running on these microcontrollers.

You can use FreeRTOS on the Arduino, of course!

There is a FreeRTOS library that you must install first (just search for "FreeRTOS" in the Library Manager), and a respectable learning curve to get through. A good place to get started is Maniacbug's Github repository, which contains examples of Arduino sketches that use FreeRTOS, and the FreeRTOS Quick Start Guide page on freertos.org

Tech Explorations Arduino intermediate level

Done with the basics? Looking for more advanced topics?

Arduino Step by Step Getting Serious is our comprehensive Arduino course for people ready to go to the next level.

Learn about Wi-Fi, BLE and radio, motors (servo, DC and stepper motors with various controllers), LCD, OLED and TFT screens with buttons and touch interfaces, control large loads like relays and lights, and much much MUCH more.


We publish fresh content each week. Read how-to's on Arduino, ESP32, KiCad, Node-RED, drones and more. Listen to interviews. Learn about new tech with our comprehensive reviews. Get discount offers for our courses and books. Interact with our community. One email per week, no spam; unsubscribe at any time

Image
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}