#381

  Переглядів 101,060

Andreas Spiess

5 місяців тому

Using a real operating system to simplify programming with the Arduino IDE. Is this possible and how? Let’s have a closer look!
Operating systems were invented to simplify our lives. But, because they need a lot of resources, they only run on reasonable computers like the Raspberry Pi or a PC. Right? Wrong. Nowadays, we also get operating systems running on our small MCUs. Particularly interesting in this respect is the ESP32 because it has enough power and memory to accommodate such an additional burden. And the best: It already runs a version of FreeRTOS with all our Arduino sketches, and it is easier than you think. Is this useful?
I am a proud Patreon of @GreatScott!, @ElectroBOOM , @Electronoobs , @EEVblog , and others. No Docker, No Microsoft Teams, Zoom

Links:
FreeRTOS deep dive: ukposts.info/have/v-deo/fmNjZWZvbq-K2mg.html
Parallel tasks without RTOS: ukposts.info/have/v-deo/rmh8jJdsrIiS15s.html
Code (for reference only): github.com/SensorsIot/Morse-T...
ESP32 Dev. Board used for Prototyping: s.click.aliexpress.com/e/_ANHrBc
ESP32 Prog: s.click.aliexpress.com/e/_AougSs or amzn.to/3tjrsL4
Logic Analyzer 16ch (clone) : s.click.aliexpress.com/e/_9R3ZMZ
Logic Analyzer 8ch (clone) : s.click.aliexpress.com/e/_APm5bP

The links above usually are affiliate links that support the channel (no additional cost for you).
Supporting Material and Blog Page: www.sensorsiot.org
Github: www.github.com/sensorsiot
My Patreon Page: www.patreon.com/AndreasSpiess
Discord: discord.gg/JfgDSa8
If you want to support the channel, please use the links below to start your shopping. No additional charges for you, but I get a commission of your purchases to buy new stuff for the channel
My Amazon.com shop: www.amazon.com/shop/andreassp...
For Banggood bit.ly/2jAQEf4
For AliExpress: bit.ly/2B0yTLL
For Amazon.de: amzn.to/2r0ZCYI
For Amazon UK: amzn.to/2mxBaJf
For ebay.com: ebay.to/2DuYXBp

profile.php?...
spiessa
www.instructables.com/member/...
Please do not try to email me. This communication channel is reserved for my primary job
As an Amazon Associate, I earn from qualifying purchases

КОМЕНТАРІ
Andreas Spiess
Andreas Spiess 5 місяців тому
Correction: ISR is Interrupt Service Routine, not internet service routine
সূর্য্য SUN uk
সূর্য্য SUN uk 4 місяці тому
ukposts.info/have/v-deo/hJGKjKibeImDmYE.html
Mark Maker
Mark Maker 4 місяці тому
Another great tutorial and reason to love the esp32 even more, thanks!
Andreas Spiess
Andreas Spiess 5 місяців тому
I already posted a pinned correction comment ;-)
varun koganti
varun koganti 5 місяців тому
This must be an April fools joke.
RobotsReloaded
RobotsReloaded 15 днів тому
Love your videos! I've heard the word RTOS many times and thought it's something very complicated. Your explanation gives a very good intro to it. Now there is so many use cases coming in my mind 😁
Andreas Spiess
Andreas Spiess 14 днів тому
Glad it was helpful!
josh mcgee
josh mcgee 18 днів тому
lately every time I have an interest in a topic and search youtube you've made a video on it already. Thanks once again :)
Andreas Spiess
Andreas Spiess 16 днів тому
Happy to hear that!
Kumar M
Kumar M Місяць тому
Nice one also check the playlists:ukposts.info/slow/PLyp1I7W35-q0EQY6oMfaKN9rhudYmoSBh
Gregory McCoy
Gregory McCoy Місяць тому
Yikes!!! I learned a lot from this video. Mind blown.. pondering possibilities.
Andreas Spiess
Andreas Spiess Місяць тому
Glad you liked it!
Eric Williams
Eric Williams Місяць тому
Have you ever explored using Firmata as a technique for computer or raspberry pi distributed processing? I'm curious what your opinion is if you have.
Eric Williams
Eric Williams Місяць тому
@Andreas Spiess I’m working on a project with it and find it pretty interesting. I’ll share more when I get it running more smoothly!
Andreas Spiess
Andreas Spiess Місяць тому
No, I never used it so far. I heard about it, but not enough to have an opinion.
Adrian Zahra
Adrian Zahra Місяць тому
Awesome stuff
Andreas Spiess
Andreas Spiess Місяць тому
Thank you!
Carlos Diaz
Carlos Diaz Місяць тому
Hello, your videos are very good, I would like to make a query regarding the use of the two cores of an esp32. How can I know the resource consumption or better said occupancy percentage of each of the two cores of an esp32? I would be interested in having that information in esp32, so I know to which core to assign new tasks. so I can load balance my tasks. RTOS has a function that gives that information? Thanks!!!
Andreas Spiess
Andreas Spiess Місяць тому
I do not know. So far I never needed this information...
Nic Whites
Nic Whites 2 місяці тому
Great video, but it should be noted there is no physical possible way for 3 tasks to run in parallel on an esp32. It is only possible to have three tasks to run concurrently on a dual core system. Although it may not seem like there is of difference between parallel and concurrency, but deep down there is a huge difference.
Andreas Spiess
Andreas Spiess 2 місяці тому
You are right, of course.
Robert Wooten
Robert Wooten 2 місяці тому
Invaluable tips
Andreas Spiess
Andreas Spiess 2 місяці тому
Glad you think so!
Shaikh Ahmed
Shaikh Ahmed 2 місяці тому
Thanks a lot for the video. I have noticed you used visual micro, any plan to make any tutorial on how to setup the visual micro with ESP32 freeRTOS sdk?
Andreas Spiess
Andreas Spiess 2 місяці тому
No need for SDK. RTOS is built into the Arduino framework. I once made a video about Visual Micro
phrankus2009
phrankus2009 3 місяці тому
Seems like home automation, environmental monitoring, control and display, and executive management are all candidates for RTOS .. After watching this video, I know what can be done but I am FAR from being able to "DO IT". ... Good intro, though, most certainly.
Andreas Spiess
Andreas Spiess 3 місяці тому
I agree, it is very versatile. But, as you write, it needs some practising...
Wolfram Webers
Wolfram Webers 3 місяці тому
I like your intro-videos as always. However, as support of RTOS for the new RP2040 seem to have stalled, any chance you make a video about RP2040 and RT-Thread? Maybe even with your simple morse example?
Wolfram Webers
Wolfram Webers 3 місяці тому
@Andreas Spiess Ok. Thanks anyway 👍
Andreas Spiess
Andreas Spiess 3 місяці тому
So far the RP2040 does not have a lot of traction in the "advanced" Maker community. So I have no plans to cover it in future videos.
Mark Ruvald
Mark Ruvald 3 місяці тому
Andreas, you should take a look at Zephyr RTOS
Andreas Spiess
Andreas Spiess 3 місяці тому
I looked at it (briefly). This seems to be a completely different world. I decided to use the _Arduino IDE on this channel because of its strong community support. RTOS fits much easier, I think. Especially on the ESP32 where it is already part of the infrastructure. But maybe I do not know everything.
Normal Universe
Normal Universe 3 місяці тому
Thanks for referencing my vid Andreas! I’m self taught so I didn’t know there are more elegant ways to do multitasking. I haven’t watched all of this video yet but I will definitely come back to it. I’m getting back into coding to make a synthesizer so this is just what I need.
Andreas Spiess
Andreas Spiess 3 місяці тому
You are welcome. You will see, RTOS is a different world because most things are "under the hood" and your code is easy to read.
OthmanEmpire
OthmanEmpire 3 місяці тому
Thanks for the video =)
Andreas Spiess
Andreas Spiess 3 місяці тому
You are welcome!
Pembo Pemberton
Pembo Pemberton 4 місяці тому
A great intro to RTOS. I find it good practice to use it all of the time with the ESP32 and just have the OTA in the "loop" function. It's a good way to learn how to program many micro controllers in the big industry and not just hobbyist style coding. As I've also been use RTOS on many other microcontrollers like ARM and PIC for many years in industry. This makes porting code from other microcontrollers to the ESP range very easy. ...Keep up the great work. - Enjoying watching from the UK. 😉👌
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you for your feedback. For sure it makes a lot simpler...
Steinar Vigdel Kolnes
Steinar Vigdel Kolnes 4 місяці тому
Great video and explanation. It flashbacked me to the old Transputer in the 90s (T4xx and T8xx, w/floating point). Wifi which has quite good bandwidt, could be used to disribute tasks among different ESP32s Will Rtos also be a good choice for the nRF5xx series.
Andreas Spiess
Andreas Spiess 4 місяці тому
I think, FreeRTOS is ported to many architectures. It is particularly easy for the ESP32 because it is part of its „infrastructure“
Hamza Hajeir
Hamza Hajeir 4 місяці тому
Hi I think it's a good suggestion to make a video to this great framework: ukposts.info/have/v-deo/i4J5rptkg4inr2g.html
Andreas Spiess
Andreas Spiess 4 місяці тому
Interesting framework. So far I do not know where it fits (for the moment it looks like a small copy of Tasmota). But I wait for the next video...
Gunther Jordan
Gunther Jordan 4 місяці тому
Ein Video an meinem Geburtstag über eines meiner aktuellen Lieblings-Bauelemente. Das ist ein extrem interessantes Thema, -werde mich da demnächst mehr mit beschäftigen. Danke für's zeigen!
Andreas Spiess
Andreas Spiess 4 місяці тому
Bitte, gern geschehen, Und herzliche Glückwünsche!
Seamus de Mora
Seamus de Mora 4 місяці тому
I loved the Einstein quote re resource allocation to problem vs. solution. And of course your observation about how the typical engineer allocates time is 100% "on target" in my experience. But you missed an opportunity I think - to remind engineers that the quality of their solution often improves when they allocate resources more like Einstein. :) Great video, BTW.
Andreas Spiess
Andreas Spiess 4 місяці тому
You are right. But I do not like to tell people what to do. I hope some learned from Einstein ;-)
HanabiMock
HanabiMock 4 місяці тому
Is it possible to do real time sampling at higher frequency than the scheduler (1 ms per task) in one task? How is that handled?
HanabiMock
HanabiMock 4 місяці тому
@Andreas Spiess thanks. I will make some experiments with the interrupts
Andreas Spiess
Andreas Spiess 4 місяці тому
I probably would use interrupts for this purpose. The ADC then would fire an interrupt request whenever it is ready. But I once made some tests and the ESP32 was quite slow in this respect. So you probably need more tricks...
Paulo Galvao
Paulo Galvao 4 місяці тому
very good explanation but this is not for me, that's why i m no ta programmer :(
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you. We also need good Hardware guys!
Casey Koons
Casey Koons 4 місяці тому
Very nicely made video of the project. Good scope. I like the design of the deck too.
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you!
Jos Ka
Jos Ka 4 місяці тому
Very, very interesting! Thansks!!
Andreas Spiess
Andreas Spiess 4 місяці тому
Glad you liked it!
Christian Carassai
Christian Carassai 4 місяці тому
Right? Wrong!!! hahahaha. Andreas, your videos are excellent, and a great source of information. Congratulations, one of the best channels on microcontrollers and iot!!!
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you for your nice words!
Robert Roig Santamaria
Robert Roig Santamaria 4 місяці тому
You say that the tasks SEEM to run in parallel, and you're running 5 tasks, any signal you generate is chopped and is produced once every 5ms ? (pwm style)
Andreas Spiess
Andreas Spiess 4 місяці тому
If you set the status of a pin it stays until you change it. So there is no chopping of the morse signal, for example even if the sketch setting the pin is interrupted.
Giblet535
Giblet535 4 місяці тому
Great presentation, as usual Mr. S! Interesting trivia: Back in the 80's, there were multiuser OSes like MPM (a multi-user version of CPM) that didn't time slice. It's true! Each user had a dedicated CPU/RAM card, and the OS managed authentication, physical board allocation, and the shared permanent storage (SMD disks, mag tapes, and even 12-inch laserdiscs). Their 15MB disks were tiny miracles of miniaturization: usually 16 inches wide, 20 inches long, and 10 inches high.
D. Hugh Redelmeier
D. Hugh Redelmeier Місяць тому
@Andreas Spiess commercial mainframes multiprocessors were available by the early 1960s. For example, the Burroughs D825. As far as I remember, the first multiprocessor VAXes were home-made at Purdue University and ran UNIX.
D. Hugh Redelmeier
D. Hugh Redelmeier Місяць тому
MP/m really did use time slicing on a single CPU. At least in most configurations. MP/m 8-16 seems to have supported multiple processors (typically one 8-bit and one 16-bit). I'd guess it also supported premption and time slicing. Multi-user without premption and time slicing is not really workable in general, but if you really dedicated one core per user it could work. What was the name of the computer system that you used.
Andreas Spiess
Andreas Spiess 4 місяці тому
You are right. We even had RTOS systems for one CPU back then. I never heard of such a concept where you had different CPUs managed by one operating system. For me this came later with the VAX/VMS multi-processor systems.
Sarah Gray
Sarah Gray 4 місяці тому
Excellent video, as always, Andreas. I found myself working through and learning how RTOS worked when working through and debugging the code for the ESP32 Internet radio project that you discussed previously. However this cleared up a few things I was not able to get my head around from the Free RTOS documentation. Thanks again.
Andreas Spiess
Andreas Spiess 4 місяці тому
You are welcome! I forgot that the internet radio also used RTOS. I am getting old...
Olli
Olli 4 місяці тому
Hello Andreas, This was very helpful. - Thx ! I ve two more questions: - Is this (RTOS) useable in the same way on ESP8266 ? - Is there a way to use ESP32 on batteries as efficiency as ESP8266 with out making a science of software or hardware optimizations ?
Olli
Olli 4 місяці тому
@Andreas Spiess Danke für deine Antwort, ich hatte nur den ESP8266-Port gesehen und dachte ich könnte es wie in Deinem Video gezeigt übertragen.
Andreas Spiess
Andreas Spiess 4 місяці тому
The ESP8266 has no built-in RTOS. It was ported but you have to do everything yourself. And RTOs systems are probably not made for battery operated systems. It is more for complex programs.
Eduardo Cardoso
Eduardo Cardoso 4 місяці тому
I want more videos like this! Thanks for this video
Andreas Spiess
Andreas Spiess 4 місяці тому
You are welcome! We will see...
QC Support
QC Support 4 місяці тому
I didn't realize it is such a short jump from ESP32+Arduino IDE to using an RTOS! It was right there all along. Anything that lets us keep our design complexity lower is potentially a huge win.
Andreas Spiess
Andreas Spiess 4 місяці тому
Indeed it is a short jump for a start. Maybe it needs some practice...
Dillon Sterling
Dillon Sterling 4 місяці тому
I can't even begin to tell you how much I value the work you (and other educational youtubers who are truly educated and articulate) do for the comunity and myself..... Tryin to jump in with arduino and programming to make my dream projects come true would have overwhelmed me and I would have definitely given up without the resources you provide. Sometimes when your teaching yourself things the hardest part is not knowing what you don't know, and not knowing how to ask the right questions, so when you go out of your way to provide context and redundant examples along the way without delight too deep into those other topics it really elevates the content from infotainment to genuinely valuable educational material.
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you for the nice words! I became a UKpostsr because I learned a lot when I started with the Arduino myself...
Lorenzo Ruscitti
Lorenzo Ruscitti 4 місяці тому
Nice video See my playlist about FreeRTOS
Doug Cooper
Doug Cooper 4 місяці тому
That was a great introduction. It would be great to see other FreeRTOS videos. Thanks
Andreas Spiess
Andreas Spiess 4 місяці тому
We will see. Maybe as a part of a project.
Rennie Allen
Rennie Allen 4 місяці тому
This is the worst possible introduction to RTOSs. You are using it exactly as a round robin scheduler, which is the very definition of a non RTOS. If priorities are not utilized, it isn't being used as an RTOS.
Rennie Allen
Rennie Allen 4 місяці тому
@Andreas Spiess if you aren't demonstrating priorities and how priority inversion is avoided then you are just using it the rtos as a conventional timeshare and not using any real-time features. Interrupts also have no relationship to an rtos. In an rtos all nonschedulable events have to be converted to scheduleable events (that's what rtoses do). If you are using a timer Interrupt you are bypassing the schesuler and if you are using an aperiodic Interrupt it shouldn't be used directly but should be converted to a scheduleable event with an assigned priority, otherwise you have priority inversion and if you have priority inversion, you don't have a real-time system.
Andreas Spiess
Andreas Spiess 4 місяці тому
I can follow your argument and it is valid. Still, you can use most of the concepts I showed here and attach it to an interrupt (I even showed, how it is done). For my project, a response time of 1ms was sufficient and therefore I did not use interrupts. One thing should be considered: When I used to work with RTOS in the 80 it was much more complicated because of a lack of resources. There, priorities etc. were much more important. The ESP32 is so fast that all tasks from my program only used a fraction of a time slot. So, priorities were not too important and would have made things more complex.
Kevin Grimshire
Kevin Grimshire 4 місяці тому
Wonderful video as always and enjoy your Swiss accent - my XYL thinks you sound like Arnie! Have you looked at a hardware watchdog for Arduinos and PICOs etc? Would be very useful for remote or difficult to reach installations. 73 Kevin G4MZH
Kevin Grimshire
Kevin Grimshire 4 місяці тому
@Andreas Spiess Thank you. That looks ideal. 73s and 88s from the XYL
Andreas Spiess
Andreas Spiess 4 місяці тому
Maybe this one: www.elektormagazine.com/news/small-circuits-can-do-the-job-an-ne555-watchdog-timer-part-6 ?
Kevin Grimshire
Kevin Grimshire 4 місяці тому
@Andreas Spiess XYL delighted! Was thinking of a hardware watchdog rather than a software one featured in your video. If it does not receive a pulse every minute it re-boots the micro-controller. Being hardware it would work for all flavours of Arduino, PICOs and Raspberry Pis
Andreas Spiess
Andreas Spiess 4 місяці тому
If I remember ringt I once made a video about watchdogs, but mainly on the ESP8266. And thanks you your XYL for the compliment!
Eduardo Cardoso
Eduardo Cardoso 4 місяці тому
Thanks for subtitles in portuguese!
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you for the feedback. Google just recently introduced this feature and I will try to include it in future videos...
Eduardo Cardoso
Eduardo Cardoso 4 місяці тому
@Andreas Spiess Only words of technical use that should not be translated ended up being translated, but it did not hinder anything for the understanding. It would be great if all of your videos had a "script" so that all Brazilians would have more democratic access to your videos. And without a doubt your channel is the best and most complete in the world. It would be great if we here in Brazil have access to such good quality content. Thank you for sharing your knowledge with us.
Andreas Spiess
Andreas Spiess 4 місяці тому
They were auto-translated by UKposts from my script. How was the quality?
Jorge YC
Jorge YC 4 місяці тому
Thanks for starting with RTOS, always wanted to learn it!
Andreas Spiess
Andreas Spiess 4 місяці тому
Go for it. It is worthwhile.
Milton Freeman
Milton Freeman 4 місяці тому
Great - now we know how to do this in C, the next part lies at hand: Redo the project in microPython using asyncio...
Andreas Spiess
Andreas Spiess 4 місяці тому
It is up to you. Usually, people start with Micropython for fast experiments and then go on with C++ for "production", not the other way round.
Alex Landherr
Alex Landherr 4 місяці тому
Curiosity and Perseverance run VxWorks as their RTOS.
Andreas Spiess
Andreas Spiess 4 місяці тому
You are right. There are numerous other RTOS available because they are very useful for a lot of applications.
ObsoletePowerCorrupts
ObsoletePowerCorrupts 4 місяці тому
You could use a unary relationship for an object to call itself by means of recursion (in place of some scenarios of while loops and other loops). It would mean a state boundary (as in UML diagram) of an object can change rather than needing to use a state machine with case statements. Depending on the code written, you need to model it for your scenario though as increased size in code (for some simpler projects) might bloat somewhat and you'd need to be mindul of includes and libraries. That said, if all that is covered, you could squeeze more out of the same object if you override the operator (basically polymorphism). That could for example mean you sometimes don't need an extra linked-list (if using lists). You'll need to be 'retentive' about it though because it can lead to instability and that can be the case especially in languages whereby dynamic memory allocation is utilised with it (dynamically linked list). If you have FPU on a esp32, it can be stunted (division is in software as a crutch to those esp32 packages) so expect poor performance (like if fractally generating something from the linked lists)... However, at least those have some manner of FPU to speak of. Any floating point in a storm. You might be able to afford some elbow room for dynamically linked lists though if, for remaining code, (pass by address vs pass by reference) if you use assembly language on baremetal (if a chip allows it) to hardcode pointers (thereby not dynamically). You can then limit your usage of data types elsewhere so as to optimise.
ObsoletePowerCorrupts
ObsoletePowerCorrupts 4 місяці тому
@Andreas Spiess To overide an operator (for example "+" symbol), it could be written "C++" and that is where the name comes from. I reckon you'd grapple it alright (because you know the syntax). See "recursion UML" and "polymorphism OOP" in an image search online, and you'd fathom what to look at on youtube for guides. You'd see sequence diagrams and state diagrams and would start to recognise code things _(like "extends class", Constructors, Destructors, Static or Dynamic instanciation/allocation, etc.)._ Java does that via keyword "new". An example of a linked list is the words we are typing in these comments connected together with pointers.
Andreas Spiess
Andreas Spiess 4 місяці тому
Unfortunately I have no clue what you are writing about :-( I am more a user of simple tools and concepts...
Lolo Ji-42
Lolo Ji-42 4 місяці тому
Wow ! That was really an eye opener for me. I had no idea we could use that. Thank you weird accent guy !
Andreas Spiess
Andreas Spiess 4 місяці тому
Glad you liked it!
Glenn Hamblin
Glenn Hamblin 4 місяці тому
I have mixed feelings about RTOS of any kind. It seems very difficult to keep your code deterministic. For safety critical real time applications I prefer a state machine format. However, there are cases where a task schedulers make sense. 🙂 Thanks for the video!
Andreas Spiess
Andreas Spiess 4 місяці тому
I heard also other comments where they used RTOS because of safety reasons. But I agree, you have to change the programming and testing style compared to "non-blocking" code. I love state machines (the morse trainer uses one to create the morse signs). But not necessarily to do task management.
MrHasie
MrHasie 4 місяці тому
That twin cam though at 6:40
Andreas Spiess
Andreas Spiess 4 місяці тому
:-)
Yordan Yanakiev
Yordan Yanakiev 4 місяці тому
Andreas Spiess - I am fan of Your way of showing things up. I really hope that you have answer of the question - why would ESP32 sometime randomly after sleep just pretend that either it's without WiFi shield, or it is connected, but it is not ( and disconnect() / begin() does not fixing it, nor reconnect() ) ?
Yordan Yanakiev
Yordan Yanakiev 4 місяці тому
@Andreas Spiess I see. Well. Check it up, it's promising things for some projects which needs to keep a lot of info and continue execution from the point before go to sleep. You might find it useful in some situations. :) It practically freeze the execution even in complex multithreading situation.
Andreas Spiess
Andreas Spiess 4 місяці тому
I never used the light sleep mode so far.
Yordan Yanakiev
Yordan Yanakiev 4 місяці тому
@Andreas Spiess Well.. I am not arguing. Definitely I am not, but seems like it's something which a lot of peoples experiencing, and I wondered if You have ever come across after light sleep mode. Yet - thank you kindly for your answer.
Andreas Spiess
Andreas Spiess 4 місяці тому
Unfortunately, I cannot do remote debugging. Especially not for intermittent stuff. I am sure if you replace the word "ESP32" with "my sketch" you will find an answer. In most cases it is the sketch and not the ESP32 (unless it is defective). Look also at your WiFi network and change locations.
StarkRG
StarkRG 4 місяці тому
The first time I heard about the concept of an RTOS was from someone I used to hang out with online who was part of the development team for the RTOS on some fighter jet (the F22, I think), then seeing RTOS as an option when compiling the Linux kernel, and, finally, FreeRTOS on the ESP32.
Andreas Spiess
Andreas Spiess 4 місяці тому
The concept is old (I used one in the 80s). But now with the abundance resources it is very easy to use...
Inly Wang
Inly Wang 4 місяці тому
Great job
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you!
Lawrence D’Oliveiro
Lawrence D’Oliveiro 4 місяці тому
21:08 Spinlocks are commonly used for multiprocessor synchronization. The Linux kernel has them.
Lawrence D’Oliveiro
Lawrence D’Oliveiro 4 місяці тому
20:37 Have you looked at the Ada programming language? That dates from the 1980s, and has many built-in constructs for concurrency and synchronization. It was designed to work well for safety-critical applications. How safety-critical? The life support system on the International Space Station is implemented in Ada.
Lawrence D’Oliveiro
Lawrence D’Oliveiro 4 місяці тому
17:13 Inherent in the definition of a queue is the fact that it has FIFO behaviour. If it was LIFO, you call that a “stack”, not a “queue”.
Andreas Spiess
Andreas Spiess 4 місяці тому
There is a function xQueueSendToFront() available...
Lawrence D’Oliveiro
Lawrence D’Oliveiro 4 місяці тому
7:05 Also worth noting that the priority system is normally static. In timeshared OSes, process priorities can float over a certain range, to allow response times to adapt to what the programs are doing. You don’t want that in real-time applications.
Lawrence D’Oliveiro
Lawrence D’Oliveiro 4 місяці тому
4:57 Actually, Linux has some real-time options. Maybe not what you might call “hard real-time”, more like “soft real-time”, suitable for multimedia-type applications like live music/audio performance.
Lawrence D’Oliveiro
Lawrence D’Oliveiro 4 місяці тому
4:13 Odd to see so many processes with identical virtual and resident memory usages, totalling up to probably more than your machine can handle. Are they separate threads sharing the same memory context?
Andreas Spiess
Andreas Spiess 4 місяці тому
It is a Docker system, that is all I know...
kwinzman
kwinzman 4 місяці тому
Thank you for this amazing video! I like to believe that me commenting about FreeRTOS in your "The All-New Arduino IDE 2.0: Introduction and Test " video had a small role it its creation. 😊
Andreas Spiess
Andreas Spiess 4 місяці тому
:-)
Christopher Heald
Christopher Heald 4 місяці тому
This is so much more elegant than the mess of millis(). Thank you for the clear explanations, as always.
Andreas Spiess
Andreas Spiess 4 місяці тому
Indeed! Much easier to read.
René-Jean Mercier
René-Jean Mercier 4 місяці тому
Excellent !
Andreas Spiess
Andreas Spiess 4 місяці тому
Glad you like it!
Bernd Eckenfels
Bernd Eckenfels 4 місяці тому
Apropos Morse, die Gboard Google Android Tastatur kann Morse Eingabe: support.google.com/gboard/answer/9011881
Andreas Spiess
Andreas Spiess 4 місяці тому
Interesting! Thanks for the link.
Phillip Susi
Phillip Susi 4 місяці тому
My problem with FreeRTOS is that it has several different synchronization primatives, including message queues, notifications ( a 32 bit mask you can sit one bit to cause the task to weak up and quickly see which thing it should do ), semaphores, and a few others, but you can't mix and match them. A task can only block on one of them. You can't say, sleep until either you get one of the 32 most common notifications this task should respond to, OR one of the more complicated messages in a message queue. It's one or the other. Newer versions do at least have a system where you can wait on multiple different message queues, but is is internally implemented by having the slave message queues cause the sender to also send a one byte message to a master queue, and it is only that message queue that the listening process actually blocks on, which is kind of dumb.
Andreas Spiess
Andreas Spiess 4 місяці тому
I am no RTOS specialist and I do not understand the effects of those lacking things you describe :-( I assume you have to create very complex programs.
Daniel Carrasco Marín
Daniel Carrasco Marín 4 місяці тому
For me RTOS was a pain in the ass... I've migrated my sketch from RTOS to just a single core task scheduler because the ESP was all the time crashing... I want to update the date/time via NTP, use a RTC, read a DHT sensor, diplay all data in a ST7789 display... and is not easy. I got random crashes even using semaphores to keep it almost synchronous and run all tasks in core 1.
Michael Meichtry
Michael Meichtry 4 місяці тому
Awesomely great video! Of course real-time programming is not for the faint of heart! One must code carefully, but the results are well worth it when concurrent/parallel operation is required.
Daniel Carrasco Marín
Daniel Carrasco Marín 4 місяці тому
@Andreas Spiess Confirmed, was my fault ;). If your ESP32 crash after adding a task, first check the stack size. I've almost converted all my code into tasks again and now is working fine, and the problem looks like was the stack size of a task. I had it configured at 4k, and doing test I've needed at least 16k to stop crashing my ESP32. Now is very stable, and I can continue implementing all the functions.
Daniel Carrasco Marín
Daniel Carrasco Marín 4 місяці тому
@Andreas Spiess Yeah, I'm planning to retry it in a different way aplying what I've learned in your video (thanks for it). Surely is something that I'm doing wrong because is the first time I use FREERTOS. Who knows, because even maybe is just a library that is not fully compatible.
Andreas Spiess
Andreas Spiess 4 місяці тому
Bad luck. Debugging is not simple with RTOS. Reading the comments, quite a few users write about positive experiences...
John Colby
John Colby 4 місяці тому
But the Pico? I ran an rtos on a zilog sbc back in 1997. The Pico has as much memory and 2 cores.
Andreas Spiess
Andreas Spiess 4 місяці тому
I do not know if somebody ported FreeRTOS to the Pico. And you are right, we ran RTOS on 8080 and Z80s in the 1980.
ailijic
ailijic 4 місяці тому
Thank you for making this video.
Andreas Spiess
Andreas Spiess 4 місяці тому
You are welcome!
Nick y Isa P
Nick y Isa P 4 місяці тому
Great video, much to learn as always. After you last video on ESP32 using two cores I have built several multi tasking systems but I wasn't aware of this level of detail. After this I switched from std:: mutex to xSemaphoreCreateMutex() which saves some memory. FYI If you are porting existing code there is no need to go back and change the calls to delay(); In the framework delay(ms) simply calls vTaskDelay(ms / portTICK_PERIOD_MS);
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you for the tip about delay(). I was not sure.
Leif Neland
Leif Neland 4 місяці тому
I think if you are updating a larger datastructure, you need to protect it with a semaphore, so one process does not read data partially updated by another process. Also, for instance in a buffer, you need to make sure updating a pointer to the next character and putting the next character in the buffer can not be interrupted by another thread.
Leif Neland
Leif Neland 4 місяці тому
@Andreas Spiess longer structures would be put in messages, only put in a queue when they are complete and ready for processing.
Andreas Spiess
Andreas Spiess 4 місяці тому
You are right. Because all my tasks only need a fraction of a time slot and I actively give control back to the scheduler I did not think about that.
Leif Neland
Leif Neland 4 місяці тому
I had a rtos for z80 back around 1980.
Andreas Spiess
Andreas Spiess 4 місяці тому
Me too... But with lots of restrictions because of small resources. Now it is much easier.
flanker
flanker 4 місяці тому
I tried to make a self-balancing robot with ESP32 last year. I figured with it's beefy CPU it should be able to handle 2 steppers, 1 IMU, some LEDs, WiFi and a simple website. It was a nightmare. I solved most of the problems after weeks of work but never got the steppers to run smoothly. I think the Hardware Clock of the ESP32 is simply not made to drive steppers. I've seen other people use ESP32 to drive Steppers, so there's got to be a way but I lost my will to work on it. I think I'd have been better served if I used an Arduino Nano for stepper control and did the rest of the tasks on ESP.
Andreas Spiess
Andreas Spiess 4 місяці тому
There are stepper libraries for the ESP32 (I recently used one and had no issues)
RBYT
RBYT 4 місяці тому
ARM Mbed?
Andreas Spiess
Andreas Spiess 4 місяці тому
Will probably not run on an ESP32? But FreeRTOS is also ported for ARM CPUs
Freaky
Freaky 4 місяці тому
Great content, thanks
Andreas Spiess
Andreas Spiess 4 місяці тому
Glad you liked it!
large65
large65 4 місяці тому
At first! Thank you for your great explanations on all the different topics. They are fabulous! Just a minor remark: I think that RTOS is not about "fast" responses to an event, but about guaranteed (!) response (in a specified time). How fast the RTOS has to react depends on the physical properties of the system under control.
Andreas Spiess
Andreas Spiess 4 місяці тому
Good point!
Jackson See
Jackson See 4 місяці тому
can i ask what is the differrence between rtos and free rtos?
Jackson See
Jackson See 4 місяці тому
@Andreas Spiess OH !!!!! Thanks for your replying to me. I'm very much appreciated!!!
Andreas Spiess
Andreas Spiess 4 місяці тому
RTOS is the category name and FreeRTOS is one implementation. You get many more RTOS with different names.
Lost In Tech
Lost In Tech 4 місяці тому
I enjoy listening to how computers used to work. It's intriguing to try to figure out how you would share resources when everything is stored on tape...?
Andreas Spiess
Andreas Spiess 4 місяці тому
We once had a thing called "library" to share information which was attached to a physical "thing" ;-) But you are right, the separation of information from a physical medium made copying and transfer much easier. I love it!
Antonio Namnum
Antonio Namnum 4 місяці тому
I believe this video should be fundamental for every maker! Thanks Andreas!
Andreas Spiess
Andreas Spiess 4 місяці тому
Glad you think so!
Rixtronix LAB
Rixtronix LAB 4 місяці тому
Cool video, thanks for the info :)
Andreas Spiess
Andreas Spiess 4 місяці тому
You are welcome!
Carl Vanderlip
Carl Vanderlip 4 місяці тому
Real Time does not imply fast response, it implies that there are controllable/repeatable bounds to the response time. also, there is a real time scheduler for Linux.
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you for your addition/ correction.
David Stonier-Gibson
David Stonier-Gibson 4 місяці тому
Danke schön, noch einmal. I managed to get through a whole career in embedded controls without ever using a true RTOS. I started with bare-metal assembler in the early 70s, and retired the same way. I did during that time make many very simple superloop systems, and never wrote blocking code. As I have just transitioned from Arduino to ESP32, and in retirement started learning C++, I found this very interesting. One day I may just have to give it a spin.
Joseph M
Joseph M 2 місяці тому
I feel the same i.e. Is it worth the time to learn it and how much time to be fully understood? I think if you are into robotics where there are a lot of things going on it could be helpful. Most of my projects are pretty simple though.
Andreas Spiess
Andreas Spiess 4 місяці тому
As you write, you can do without it. But it is much easier to do it with one. We already used RTOS in the 80s for räsonable complex products. I am curious what your verdict would be after trying it...
Chris
Chris 4 місяці тому
"If you are good, you get more work!" Not going to lie, that line gave me flash backs to my Air Force days. haha As always, love the videos and I always learn a lot from you!
Andreas Spiess
Andreas Spiess 4 місяці тому
:-))
Kent talks tech
Kent talks tech 4 місяці тому
You sir are a gentleman and a scholar. Well done as usual.
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you!
Astral Chemistry
Astral Chemistry 4 місяці тому
I'm running Forth on the ATmega328p to ge able to program in real time, even over the air.
Andreas Spiess
Andreas Spiess 4 місяці тому
Very good. I did not know Forth had RTOS capabilities.
RP6conrad
RP6conrad 4 місяці тому
I use RTOS on the ESP32 for a gps-logger with a e-paper screen (GPS-speedsurfing). As the display routine was blocking (>0.5s), I was stucked... Then I discovered RTOS, and this was a fantastic tool to fix this problem ! Now the esp32 can receive, parse and store the gps data @ 10 Hz on a sd-card ! The display gives me the actual speed and distance. I still work with a lot of global variables, works fine for me !
Andreas Spiess
Andreas Spiess 4 місяці тому
A good application for an RTOS, indeed!
Dickes F
Dickes F 4 місяці тому
This video is super usefull! Thanks a lot!
Andreas Spiess
Andreas Spiess 4 місяці тому
Glad it was helpful!
marlb64
marlb64 4 місяці тому
Thanks Andreas, for yet another great educational video !!
Andreas Spiess
Andreas Spiess 4 місяці тому
Glad you liked it!
chatnel numéro 5
chatnel numéro 5 4 місяці тому
can we put RIOT on esp32?
Andreas Spiess
Andreas Spiess 4 місяці тому
Yes: doc.riot-os.org/group__cpu__esp32.html
varun
varun 4 місяці тому
Thanks for explaining FreeRTOS with well suited example as well. One thing I want to bring to your attention that FreeRTOS is not designed to support multiple CPU cores. You when you said that scheduler is giving time to core0 for network related tasks that is not completely correct. Yes scheduler manages core0 tasks as well but that is separate scheduler dedicated for core0. It means there are two separate schedulers running for core0 and core1.
Andreas Spiess
Andreas Spiess 4 місяці тому
You are right. In addition, Espressif added a few "bells and whistles" for two cores which are not standard.
Paul Nielsen
Paul Nielsen 4 місяці тому
For a great fork, look at Qnx (now a Blackberry Company). 18 years ago they posed the single floppy challenge to all OS manufacturers. They packed a complete OS with IP stack and graphical UI with mouse support on a single 1.44 meg floppy. Brilliant and Canadian.
Paul Nielsen
Paul Nielsen 4 місяці тому
@Andreas Spiess You are correct, it is proprietary. I just thought you'd enjoy the perspective of a great RTOS. It does run my current BB Z10 but they gave up on it in favour of white labelling other products. QNX is achieving great industrial success even in the automotive world. All the best Mr. Funny Hat (meant respectfully). Paul N.
Andreas Spiess
Andreas Spiess 4 місяці тому
I still remember my first Blackberry when it was a status symbol ;-) According to Wikipedia, QNX is proprietary and does not run on our MCUs.
Aaron Zhang
Aaron Zhang 4 місяці тому
Great video as always! There's an alternative solution to this problem, we can write non-blocking code with some help from libraries like AceRoutine.
Aaron Zhang
Aaron Zhang 4 місяці тому
@Andreas Spiess github.com/bxparks/AceRoutine it works on esp32 and esp8266.
Andreas Spiess
Andreas Spiess 4 місяці тому
Never heard of it. Thanks for the tip! Maybe not for the ESP32 because it already runs Freertos. But for Arduinos.
Saz Viki
Saz Viki 4 місяці тому
I understand that vTaskDelay() is a FreeRTOS function. Therefore it signals the RTOS not to schedule till the expiry of delay duration. But how keyboard.available() keeps the tasks from getting scheduled? Does FreeRTOS provide I/O functions too?
Andreas Spiess
Andreas Spiess 4 місяці тому
keyboard.available runs inside a task. So it runs every 1ms and checks if a letter is available. If not, you can give the control back to the scheduler (taskYIELD() )
Ilia Salaur
Ilia Salaur 4 місяці тому
I thought that i will never use FreeRTOS because of its pain in a.. , but this video changed my decision. Thanks a lot
Andreas Spiess
Andreas Spiess 4 місяці тому
You will love it!
Balázs Kelemen
Balázs Kelemen 4 місяці тому
I was recommended to use RTOS over regular ESP32 framework, as ESP framework suffers from bugs. According to this video, RTOS does not re-implement ESP things, it just reused them in an RTOS way. Or not? In other words: if there is a bug in ESP32 framework, is it likely to work correctly with RTOS?
Andreas Spiess
Andreas Spiess 4 місяці тому
I only use the Arduino framework and so far, did not suffer from bugs. So I do not know.
mars 000
mars 000 4 місяці тому
Well explained as usual Andreas.
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you!
AKA SiCkFoRM
AKA SiCkFoRM 4 місяці тому
Who's thumbs downing this?! Imagine getting quality education content for free and then disagreeing with it.
Andreas Spiess
Andreas Spiess 4 місяці тому
I have some "special friends" ;-) Let's hope they have a happy Sunday after the "thumbs down procedure".
Carl Gifford
Carl Gifford 4 місяці тому
Andreas, excellent instructional video. Your explanation of time slicing, task creation by breaking down the requirements of the program, communication queues was well explained. The analysis aspect of programming is a crucial skill that is required when incorporating the additional control of a multitasking environment into a program solution. Your big picture overview to small detail approach, embedded humour (pun) ensure your technical videos are a great learning tool and a joy to watch. Well done!
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you for your nice words!
Bela Platform
Bela Platform 4 місяці тому
Brilliant video, thank you! You may find our class on the Xenomai RTOS interesting. We use this for our hardware platform Bela. The lecture is more focused on realtime audio and sensor processing but there is definitely some fruitful crossover. ukposts.info/have/v-deo/hmOJn4eon3tn1I0.html
Max DiDo
Max DiDo 4 місяці тому
Great video, thanks for sharing this - I was used to C parallel programming on high performance computing, finding the similar concepts here makes me feel younger 😊
Andreas Spiess
Andreas Spiess 4 місяці тому
Glad you feel young! Here it is spring. A perfect time for that. These concepts are not new. We had RTOS in the 1980s already. But now they are much easier to use because we do not encounter limitations on the ESP32.
Trust me I'm an engineer!
Trust me I'm an engineer! 4 місяці тому
Very interesting. Now we need a good strategy to integrate sleeps to save energy in there :)
Trust me I'm an engineer!
Trust me I'm an engineer! 4 місяці тому
@Andreas Spiess but they don't run FreeRTOS ;)
Andreas Spiess
Andreas Spiess 4 місяці тому
The Atmel chips start where they were after deep sleep. A big difference in my opinion.
Trust me I'm an engineer!
Trust me I'm an engineer! 4 місяці тому
@Andreas Spiess I don't think it's mutch harder than in Arduino sketches. I usually maintain my state in RTC memory which works fine for most of my projects.
Andreas Spiess
Andreas Spiess 4 місяці тому
After deep-sleep, the ESP32 boots. Probably not easy to handle...
Trust me I'm an engineer!
Trust me I'm an engineer! 4 місяці тому
@Andreas Spiess Well I guess we can answer the "if"-question based on the fact that deep sleep is working with Arduino-Sketches and FreeRTOS is running all the time below Arduino. Comming to the how: For sure it is just for applications where the controller has to wait on something (I guess the morse trainier is not the best application for that). Then, the trick is to find out if tasks are finished or able to be postponed ... not easy ... I think I have to think a view more showers about that :)
Jeremy Kelaher
Jeremy Kelaher 4 місяці тому
Great presentation ! I love RTOS, by first was VxWorks, they really make embedded coding easier in most cases. Your single writer, multiple readers comment about mutex not being needed is only true for simple variables - if you need to update many parts of a struct, for example the x and y parts of coordinate, then either both reads and writes always need a mutex (if writes are common relative to reads) or a spin lock on write is needed (faster if writes are much less common than reads), or some odd stuff might be seen ! General rule is mutex unless performance is an issue then selectively remove them with massive comments in code - better safe than sorry . Defensive coding is always the RTOS coders friend !
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you for the addition about mutexes. I did not think about those cases because all my tasks only use a fraction of a slot and I always actively pass control back to the scheduler. But I agree: Better safe than sorry...
Torsten Rüger
Torsten Rüger 4 місяці тому
Thanks. Since i am just starting i decided to go with micropython and not arduino. They seem to have an async concept to allow for multitasking. It would be great to have see a comparison.
Torsten Rüger
Torsten Rüger 4 місяці тому
@Andreas Spiess Yes i watched that, it was using threads. But the async, that is incorporated since 1.1.3, allows lightweight tasks, much faster switching, and an easier programming model (cooperative multitasking, even one one core).docs.micropython.org/en/latest/library/uasyncio.html As i said, would be nice to see a comparison, eg that traffic light led code redone as async. Thanks T.
Andreas Spiess
Andreas Spiess 4 місяці тому
You are right. I showed how to use two cores using Micro Python.
Craig Hollabaugh
Craig Hollabaugh 4 місяці тому
Excellent comprehensive example with code examination. I've used FreeRTOS on 10 or so projects. What you've covered here is probably 90% of FreeRTOS projects. If users can get through your example understanding these concepts, their spaghetti code will become readable, understandable and maintainable. One last thing, do NOT use arduino delay. It affects the scheduler and your code will stop working. Search your code and change delay to vTaskDelay. Thanks from Colorado.
Craig Hollabaugh
Craig Hollabaugh 4 місяці тому
On Linux Arduino 1.8.13, ESP32 delay implementation is here. ~/.arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/esp32-hal-misc.c void delay(uint32_t ms) { vTaskDelay(ms / portTICK_PERIOD_MS); }
Craig Hollabaugh
Craig Hollabaugh 4 місяці тому
​@Andreas Spiess I looked at the ESP32 FreeRTOS delay code. It implements Arduino delay with vTaskDelay, so on the ESP32 using delay should work fine. I believe my comment above deals the smaller Atmel parts, 328P, with limited timers. Seems like I remember using Arduino delay changes TIMER2 (may be incorrect here), that's the same timer used by FreeRTOS's scheduler. It may be different now, but back then Arduino's delay affected the scheduler. If this is incorrect or has changed, please comment below. I've switched to using STM32's for my designs which runs FreeRTOS just fine. Thanks again for the video, I'm always interested in what your doing (keeps me from having to figure things out), you do a wonderful and complete exploration.
Andreas Spiess
Andreas Spiess 4 місяці тому
Thanks for sharing your experience! One question: What does the Arduino delay() harm? I thought, it just takes up all the time in the task's slot (which is, of course, not ideal).
THUNDERBOLT
THUNDERBOLT 4 місяці тому
my small feedback here: you presentation background image is hard on the eyes (moving dots or dot changing color illusion)
Andreas Spiess
Andreas Spiess 4 місяці тому
Thank you for your feedback. So far you are the first mentioning it.
y2ksw1
y2ksw1 4 місяці тому
As an app developer for cellular phones, I have to battle a lot with real time. This is a commonly underestimated skill, and many applications crash because they don't respect the underlying rules.
Andreas Spiess
Andreas Spiess 4 місяці тому
I completely agree!
Shawn Hymel
Shawn Hymel 4 місяці тому
Great explanation, and thanks for the shout out!
Andreas Spiess
Andreas Spiess 4 місяці тому
You are welcome!
Get to know FreeRTOS from the Creator! - DesignWest 2013
38:09
LPCZone
Переглядів 74 тис.
INSTASAMKA - LIPSI HA (prod. realmoneychlen)
2:01
INSTASAMKA
Переглядів 7 млн
D3 Mercedes S-класс Продажный тест.
24:34
smotraTV
Переглядів 1,3 млн
#112 LoRa / LoRaWAN De-Mystified / Tutorial
20:25
Andreas Spiess
Переглядів 697 тис.
I Made A Water Computer And It Actually Works
16:30
Steve Mould
Переглядів 3,7 млн
Control ANY COMPUTER with these Pi KVMs!
17:46
Jeff Geerling
Переглядів 11 тис.
#286 How does Software Defined Radio (SDR) work under the Hood? SDR Tutorial
27:20
#371 RISC-V: How much is open source? Featuring the new ESP32-C3
25:25
Andreas Spiess
Переглядів 128 тис.
Why Algae Could be the Plastic of the Future
11:47
Undecided with Matt Ferrell
Переглядів 96 тис.
INSTASAMKA - LIPSI HA (prod. realmoneychlen)
2:01
INSTASAMKA
Переглядів 7 млн
D3 Mercedes S-класс Продажный тест.
24:34
smotraTV
Переглядів 1,3 млн
D3 Mercedes S-класс Продажный тест.
24:34
smotraTV
Переглядів 1,3 млн
Холостячка - Сезон 2. Выпуск 1 - СМОТРИТЕ ПРЯМО СЕЙЧАС НА TELEPORTAL.UA
10:59
BIKINI LIFE HACK!! 😱 - #Shorts
0:53
Julius Dein
Переглядів 23 млн
3 тиждень - Танці з зірками. 8 сезон
3:9:31
Танці з зірками
Переглядів 221 тис.
Я не думал, что будет так...
30:39
Чердак
Переглядів 476 тис.