Setting up RIOT-OS on Arduino – An Operating System for Internet of Things

Getting Started with Arduino and RIOT-OS

When we talk about embedded projects, Arduino comes first in our mind. But why Arduino? Because Arduino is a Single-core Microcontroller, which is available in the market at a very low price. And besides, there are various supported sensor/actuator boards available, which we can use as a plug and play. Here at IoTDesignPro, we have also built many IoT projects with Arduino, you can check them out if interested.

 

But when it comes to applications with time complexity, where we have to execute multiple tasks in real-time, we start doubting. Is Arduino good for this project or should we change it? What will we do? Here, RIOT comes as a rescue. 

 

You might be thinking what is RIOT? Well, RIOT is not a complicated thing, in fact, it is a real-time operating system for embedded systems that comes with various libraries, to help us to complete the IoT operation as well. In short, we call RIOT-OS “the friendly operating system for IoT”. We already covered the tutorial on “What and How to use RIOT-OS in Embedded Devices” where we can know more about the RIOT-OS.

 

In this tutorial, we are Getting Started with Arduino and RIOT-OS, and Setting up RIOT-OS on Arduino. We will demonstrate a LED blink operation into another task on Arduino using RIOT-OS.

 

Components Required

  1. Arduino Uno/Nano (I use Arduino Nano)
  2. LED (I use Red LED)
  3. 220Ω Resistor
  4. BreadBoard
  5. Jumper Wires
  6. Latest Release RIOT-OS SDK
  7. Any IDE which supports the C Makefile project.
  8. USB Cable
  9. I use Ubuntu 16.04 for developing the application. (RIOT-OS currently support on Linux/MAC-OS)

 

Hardware Connection of the LED with Arduino Nano

The complete connection diagram of the set-up is shown below. You just have to follow the figure to make the connections to see the LED blink.

Arduino Nano Circuit

 

Code Explanation

In this project, we use RIOT-OS to make a LED blink with an interval of 1sec from an independent thread.

Those libraries mentioned below are included at the beginning of the code.

//Include Libraries
#include <stdio.h>
#include "thread.h"        // Use for Create the Thread
#include "xtimer.h"        // Use for create the delay
#include "periph/gpio.h"    // Use for GPIO operations

 

Next, define a “#define” variable with the name of “EXTERNAL_LED”, for accessing the LED which is connected with the Arduino-Nano GPIO-A5. But in the RIOT OS, all module pins are mapped with their PORT & PIN. If the microcontroller’s PORTs are called by “PORT-A, PORT-B, PORT-C, …..” or “PA, PB, PC, …..” or “P0, P1, P2, …..”, then in RIOT OS, those PORTs are assigned with the number like “0, 1, 2, …..” and so on. So, when we need access to GPIO-A5, which is mapped with the atmega328p pin "PC5", then we need to call the GPIO_PIN(PORT, PIN)  function, where the port=0 and pin=5.

// Arduino-Nano On-Board LED connected with "A5" which mapped with atmega328p pin "PC5"
#define EXTERNAL_LED GPIO_PIN(2,5)

 

Now, create a stack for a task and implement the task function to do the Led blink process independently with the interval of 1sec.

#define DELAY_SEC        1    // 1sec
char task1_stack[THREAD_STACKSIZE_MAIN];
/**
 *
 */
void *Task1(void *arg)
{
    (void) arg;
    printf("Create Task1 Thread for Blink the External LED from the %s board.\n", RIOT_BOARD);
    gpio_init (EXTERNAL_LED, GPIO_OUT);
    while(1){
        puts("Task1\r\n");
        gpio_write (EXTERNAL_LED, 1);
        xtimer_sleep(DELAY_SEC);
        gpio_write (EXTERNAL_LED, 0);
        xtimer_sleep(DELAY_SEC);
    }
    return NULL;
}

 

In the main() loop, we create the thread using thread_create() function.

/**
 *
 */
int main(void)
{
#if 1
    printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
    printf("This board features a(n) %s MCU.\n", RIOT_MCU);
#endif
   thread_create(task1_stack,                         /* stack array pointer */
            sizeof(task1_stack),                            /* stack size */
            THREAD_PRIORITY_MAIN - 1,            /* thread priority */
            THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,        /* thread configuration flag, usually By default, the thread starts immediately */
            Task1,                                                 /* thread handler function */
            NULL,                                                 /* argument of thread_handler function */
            "task1"                                                /* thread_name */
            );            
    while(1){        
        puts("--> I'm Main \n");
        xtimer_sleep(2);
    }
    return 0;
}

 

Testing and Debugging RIOT Communication Process

Once the circuit and code are complete, we build and tested code with the help of these commands.

So, in this case, we use Ubuntu 20.04.2 LTS-64bit, and to create the development environment, we need to install the prerequisite before setting up the RIOT OS.

sudo apt-get update && sudo apt-get upgrade

Setting up RIOT-OS on Arduino

sudo apt-get install build-essential cppcheck git make gcc pkg-config autoconf automake libtool libusb-dev libusb-1.0-0-dev libhidapi-dev libftdi-dev g++-multilib gcc-multilib python3-serial curl doxygen graphviz pcregrep python python3 python3-flake8 unzip wget

RIOT-OS on Arduino

sudo add-apt-repository ppa:npalix/coccinelle
sudo apt-get install coccinelle

RIOT Communication Process

 

After installing all requirements, we can set up the RIOT-OS. For that, we need to create a workspace folder for download and git clone the latest release of RIOT-OS. To do this, follow these steps:

cd $HOME
mkdir riot_workspace
cd riot_workspace/
git clone git://github.com/RIOT-OS/RIOT.git
cd RIOT/
git checkout 2021.01

RIOT Communication Process

 

Now it’s time to set up the Hardware Toolchain, for Arduino.

sudo apt-get install gcc-avr avr-libc avrdude 

 

After setup, the RTOS-OS for Arduino, it’s time to compile the code. For Build/Compile the code, we need to call the make command along with the BOARD argument.

In our case, we used an Arduino-Nano Dev Board, so the board’s value is “arduino-nano”. If you use a different board, then please check the path [$HOME/riot_workspace/RIOT/boards] for the supported Arduino board’s list.

make BOARD=arduino-nano

Debugging RIOT Communication Process

 

For flashing the code into the Arduino Nano, we need to call the flash command.

make BOARD=arduino-nano PORT=/dev/ttyUSB0 flash

Debugging RIOT Communication Process

 

After flashing the code, we need to call the term command to check the log output on the screen.

make BOARD=arduino-nano PORT=/dev/ttyUSB0 term

RTOS Arduino

[Note: If any error occurs like “Permission denied: '/dev/ttyUSB0'” then call this command to resolve this “sudo chmod a+rw /dev/ttyUSB0”]

Arduino with LED

You will get more information about RIOT-OS and Arduino from their Tutorials and documentation. Link: Doc.RIOT-OS.org/arduino & RIOT-OS.github.io/riot-basics

Code

/*
 * Copyright (C) 2013 INRIA
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */
/**
 * Project Name: arduino_riot_blink_led
 * Created on: 8-May-2021
 * Author: Noyel Seth (noyelseth@gmail.com)
 */
//Include Libraries
#include <stdio.h>
#include "thread.h"        // Use for Create the Thread
#include "xtimer.h"        // Use for create the delay
#include "periph/gpio.h"    // Use for GPIO operations
// Arduino-Nano On-Board LED connected with "A5" which mapped with atmega328p pin "PC5"
#define EXTERNAL_LED    GPIO_PIN(2,5)
#define DELAY_SEC        1    // 1sec
char task1_stack[THREAD_STACKSIZE_MAIN];
/**
 *
 */
void *Task1(void *arg)
{
    (void) arg;
    printf("Create Task1 Thread for Blink the External LED from the %s board.\n", RIOT_BOARD);
    gpio_init (EXTERNAL_LED, GPIO_OUT);
    while(1){
        puts("Task1\n");
        gpio_write (EXTERNAL_LED, 1);
        xtimer_sleep(DELAY_SEC);
        gpio_write (EXTERNAL_LED, 0);
        xtimer_sleep(DELAY_SEC);
    }
    return NULL;
}
/**
 *
 */
int main(void)
{    
#if 1
    printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
    printf("This board features a(n) %s MCU.\n", RIOT_MCU);
#endif
   thread_create(task1_stack,                         /* stack array pointer */
            sizeof(task1_stack),                            /* stack size */
            THREAD_PRIORITY_MAIN - 1,            /* thread priority */
            THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,        /* thread configuration flag, usually By default, the thread starts immediately */
            Task1,                                                 /* thread handler function */
            NULL,                                                 /* argument of thread_handler function */
            "task1"                                                /* thread_name */
            );            
    while(1){        
        puts("--> I'm Main \n");
        xtimer_sleep(1); // 1sec delay
    }
    return 0;
}

Video

24 Comments

I am also commenting to let you know of the brilliant experience my friend's princess undergone browsing your blog. She came to find a lot of issues, which include how it is like to possess an excellent giving character to get many people with ease fully understand a variety of impossible subject areas. You undoubtedly did more than people's expected results. Many thanks for supplying these beneficial, dependable, revealing and as well as easy guidance on this topic to Gloria.

My husband and i felt quite comfortable that Edward managed to complete his investigations using the precious recommendations he discovered using your web site. It's not at all simplistic to simply continually be handing out hints the rest may have been trying to sell. And we all do understand we now have you to thank because of that. The specific explanations you've made, the easy web site navigation, the relationships you will give support to foster - it's many powerful, and it's letting our son in addition to the family do think this theme is awesome, which is extremely indispensable. Thanks for the whole thing!

I simply desired to say thanks yet again. I am not sure the things I might have taken care of in the absence of the type of recommendations discussed by you over such a theme. It seemed to be the depressing dilemma in my circumstances, but finding out a new skilled strategy you resolved that forced me to weep over fulfillment. Extremely grateful for the work and then have high hopes you find out what an amazing job that you are putting in teaching other individuals all through your website. Most probably you've never encountered any of us.

I not to mention my buddies have already been digesting the excellent thoughts on your web blog while suddenly I had an awful suspicion I never thanked the website owner for those techniques. These young men appeared to be for this reason joyful to see all of them and have now quite simply been making the most of those things. I appreciate you for indeed being simply considerate and also for utilizing this sort of fantastic areas millions of individuals are really desperate to learn about. My very own honest apologies for not saying thanks to you sooner.

Thank you a lot for providing individuals with an extremely splendid possiblity to read critical reviews from this blog. It's usually so sweet and as well , packed with amusement for me personally and my office co-workers to visit your blog not less than three times in 7 days to read the fresh guidance you will have. And indeed, I'm also at all times happy considering the attractive things you serve. Some 3 facts in this posting are easily the most beneficial I have ever had.

My wife and i ended up being absolutely joyous when Edward could complete his research from the ideas he received from your own web page. It's not at all simplistic to simply find yourself giving out guidance others have been making money from. And we all remember we have the website owner to give thanks to for that. The most important explanations you made, the straightforward site navigation, the friendships you can give support to foster - it's got all impressive, and it is letting our son and us know that this situation is amusing, and that's truly serious. Many thanks for the whole thing!

I and my friends happened to be following the great tips and tricks found on the website then before long developed a terrible suspicion I never expressed respect to the web site owner for those strategies. All the young boys came glad to read all of them and have certainly been using them. Thank you for actually being quite accommodating as well as for choosing certain beneficial guides millions of individuals are really eager to understand about. My very own honest apologies for not saying thanks to sooner.

I have to point out my love for your kind-heartedness giving support to men and women that require guidance on the field. Your very own dedication to passing the message up and down came to be astonishingly beneficial and has usually allowed folks much like me to achieve their ambitions. Your personal useful tutorial entails much to me and much more to my office colleagues. Best wishes; from each one of us.

I want to show my affection for your kindness for people that need help on this situation. Your special commitment to getting the message all over had become particularly powerful and has consistently encouraged workers just like me to attain their goals. Your new warm and helpful instruction implies a great deal to me and especially to my mates. Thanks a lot; from each one of us.

I needed to put you the very little remark to be able to thank you very much as before on the exceptional strategies you have provided above. It has been quite particularly generous of people like you to provide extensively all a few people would've distributed as an ebook to help make some dough on their own, mostly considering that you could have tried it if you desired. These good tips as well served like the good way to be sure that other people have the identical desire the same as my own to understand a good deal more on the subject of this issue. Certainly there are thousands of more fun times in the future for folks who scan through your website.

I really wanted to write down a brief message in order to thank you for those fantastic recommendations you are sharing at this website. My prolonged internet lookup has at the end been compensated with high-quality ideas to go over with my family. I 'd assert that most of us visitors are undoubtedly blessed to exist in a fine community with so many marvellous individuals with interesting principles. I feel extremely lucky to have seen your entire website page and look forward to plenty of more enjoyable times reading here. Thanks a lot once more for all the details.

I and also my guys have been analyzing the great tactics on your web blog and suddenly developed a terrible suspicion I never thanked the web blog owner for them. Most of the men had been for that reason passionate to read through them and have now sincerely been enjoying them. Appreciation for really being considerably kind and also for pick out this kind of excellent areas millions of individuals are really eager to discover. My sincere apologies for not saying thanks to you sooner.

I have to show my appreciation to the writer for bailing me out of this particular condition. As a result of browsing throughout the online world and meeting ideas that were not powerful, I figured my entire life was done. Living without the solutions to the difficulties you've sorted out through your main short post is a crucial case, and the ones which may have in a negative way affected my career if I hadn't encountered your blog post. Your own personal know-how and kindness in maneuvering all the stuff was excellent. I don't know what I would've done if I hadn't come across such a thing like this. I am able to now look forward to my future. Thanks very much for your high quality and sensible help. I will not hesitate to propose the sites to anyone who requires care about this subject matter.

I would like to express appreciation to the writer just for bailing me out of this type of scenario. Right after browsing throughout the search engines and meeting views which were not powerful, I figured my life was done. Being alive without the presence of strategies to the problems you've resolved by way of the article content is a critical case, as well as ones which may have in a wrong way affected my entire career if I had not noticed the blog. That capability and kindness in handling almost everything was helpful. I'm not sure what I would've done if I hadn't come upon such a subject like this. I can also at this moment look forward to my future. Thanks a lot very much for your reliable and sensible guide. I won't think twice to suggest your web sites to any person who would like assistance about this area.

I wish to convey my love for your kindness in support of people that absolutely need assistance with that area. Your special commitment to getting the message along appears to be especially good and have constantly enabled folks just like me to realize their ambitions. Your personal useful recommendations signifies a lot a person like me and especially to my mates. Warm regards; from everyone of us.

I wanted to make a small message to be able to say thanks to you for all the marvelous items you are giving here. My considerable internet look up has now been recognized with beneficial facts and strategies to exchange with my relatives. I would say that many of us site visitors actually are really blessed to exist in a remarkable community with very many brilliant individuals with helpful methods. I feel somewhat lucky to have used your web page and look forward to many more thrilling moments reading here. Thank you again for a lot of things.

I am glad for writing to make you understand of the remarkable discovery my wife's daughter enjoyed checking your site. She noticed lots of issues, including what it's like to possess an awesome helping mindset to get many people with no trouble learn selected extremely tough matters. You really exceeded readers' expectations. Thank you for churning out these warm and friendly, safe, informative and cool tips about the topic to Sandra.

I simply wanted to thank you very much once again. I do not know what I could possibly have undertaken in the absence of the entire information documented by you relating to this theme. It truly was an absolute frustrating condition in my position, however , viewing the professional technique you processed the issue forced me to cry with joy. Now i'm grateful for this guidance and even hope that you comprehend what a great job that you're carrying out educating men and women via a site. I'm certain you have never got to know any of us.

I must show some appreciation to this writer just for rescuing me from this trouble. Right after scouting through the world wide web and getting tricks which are not beneficial, I assumed my entire life was done. Existing without the solutions to the difficulties you have sorted out as a result of your website is a crucial case, as well as those which might have adversely affected my career if I had not encountered your site. Your personal ability and kindness in maneuvering all the stuff was helpful. I am not sure what I would've done if I had not encountered such a subject like this. I am able to at this point look forward to my future. Thanks a lot so much for the skilled and amazing help. I won't be reluctant to suggest your blog post to anyone who desires support about this matter.

My wife and i got now thankful when John could carry out his web research out of the ideas he made in your web site. It's not at all simplistic to just continually be offering secrets that many other folks might have been trying to sell. And we already know we've got the website owner to give thanks to for that. The type of explanations you made, the straightforward website navigation, the relationships your site help to create - it's got everything exceptional, and it's leading our son in addition to us reason why this idea is enjoyable, which is wonderfully indispensable. Thank you for the whole thing!

I and also my friends were actually reviewing the nice secrets located on the website and so instantly I got an awful suspicion I had not expressed respect to the web blog owner for those strategies. My young boys came totally glad to learn all of them and have in effect undoubtedly been taking advantage of those things. Appreciation for getting really considerate and for having variety of incredibly good information most people are really desirous to learn about. Our own sincere regret for not expressing appreciation to you sooner.

I wanted to post a remark to be able to appreciate you for all of the stunning ways you are giving out on this website. My considerable internet investigation has at the end been recognized with awesome facts and techniques to exchange with my friends. I would state that that we website visitors are truly blessed to dwell in a wonderful place with very many wonderful professionals with great tactics. I feel very blessed to have seen the webpages and look forward to so many more thrilling times reading here. Thanks a lot once more for all the details.

My husband and i felt so satisfied that Emmanuel managed to finish up his investigations from your precious recommendations he came across from your very own web page. It is now and again perplexing to just find yourself giving out thoughts that men and women could have been selling. We really already know we've got the blog owner to appreciate for that. These explanations you made, the straightforward blog menu, the friendships you assist to foster - it is many powerful, and it is facilitating our son in addition to us do think this concept is enjoyable, and that is incredibly indispensable. Thanks for everything!

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.