Arduino has recently been releasing a large number of boards geared towards IOT applications such as the MKR family, the new Nano family, the Portenta H7 etc. Out of these, the Nano family has a very special feature, that is the integration of ARM’s Mbed OS, a powerful but lightweight, open-source Real Time Operating system built for 32-bit ARM Cortex microcontrollers & processors.
In this article, I will be demonstrating how to get start writing programs using the Mbed library on supported Arduinos with the Arduino IDE. Let’s get started!
Bootloader vs RTOS
Before we begin, it is important to understand some of the key differences between a bootloader (used by entry level 16-bit Arduinos such as the UNO, Mega, Micro etc.) and a Real Time Operating Systems.
A bootloader is a simple program which serves one singular purpose, that is to allow your program to be uploaded to and run on the target device. A diagram can be used to better understand this-
When your Arduino is powered on, the bootloader is the first program to start running. The program you would have previously uploaded to the Arduino is stored in the ROM and can not start running immediately. The bootloader then loads the stored program from ROM to RAM, after which it relinquishes all control. It is then the programmer’s responsibility to define abstractions over and to manage system resources. This also prevents multiple programs from running simultaneously as the bootloader is not capable of time-slicing.
All of the entry level Arduinos such as the UNO, MEGA, Micro, Pro etc. use bootloaders as they use smaller 16-Bit AVR chips running at lower frequencies.
An Operating System, on the other hand is a much larger program which is responsible for allowing other programs to run in a systematic way.
Unlike the bootloader, an OS always runs in the background and provides a layer of abstraction over the core hardware resources for your program/programs by acting as a middleman. It can also time-slice, allowing multiple programs to run at the same time and giving the illusion of multi-tasking.
Operating systems often require slightly more powerful and complicated microcontrollers for any meaningful advantages to show up and as a result are not used in the previously mentioned Arduinos. They are, however, used in the newer ARM based Arduinos, which is what we will be using today.
As of now, the only boards which support Mbed OS integration are the Arduino Nano 33 BLE and Arduino Nano 33 BLE Sense. However, in the future, there are more boards to come and this list will be updated as they do.
Now that the you know about the supported Arduinos, it is finally time to gets started with the Mbed Library using the Arduino IDE. For these examples, I will be using the Arduino Nano 33 BLE.
To start, you will first have to make sure that all the necessary libraries and dependencies are in their appropriate locations, without which the Arduino IDE will not be able to make any sense of the Mbed language. Start by making sure you have the latest version of the Arduino IDE installed (which is 1.8.12 as of writing this article). The latest version of the Arduino IDE can be found here.
Then, make sure you have the latest version of the nrf528x boards from the boards manager. Even if you have previously installed and configured the Nano 33 BLE, it is important to update to the latest version as it is the easiest way to get all the Mbed libraries into your IDE. If you have not already configured the Nano 33 BLE or BLE sense, then click here.
Now that all that is out of the way, you should be able to include the Mbed library in your sketch and be able to compile it without any issues, as shown below.
And that’s it! You have set up everything required to use an RTOS with your Arduino. In the next blog, I will be going over writing your first sketch and using a few basic Mbed functions along with a simple multithreaded program. Click here to go right to it.