---
title: "Using FreeRTOS multi-tasking in Arduino"
url: "https://maker.wiznet.io/WIZnet/projects/using-freertos-multi-tasking-in-arduino/"
markdown_url: "https://maker.wiznet.io/WIZnet/projects/using-freertos-multi-tasking-in-arduino/md"
type: "UCC: User Created Content"
author: "WIZnet"
author_url: "https://maker.wiznet.io/WIZnet/"
original_url: "https://wiki.seeedstudio.com/Software-FreeRTOS/#:~:text=With%20the%20help%20of%20FreeRTOS,favorite%20Arduino%20boards%20with%20ease!"
published: "2023-02-14"
language: "en"
likes: 4
views: 418
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Using FreeRTOS multi-tasking in Arduino

> .

Original source: https://wiki.seeedstudio.com/Software-FreeRTOS/#:~:text=With%20the%20help%20of%20FreeRTOS,favorite%20Arduino%20boards%20with%20ease!

## Article

## **About this project**

The Arduino IDE and environment has many drivers and libraries available within an arms reach, but the Arduino environment is limited to just **setup()** and **loop()** and doesn’t support **multi-tasking** effectively.

This is a simple, easy to use and robust FreeRTOS implementation that can just shim into the Arduino IDE as a Library and allow the use of the best parts of both environments, seamlessly.

### **Background**

Most operating systems appear to allow multiple programs or threads to execute at the same time. This is called **multi-tasking**. In reality, each processor core can only be running a single program at any given point in time. A part of the operating system called the **scheduler **is responsible for deciding which program to run when, and provides the illusion of simultaneous execution by rapidly switching between each program.

The scheduler in a Real Time Operating System (RTOS) is designed to provide a predictable (normally described as **deterministic**) execution pattern. This is particularly interesting for embedded systems, like the Arduino devices, as embedded systems often have real time requirements.

Traditional real time schedulers, such as the scheduler used in [FreeRTOS](http://www.freertos.org/RTOS.html), achieve determinism by allowing the user to assign a **priority** to each thread of execution. The scheduler then uses the priority to know which thread of execution to run next. In FreeRTOS, a thread of execution is called a **Task**.

### **Let’s get started**

The easiest option is use [Codebender](https://codebender.cc/), where [Arduino FreeRTOS available as a library.](https://codebender.cc/library/Arduino_FreeRTOS)

Otherwise…

Firstly in the Arduino IDE Library manager, from Version 1.6.8, look for the [FreeRTOS Library](https://github.com/feilipu/Arduino_FreeRTOS_Library) under the Type: “Contributed” and the Topic: “Timing”.

![Searching in Arduino Library Manager](https://hackster.imgix.net/uploads/image/file/128500/screenshot-from-2016-03-01-110307.png?auto=compress%2Cformat&w=680&h=510&fit=max)

*Searching in Arduino Library Manager*

Ensure that the most recent FreeRTOS Library Release is installed. As of writing that is **v9.0.0-1**.

![FreeRTOS v8.2.3 Release 6 installed.](https://hackster.imgix.net/uploads/image/file/128501/screenshot-from-2016-03-01-110338.png?auto=compress%2Cformat&w=680&h=510&fit=max)

*FreeRTOS v8.2.3 Release 6 installed.*

Then under the Sketch->Include Library menu, ensure that the **FreeRTOS** library is included in your sketch. A new empty sketch will look like this.

![Empty Sketch with FreeRTOS Included.](https://hackster.imgix.net/uploads/image/file/128502/arduinoide_freertos.png?auto=compress%2Cformat&w=680&h=510&fit=max)

*Empty Sketch with FreeRTOS Included.*

Compile and upload this empty sketch to your Arduino Uno/Yun/Leonardo/Mega or Goldilocks 1284p device. This will show you how much of your flash is consumed by the FreeRTOS scheduler. As a guide the following information was compiled using Arduino v1.6.9 on Windows 10.

```plaintext
// Device:   loop() -> FreeRTOS | Additional Program Storage
// Uno:         444 ->   7340   |     21%
// Goldilocks:  502 ->   7408   |      6%
// Leonardo:   3624 ->  10508   |     24%
// Yun:        3618 ->  10502   |     24%
// Mega:        656 ->  24108   |      9%
```

At this stage FreeRTOS is already running on your device.

### **Next steps**

Now upload and test the Blink sketch, with an underlying Real-Time Operating System simply by inserting `#include <Arduino_FreeRTOS.h>` at the start of the sketch. That’s all there is to having FreeRTOS running in your sketches.

The next step is to explore the features provided by a professional RTOS within the Arduino IDE.

Blink_AnalogRead.ino is a good way to start off as it combines two basic Arduino examples, Blink and AnalogRead into one sketch with two separate Tasks. Both Tasks perform their duties, managed by the FreeRTOS scheduler. This sketch can be found in the Examples Folder of the Arduino IDE.

If you’re interested in [low power or battery applications](https://www.hackster.io/feilipu/battery-powered-arduino-applications-through-freertos-3b7401), it is easy to use FreeRTOS to support the AVR ATmega power reduction modes.

Later articles will cover the [use of Semaphores](https://www.hackster.io/feilipu/using-freertos-semaphores-in-arduino-ide-b3cd6c) to protect hardware resources (like the Serial port), Queues to transfer data between Tasks, or Timers to manage exact delays and timeouts. The [FreeRTOS Getting Started](http://www.freertos.org/FreeRTOS-quick-start-guide.html) page has lots of further information on how to use the advanced features, and provides [Demonstration Examples](http://www.freertos.org/a00102.html). Also many more [AVR FreeRTOS example applications](https://github.com/feilipu/avrfreertos) are available, that can be simply converted to use the Arduino environment.

## **Components**

- 1 × [Arduino UNO & Genuino UNO](https://create.arduino.cc/projecthub/products/buy/41?s=BAhJIhYxNzQyNCxCYXNlQXJ0aWNsZQY6BkVG%0A)

- 1 × [Arduino Yun](https://create.arduino.cc/projecthub/products/buy/250?s=BAhJIhYxNzQyNCxCYXNlQXJ0aWNsZQY6BkVG%0A)

- 1 × [Arduino Leonardo](http://www.arduino.cc/en/Main/ArduinoBoardLeonardo)

- 1 × [Arduino Micro & Genuino Micro](https://create.arduino.cc/projecthub/products/buy/112?s=BAhJIhYxNzQyNCxCYXNlQXJ0aWNsZQY6BkVG%0A)

- 1 × [Arduino Mega 2560 & Genuino Mega 2560](https://create.arduino.cc/projecthub/products/buy/145?s=BAhJIhYxNzQyNCxCYXNlQXJ0aWNsZQY6BkVG%0A)

- 1 × [SeeedStudio Seeeduino Lite](https://create.arduino.cc/projecthub/products/buy/8571?s=BAhJIhYxNzQyNCxCYXNlQXJ0aWNsZQY6BkVG%0A)

- 1 × [SeeedStudio Seeeduino Stalker V3](https://create.arduino.cc/projecthub/products/buy/8572?s=BAhJIhYxNzQyNCxCYXNlQXJ0aWNsZQY6BkVG%0A)

- 1 × [SeeedStudio Seeeduino Ethernet](https://create.arduino.cc/projecthub/products/buy/8573?s=BAhJIhYxNzQyNCxCYXNlQXJ0aWNsZQY6BkVG%0A)

- 1 × [SparkFun Pro Micro – 5V/16MHz](https://create.arduino.cc/projecthub/products/buy/81?s=BAhJIhYxNzQyNCxCYXNlQXJ0aWNsZQY6BkVG%0A)

- 1 × [SparkFun RedStick](https://create.arduino.cc/projecthub/products/buy/563?s=BAhJIhYxNzQyNCxCYXNlQXJ0aWNsZQY6BkVG%0A)

- 1 × SparkFun MicroView – OLED Arduino Module

Author : [Phillip Stevens](https://create.arduino.cc/projecthub/feilipu)

Source : https://create.arduino.cc/projecthub/feilipu/using-freertos-multi-tasking-in-arduino-ebc3cc?ref=search&ref_id=ethernet&offset=77

---

Source: https://maker.wiznet.io/WIZnet/projects/using-freertos-multi-tasking-in-arduino/
