FreeRTOS-Why To Use It?

IoT Projects? What is it? — IoT — Episode #02

J3
Jungletronics
5 min readJan 4, 2020

--

For IoT projects!

IoT or the internet of things is an upcoming technology that makes use of the internet to control/monitor electronic/mechanical devices, automobiles, and other physical devices connected to the internet.

Fig 1. Example of an IoT Project 😮

Is Arduino IoT Compatible?

Yes, It is!

In IoT projects, all the physical objects (things) are connected together using internet infrastructure. Arduino board is one of the most important devices that enables us to prototype projects.

Good, so this is the Hardware that I have to use in my IoT project, right?

Well…no!

Just consider this board for now…ESP-32!

Fig 2. This one: ESP-32!

And here is why?

Table 1. DIYers Board’s Most Loved Comparison

Look just these two points…and I hope you’d get the idea (:

First, Core: ESP-32 is dual-core.

Secondly, ADC: ESP-32 has 18 GPIO’S Analog-to-digital-Converter. Remember Peter Kinget? The World is Analogue!

Just these points will be sufficient to draw our attention to this awesome, low-cost, low-power system on a chip (SoC) microcontroller. But there is more…MUCH MORE…

Wi-Fi and Bluetooth (classic & BLE 😮)!

Meet the king of all IoT’s boards: ESP-32!

Fig 3. Look how many ESP-32 embedded board options are available out there in the IoT market!

So, I will program it like this, right?

void main()
{
InitSys();
While(TRUE)
{
currentSensor();
termopar();
humidity();
motionSensor();
sendoToUART();
updateLCD();
}
}

Well, again: No!

Then by using the state machine, maybe?

Ups…no…but wait…What state machines mean?

State machines are useful tools that in the right application can simplify designing microcontroller firmware. They allow you to create an event-driven system that can change its response to inputs based on its internal state. … Also, our system must turn off the LED after a period of inactivity (yeah! Green Product).

Good, but there is a better solution!

Let me try to convey the main idea…

while(true)
{
task_1(); // 60us
task_2(); // 2us
} // 62us

These two tasks code takes 62us, right?

How to get a better code?

The answer: Finite State Machines — The better way to code!

Using Finite State Machines (FSM) is a common industrial practice in coding, but their use extends beyond everyday software. They can easily be used in projects, to help prevent bugs, to stop infinite loops hogging the processor, and to ease debugging.

Let’s use it just now, by using the state machine switch-case structure:

{ 
switch(task_1_state)
{
case a:
task_1_state_a();
break; //20 us
case b:
task_1_state_b();
break; //20 us
case c:
task_1_state_c();
break; //20 us
}
task_2();//2us
} //22us

Much better: 22 us!

But maybe this is not enough…

Let’s think about UART communication. First, consider this table:

Table 2. Theoretical transfer rate/controller comparations table. Can you see Serial Port? (Mb/s or Mbps stands for megabits per second, and by extension Gb/s or Gbps, gigabits per second;)

Yes, UART is a very, very … but a very slow communication protocol. What may result?

The dreaded infinite loop! a terrorist for all of us hobbyists and engineers alike”/

How to get rid of this?

Real-time operating system!

What is meant by the real-time operating system?

A real-time operating system (RTOS) is an operating system (OS) intended to serve real-time applications that process data as it comes in, typically without buffer delays. Processing time requirements (including any OS delay) are measured in tenths of seconds or shorter increments of time.

And there is more…but this is an issue for the next IoT episode (FreeRTOS more specifically… to be honest :)

See you there!

Bye:)

IoT Episodes Posts:

1° Episode — IoT — Meet IoT Boards: ESP8266 & ESP32 — Which are the best? ESPs or RPis or Arduinos Boards?

2° Episode — IoT — FreeRTOS Why To Use It? — IoT Projects? What is it? (this one:)

3º Episode — IoT — FreeRTOS — We are all Preemptive Scheduler! — Some Important Concept for Real-Time Operating System (RTOS)

4° Episode — IoT — FreeRTOS — More About it! — The Essence of FreeRTOS

5° Episode — IoT — FreeRTOS A Real Real-Time TV Transmissions Fundamental Understanding of FreeRTOS Apps

More Related Posts

Adafruit-IO Meets ESP8266, Arduino & MIT App Inventor 2 — Hello World for Adafruit-io & MQTT Protocol — 05 #kidSerie

MIT App Inventor 2 Meets Esp8266!!! — Playing With ESP8266–03 #kidSerie

Arduino Headless Setup & ESP8266 (WIFI cheap chip!) — Rather Stunning MCU!!! — #arduSerie 16

Flashing The Official ESPRESSIF Firmware in ESP8266 !!! — Easy ESP8266 Flashing!!! — #arduSerie 17

Get Started Using AT Commands w/ ESP8266 — Multiple Connection as TCP Server — #arduSerie 19

Your First NodeMCU/Lua Script Flash on ESP8266!!! — Let’s get our feet wet with NodeMCU/Lua and sees what happens !!- #arduSerie 20

References & credits

Microgênios — Treinamento em Sistemas Embarcados — Microchip Regional Partner Certified Training Courses a Simplício-owned enterprise

https://www.freertos.org/RTOS.html

ESP32 V2.0 TTGO & para Arduino OLED

Esp32

Finite State Machines & Microcontrollers by AllAboutCircuit.com

Notes:

FreeRTOS
FreeRTOS was developed (and is constantly improved) in partnership with the largest chip manufacturers, a development that lasts more than 15 years, following strict software quality standards (it follows almost all MISRA standards).
The popularity is so great that, in 2017, Amazon acquired FreeRTOS and launched interesting customizations for using its IoT-targeted services (read more here and here). So yes, FreeRTOS is 'owned' by Amazon, and that gives you an idea of the proportion of this project.MISRA
MISRA-C is a software development standard in C language developed by the company that gives its name, the Motor Industry Software Reliability Association.
This standard focuses on automotive embedded systems, but its practices can also be extended to other areas, such as medical and aerospace equipment.FreeRTOS uses MISRA standards.

edited @ Dez/2020 — Adding note:)

--

--

J3
Jungletronics

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Ruby, Rails, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!