How to Multitask with FreeRTOS (ESP32 + Arduino series)

  Рет қаралды 79,176

Simply Explained

Simply Explained

Күн бұрын

Run multiple tasks on the ESP32 with FreeRTOS. For instance: blinking two LED's at different intervals or increment two counters at the same time.
A FreeRTOS task is nothing more than a standard C (or C++) function. Nothing fancy, very easy!
Most ESP32's have a dual-core processor, so FreeRTOS will balance your tasks across cores. This technique also works for single-core versions of the ESP32. In that case, FreeRTOS will rapidly switch between tasks, giving the impression that it's multitasking.
⚡️Other videos in this series:
• ESP32 + Arduino
(Everything you need to know about programming the ESP32 by using the Arduino Framework)
🌍 Social
Twitter: / savjee
Facebook: / savjee
Blog: savjee.be
❤️ Become a Simply Explained member: / @simplyexplained
💌 Newsletter: newsletter.savjee.be
(no more than once a month)

Пікірлер: 58
@portillajoe
@portillajoe 3 жыл бұрын
FreeRTOS was a topic that I thought was quite complex but with your explanation I finally understood how to handle it. Thank you.
@fatheramo1
@fatheramo1 2 жыл бұрын
I love how I just tried looking for generic Arduino Multitasking and I was so lucky to find this video using an esp32 with platformIO which is a prefect reference for my project.
@adrianw2972
@adrianw2972 Жыл бұрын
Nice Entry into RTOS 👍 May I note that one should not add computation within a print function, especially if using the Arduino IDE. In the above example the count1++ should occur outside (before) the print statement, then the value of count1 can be printed (this goes for count2 also!). To see this issue in action, change the BAUD rate to 115200 and set the second delay (task2) to 200ms. After every few iterations you will see that the print is corrupted. Move the count++ outside of the print function to fix this. It's a very tempting short-cut, but it will bite you! 😄
@shuaibalghazali3405
@shuaibalghazali3405 Жыл бұрын
I love this video, simplifies the concepts of RTOS
@cloudpicrc5076
@cloudpicrc5076 Жыл бұрын
freertos is so easy to understand from you vides.I will using it in my projects,thanks.
@k.k8221
@k.k8221 Жыл бұрын
Thank you man, you are "Simply Explained" .....now I understood, again Tahanks.
@jonathanrodriguez8219
@jonathanrodriguez8219 2 жыл бұрын
Good and simple explanation!!
@billtsou8071
@billtsou8071 2 жыл бұрын
This is an amazing tutorial. I've gotten an error because I wrote an infinite loop inside the task with millis() instead of calling vTaskDelay(), which would trigger the watchdog timer and reset the chip. Thanks for your kindness sharing. It does really help me a lot!
@maximebernard7212
@maximebernard7212 2 жыл бұрын
clean and clear thank you
@kingsoapvii4273
@kingsoapvii4273 Жыл бұрын
Good video bro, you have my respect, +1 like
@SinanAkkoyun
@SinanAkkoyun 3 жыл бұрын
Very clean 😍😍😍
@zerobow9413
@zerobow9413 2 жыл бұрын
Excellent dude
@benzemamumba
@benzemamumba 2 жыл бұрын
Brilliant!
@dukathneu
@dukathneu 10 ай бұрын
Thanks. That helped!
@f7p1764
@f7p1764 2 жыл бұрын
How to calculate or view somewhere how many bytes is needed to set in task and what is the limits on esp32?
@handlewithoutsuitcase
@handlewithoutsuitcase Жыл бұрын
Nice reverb, mate.))
@ShaffleOne
@ShaffleOne Жыл бұрын
Man... Where have you been all this time?? I searched literally everything to learn how to multitask with esp32...
@Vietnamcamping89
@Vietnamcamping89 2 ай бұрын
Cool bro
@Chris-Brown-
@Chris-Brown- Ай бұрын
How did you set it up, what library, add-on etc did you install? Why is it not in Arduino IDE, like the title?
@TrackAnimatorsMEDIA
@TrackAnimatorsMEDIA 3 ай бұрын
I have a question for you. Do you know of a way to install a OS from a keyboard like the Ensoniq EPS Classic or old Akai MPC drum machines on an ESP 32?
@henrychan720
@henrychan720 2 жыл бұрын
How accurate is vTaskDelay? That is, is it affected by other tasks?
@yashaskumargb3827
@yashaskumargb3827 4 ай бұрын
Please provide link to video where data generated in one task can be transferred to another task
@tcl78
@tcl78 2 жыл бұрын
It is not clear if i have to install something to make FreeRTOS available. Also, you mentioned ESP IDF in the previous video, what is it? How can i use it? Is it an alternative to the Arduino's Framework? Wouldn't it be better to learn something native to ESP32 instead than using something that was born for a different platform (the Arduino Library) and that perhaps cannot use the full power of ESP32?
@simplyexplained
@simplyexplained 2 жыл бұрын
Arduino for the ESP32 is built on top of the “native” framework (ESP-IDF). Everything that’s in IDF, is available from Arduino (including FreeRTOS). Is it better to directly use IDF? Nowadays, yes. The Arduino version is stable, but uses an older version of IDF.
@ptmoy1
@ptmoy1 2 жыл бұрын
I have a conceptual question: do you have to install FreeRTOS like you do a regular operating system (e.g., Windows, Ubuntu, etc.) before you can use its functions, or is FreeRTOS just a library in ESP-IDF, and you flash what you use from the library to the microcontroller along with your own code?
@adrianw2972
@adrianw2972 Жыл бұрын
No, you do not. It is not an interpreted language like python or BASIC, the final program is compiled. If you have installed the IDE for the ESP, it will then work
@wnbrook4220
@wnbrook4220 2 жыл бұрын
Hello, How to put ISRs in core0 ? thanks in advance.
@hazlamyfaizal9992
@hazlamyfaizal9992 9 ай бұрын
Can someone tell me if i need to download smtg from a library first before able to use this RTOS. The commands dont work for me
@bascelik91
@bascelik91 3 жыл бұрын
Maybe I am wrong and pls correct me. But freertos is included in Arduino library and it supports esp32? I mean this is already builtin library? I guess same lib can be used for arduino boards? thanks :)
@simplyexplained
@simplyexplained 3 жыл бұрын
No. Arduino for the ESP32 has been build on top of esp-idf. FreeRTOS comes from idf, not Arduino.
@billtsou8071
@billtsou8071 2 жыл бұрын
Yep, like what @Simply Explained said. ESP32 packages should be installed externally. But there is Board Manager in Arduino which reduces a lot of works. Or be more simple, you can directly download the ESP32-packaged version of Arduino on Google.
@mlsh-azerty
@mlsh-azerty 11 ай бұрын
hmm what🤨 ? how you run freertos without any includes ? and hiw to have both arduino.h ard freertos ??? help 🙃 (trying on esp8266)
@vjreviewsandiy
@vjreviewsandiy Жыл бұрын
Hi, for development mode, I don't want the task to run continuously. If I change from for(;;) to (int i = 0; i
@CodeExplorer-tm2ur
@CodeExplorer-tm2ur Жыл бұрын
I get this exact same error when even using the codes as is (with my wifi settings of course). I'm starting to think that this is some kind of issue with the chip as mine is Adafruit ESP32 Feather. If i comment out the wifi.begin() function I do not get this error but of course system doesn't do what is supposed to
@joecox9958
@joecox9958 2 жыл бұрын
Very nice! but not sure which IDE you used.
@adrianw2972
@adrianw2972 Жыл бұрын
This will work in the Arduino IDE, just add the ESP32 with the JSON line as explained all over the web.
@quanyechen4161
@quanyechen4161 6 ай бұрын
In my board, the `usStackDepth` argument for `xTaskCreate` function is equal or more than 2048, otherwise board will kernel panic.
@vinhnguyenquang7205
@vinhnguyenquang7205 2 жыл бұрын
pls anyone show me how to include freertos. tkssssssss
@zunairakhalid7358
@zunairakhalid7358 Жыл бұрын
can we make Free RTOS based Encrypted Walkie Talkie?
@AliHussein-bb3ie
@AliHussein-bb3ie Жыл бұрын
How many tasks can use?
@annoorkhan4219
@annoorkhan4219 Жыл бұрын
What compiler you are used ? It's not Arduino ide?
@simplyexplained
@simplyexplained Жыл бұрын
I'm using Visual Studio Code as the editor. Compiling is handled by the PlatformIO plugin.
@kingsoapvii4273
@kingsoapvii4273 Жыл бұрын
I love You
@djtyros
@djtyros 2 жыл бұрын
What IDE is this, and how can I download it, and link it to my esp32 so I can run/upload code from within this IDE? I find the Arduino IDE lacks AutoComplete. Thanks
@krillnyetheshrimpguy6152
@krillnyetheshrimpguy6152 2 жыл бұрын
it's platformio, it's an extension to Vscode
@felipefelin8362
@felipefelin8362 Жыл бұрын
what theme are u using in VScode?
@simplyexplained
@simplyexplained Жыл бұрын
Quiet light
@rongarza9488
@rongarza9488 11 ай бұрын
Maybe I'm misunderstanding the terminology but this is not parallel processing. It appears to be time slicing instead, bouncing between one task and the other. Try counting from 0 to 99 and then printing on task 1, and counting from 0 to 199 and then printing on task2. If task1 prints twice as often as task2, then you really are parallel processing.
@simplyexplained
@simplyexplained 10 ай бұрын
This depends on the ESP32 you’re using. Most models are dual-core, and if the WiFi is disabled, two tasks will run in parallel. In other cases, FreeRTOS is indeed sharing the CPU time amongst tasks.
@haritkrishan947
@haritkrishan947 2 жыл бұрын
I don't understand how this has anything to do with the FreeRTOS source code that we download from the website. I have been doing this multi-core computation with the ESP32 for quite some time, but never realised this is considered RTOS programming.
@ahmadal-tarabeen9253
@ahmadal-tarabeen9253 2 жыл бұрын
Who think that this method is the best method that I can use to generate Signal pattern to an Inverter Mosfet gates ?!
@marquezchris2210
@marquezchris2210 3 жыл бұрын
6.9$ for DFRobot FireBeetle ESP32 IoT Microcontroller (Supports Wi-Fi & Bluetooth)
@zyghom
@zyghom 2 жыл бұрын
unfortunately these examples are ok but only when there is no any other process that is running in rtos, i.e. OTA. But when OTA kicks, the ESP32 crashes. So probably this tutorial requires a bit more of explanation how the 2 tasks can work with other tasks without crashing. I would be first to watch it ;-)
@adrianw2972
@adrianw2972 Жыл бұрын
IF you are not using Wi-Fi or BT, then switch them off, otherwise set your application to use only one processor, the wireless stacks take precedence!
@zyghom
@zyghom Жыл бұрын
@@adrianw2972 you are right but esp32 without communication is useless ;-)
@adrianw2972
@adrianw2972 Жыл бұрын
@Zygfryd Homonto quite untrue. I use them in standalone projects, usually with displays. If you wish to use WiFi or BT, simply set your code to use core one only, core zero is used for wireless. And do not use blocking code. I.e. do not use delay, use the FTOS delay functionality etc.
@zyghom
@zyghom Жыл бұрын
@@adrianw2972 some ESP32 are single core - actually I mainly use S2 that is much faster but 1 core only. So I had to use it different way
1 класс vs 11 класс  (игрушка)
00:30
БЕРТ
Рет қаралды 1,9 МЛН
ХОТЯ БЫ КИНОДА 2 - официальный фильм
1:35:34
ХОТЯ БЫ В КИНО
Рет қаралды 2,9 МЛН
Заметили?
00:11
Double Bubble
Рет қаралды 3,4 МЛН
Como ela fez isso? 😲
00:12
Los Wagners
Рет қаралды 34 МЛН
how Google writes gorgeous C++
7:40
Low Level Learning
Рет қаралды 774 М.
How to use millis() function to multitask in arduino code.
10:34
Mario's Ideas
Рет қаралды 57 М.
BEST WAY to make Desktop Applications in C++
26:00
The Cherno
Рет қаралды 877 М.
How to Run Linux on an ESP32
18:53
element14 presents
Рет қаралды 146 М.
📱 SAMSUNG, ЧТО С ЛИЦОМ? 🤡
0:46
Яблочный Маньяк
Рет қаралды 1,9 МЛН
Урна с айфонами!
0:30
По ту сторону Гугла
Рет қаралды 945 М.
iPhone 15 Pro vs Samsung s24🤣 #shorts
0:10
Tech Tonics
Рет қаралды 11 МЛН
Mi primera placa con dios
0:12
Eyal mewing
Рет қаралды 598 М.