Multitasking And Real-Time Arduino System

Multitasking And Real-Time Arduino System © MIT

This simple project shows how Arduino can be used with a RTOS. A special version of Arduino called ARTe was used for software development.

  • 11,846 views
  • 18 comments
  • 19 respects

Components and supplies

Apps and online services

About this project

Introduction

This simple project shows how Arduino can be used with a real time operating system (Erika). The project is designed to show how Arduino can be integrated with a Real-Time operating system and how to use hardware and software components. A special version of Arduino called ARTe was used for software development. For more information on how to use ARTe, visit the official developer site (http://arte.retis.santannapisa.it/index.html or http://retis.sssup.it/?q=arte).

For more details how to install ARTe it is better if you visit the github page (https://github.com/melvin-mancini/Multitasking-RealTime-Arduino-System).

ARTe (Arduino Real-Time extension)

ARTe (Arduino Real-Time extension) is an extension to the Arduino framework that supports multitasking and real-time preemptive scheduling. Thanks to ARTe, the user can easily specify and run multiple concurrent loops at different rates, in addition to the single execution cycle provided by the standard Arduino framework. Today ARTe supports the most popular platforms: Arduino UNO and Arduino DUE. In addition to the single loop present in the standard Arduino approach, the user can easily specify a number of concurrent loops to be executed at specific rates. Concurrency and real-time scheduling is provided by the ERIKA Enterprise (http://erika.tuxfamily.org/drupal/) open-source real-time kernel. Loops can use the standard Arduino libraries, which have been enhanced to guarantee mutual exclusion in the access of shared data structures. The impact of ARTe in terms of footprint and runtime overhead has beed evaluated by extensive tests and resulted to be negligible. You can use ARTe and develop Arduino code only with Windows platforms. The project under consideration was developed on a machine with Windows 8.1.

About this project

Thanks to ARTe it has been possible to implement a system in which there are 3 periodic processes. Each of them has a given priority and is managed according to a real time scheduler algorithm made available by the ERIKA operating system. Processes, when they are running, handle different activities. A process for managing every 3 milliseconds the acquisition of the distance through the sensor HC-SR04. When an obstacle is placed at a distance of less than 10 cm, an "alarm" LED lights up. Another process for flashing a LED every 7 milliseconds. A final process to read the temperature returned by the LM35 sensor expressed in degrees Celsius. If the temperature exceeds 23 degrees Celsius then a warning LED is switched on. All processes are managed in real time mode. The system is efficient and effective with responsive response times.

How to use

ARTe installation

In order to develop applications with ARTe you have to download the development tool. The version of ARTe used to develop this project can be found on the following web page: http://retis.sssup.it/?q=arte . ARTe is evolved and the new version can be downloaded from the site: http://arte.retis.santannapisa.it/index.html . The developer site provides all the information on how to use the development tool, providing documentation and examples. Once installed the tool is quite similar to Arduino's editor but with the ability to use the Arte Extension. You can then enable or disable the ARTe extension by clicking on the Tools item in the menu bar. The item ARTℇ will appear and click on it you can select enable or disable.

Run the project

In order to realize the system described above, you must have the following hardware components:

  • Arduino Uno
  • HC-SR04 (distance sensor)
  • LM35 (temperature sensor)
  • LED
  • Electrical resistor
  • Simple connectors for electronic devices.

In the Circuit Diagram folder there are two files that show how to connect the various components to the Arduino. The file .fzz format was created using the Fritzing software, the recommended tool for building electronic circuits. In addition, there is an image that shows more intuitive how the various components must be connected.

After installing ARTe and implementing the circuit, you can connect the Arduino to the PC and wait for the software to recognize the device. Then, through the Arduino editor with ARTe, you should open the src.ino file located in the src folder of the project. I recommend opening the src.ino file using the ARTe editor directly, by clicking on the menu bar File -> Open -> Select src.ino file. You must enable ARTe as explained in the previous section ARTe installation and then you can compile the project and upload it to the Arduino board.

Problems

Problem with DigitalToggle Arduino Library

ARTe is an extension of an Arduino version so you may encounter compilation errors when using some Arduino libraries. Compilation errors may occur when using the Arduino DigitalToggle library. You should edit a file in order to use the library properly. Follow the steps below:

  • Before importing the library through the Arduino IDE, you must unzip the DigitalToggle.zip file and open the DigitalToggle.h file
  • Replace the line of code #include <pins_arduino.h> with #include "Arduino.h"
  • Once the DigitalToggle.h file has been modified, compress the folder into a .ZIP file and run the procedure to import the new library (See the section "Download, install and import" from the site https://playground.arduino.cc/Code/DigitalToggle).

Code

Multitasking and Real-Time Arduino ProcessingArduino
This simple project shows how Arduino can be used with a real time operating system (Erika). A special version of Arduino called ARTe was used for software development ( http://retis.sssup.it/?q=arte ).
ARTe (Arduino Real-Time extension) is an extension to the Arduino framework that supports multitasking and real-time preemptive scheduling. Thanks to ARTe, the user can easily specify and run multiple concurrent loops at differents rates, in addition to the single execution cycle provided by the standard Arduino framework. Today ARTE supports the most popular platforms: Arduino UNO and Arduino DUE. In addition to the single loop present in the standard Arduino approach, the user can easily specify a number of concurrent loops to be executed at specific rates. Concurrency and real-time scheduling is provided by the ERIKA Enterprise (http://erika.tuxfamily.org/drupal/) open-source real-time kernel. Loops can use the standard Arduino libraries, which have been enhanced to guarantee mutual exclusion in the access of shared data structures. The impact of ARTe in terms of footprint and runtime overhead has beed evaluated by extensive tests and resulted to be negligible.
In this project was used to run 3 periodic processes that handle different activities. A process for managing every 3 seconds the acquisition of the distance through the sensor HC-SR04. Another process for flashing a LED every 7 seconds. A final process to read the temperature returned by the LM35 sensor expressed in degrees Celsius is executed every 11 seconds. All processes are managed in real time mode.
//Pin definition
static int trigger = 9; // Pin HC-SR04
static int echo = 8; // Pin HC-SR04
static int led_HC = 10; // Pin HC-SR04
static int led_pulsed = 13; // Timed pulsed led
static int led_temperature = 12; // Led to temperature overflow
static int LM35_analogPin = 0; // analog pin for temperature sensor


// Variables for calculating the distance with sensor HC-SR04
long duration; // Flight time of signal
long distance;  // Calculated distance 
float temp_C; // temperature variable (Celsius degrees)

void setup() {
  //Serial communication
  Serial.begin(9600);

  //Pin setup
  pinMode(trigger, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(led_HC, OUTPUT);
  pinMode(led_pulsed, OUTPUT);
  pinMode(led_temperature, OUTPUT);

  digitalWrite(echo, LOW);
  digitalWrite(trigger, LOW);
  digitalWrite(led_HC, LOW);
  digitalWrite(led_pulsed, LOW);
  digitalWrite(led_temperature, LOW);

  //Analog input
  analogReference(INTERNAL); // prendo la misura analogica di riferimento di Arduino a 1.1V

  //Variable initialization of the distance
  duration = 0;
  distance = 0;
}

void loop() {
}

void loop1(3000) {
  //Send a HIGH pulse to the trigger pin
  digitalWrite(trigger, HIGH);
  //I leave it to the HIGH value for 10 microseconds
  delayMicroseconds(10);
  //I carry it back to the LOW state
  digitalWrite(trigger, LOW);

  //I get the number of microseconds for which the echo PIN is left in HIGH state
  duration = pulseIn(echo, HIGH);

  /*Sound velocity is 340 meters per second, or 29 microseconds per cent.
    Our impulse travels back and forth, so to calculate the distance
   Between the sensor and our obstacle we need to do:*/
  distance = duration / 29 / 2;

  // Turn on the led if there is an obstacle at a distance of less than 10 cm
  if (distance < 10) {
    digitalWrite(led_HC, HIGH);
  }
  else {
    digitalWrite(led_HC, LOW);
  }
  // Print on the serial buffer
  Serial.print("duration : ");
  Serial.print(duration);
  Serial.print(" - distance : ");
  Serial.println(distance);
}

void loop2(7000) {
  int i;
  Serial.println("Pulsed LED");
  // Code for the flashing of the led
  for (i = 0; i < 5; i++)
  {
    digitalWrite(led_pulsed, HIGH);
    delay(500);
    digitalWrite(led_pulsed, LOW);
    delay(500);
  }
}

void loop3(11000) {
  float sum_temp = 0;
  float average_temp = 0;
  /* Acquire 3 values from the sensor every 500 milliseconds.
     Through an appropriate conversion I get the measure in degrees Celsius.
     Calculate the average of subsequent measurements.*/
  for (int i = 0; i < 3; i++){  
    delay(500);
    temp_C = (1.1 * analogRead(LM35_analogPin) * 100.0) / 1024;
    sum_temp += temp_C;
  }
  average_temp = sum_temp / 3;
  // If the temperature is greater than 23 degrees, turn on the led
  if (average_temp > 23) {
    digitalWrite(led_temperature, HIGH);
  }
  else {
    digitalWrite(led_temperature, LOW);
  }
  Serial.print("Temperature : ");
  Serial.println(average_temp);
}
Multitasking-RealTime-Arduino-System
This simple project shows how Arduino can be used with a real time operating system (Erika). A special version of Arduino called ARTe was used for software development ( http://retis.sssup.it/?q=arte ). ARTe (Arduino Real-Time extension) is an extension to the Arduino framework that supports multitasking and real-time preemptive scheduling. Thanks to ARTe, the user can easily specify and run multiple concurrent loops at differents rates, in addition to the single execution cycle provided by the standard Arduino framework. Today ARTE supports the most popular platforms: Arduino UNO and Arduino DUE. In addition to the single loop present in the standard Arduino approach, the user can easily specify a number of concurrent loops to be executed at specific rates. Concurrency and real-time scheduling is provided by the ERIKA Enterprise (http://erika.tuxfamily.org/drupal/) open-source real-time kernel. Loops can use the standard Arduino libraries, which have been enhanced to guarantee mutual exclusion in the access of shared data structures. The impact of ARTe in terms of footprint and runtime overhead has beed evaluated by extensive tests and resulted to be negligible. In this project was used to run 3 periodic processes that handle different activities. A process for managing every 3 seconds the acquisition of the distance through the sensor HC-SR04. Another process for flashing a LED every 7 seconds. A final process to read the temperature returned by the LM35 sensor expressed in degrees Celsius is executed every 11 seconds. All processes are managed in real time mode.

Schematics

Circuit Diagram
Electronic circuit of the components used. This schema has been designed to work properly with the implemented Arduino code. If the layout of the components is changed, you must change the pin statement in the Arduino code.
circuitdiagram_WWyvXhbDQZ.fzz

Comments

Similar projects you might like

Home/Hotel Monitoring System with Automated controls

Project tutorial by Anas Siddiqui

  • 4,181 views
  • 10 comments
  • 15 respects

Ultrasonic Security System

Project tutorial by Ivan

  • 17,286 views
  • 18 comments
  • 50 respects

Traffic Light Information System

Project tutorial by Joppe Smeets and Pieter Luyten

  • 19,032 views
  • 26 comments
  • 41 respects

Control your light system with your voice

Project tutorial by Maha Raafat

  • 35,012 views
  • 22 comments
  • 154 respects

Control your Light System Using Smart Phone

Project tutorial by Ahmed Yassin

  • 35,262 views
  • 4 comments
  • 55 respects

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 24,826 views
  • 17 comments
  • 75 respects
Add projectSign up / Login