hey there! I have been using the Arduino Nano for a project and I noticed that I cannot perform multiple things at the same time unless I use a simulated function such as millis, in my code I use the delay function for timing. I was recently looking at videos on the esp32 chip and found that it can do multiple things at the same Time. I would like to have code run in the background with delay and still be able to turn off a screen and turn on a screen anytime I want while my delay is happening in the background. and while the delay is still happening I would like to even change values via rotary encoder, also even doing other things in the background, I cannot do this with Arduino Nano unless I use millis. my question is do any one of you guys ever used the esp32?
what was the process like moving over to the esp32?
is there anything better than the esp32 currently?
Learning to use millis() is a lot easier then learning multitasking on the esp32.
how so? can you explain
You have to learn the FreeRTOS mini operating system and then set up multiple tasks.
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos.html
The usual starting place for recommending "millis()" information is here:
For "multitasking" I like to recommend Programming Electronics Academy's multi-part
I have been through this but I asked question about esp32's not millis.
Here is a link to a simple tutorial using FreeRTOS and tasks that were mentioned by oldcurmudgeon, there are many more out there.
thank you
Using millis for "cooperative multitasking" is like placing TODO entries in your diary. As time progresses, you check your diary and when it is time to do one of the TODOs you do it.
"preemptive multitasking" is like juggling - all of the things are going at the same time, you need to ensure that you service each ball (task) when it needs it and you need to make sure that each ball (task) doesn't interfere with another ball (task) at random points during it's execution.
I would suggest that writing an entry in a diary and then doing it when the time comes is a much simpler thing to do than juggling.
In practical terms, imagine you have to do two things - in the first model, you do one and then the other, each one is a complete unit of work.
In the second model, it is kind of like two people working on the same project together at the same time. What can happen if you don't set it up correctly is that one of the people might have to do something - albeit temporarily - that interferes with what the other person is doing. I'm sure you have been in the situation of "Why did you do X? That prevented me from doing Y!".
Example, the two tasks require hammering nails into some wood - there is only one hammer and one bucket of nails available (i.e. the hammer and nails are a critical shared resource). You collected the nails but before you could get to it, the other guy took the hammer - now you have a problem to resolve. That is the sort of thing that you need to guard against in pre-emptive multitasking, but hopefully you can see wouldn't be an issue in the cooperative multitasking model because only one task is being performed at any one time, it is performed to completion before the next one starts (i.e. you use the hammer and the nails, then put them back for the next guy needs to use them).
The above is just a simplistic description, there is a lot more to it than that, but hopefully that gives you a basic idea. Perhaps have a read of this page about RTOS note that it says things like "tasks will be more or less independent of each other" and things like "...semaphores, Mutexes, queues, software timers.." - which are capabilities you will need to manage critical interactions such as, for example, if you attempt to take the hammer, you can be assured that you will also get the nails.
Both millis and RTOS style kernels can support multi-tasking. They just do it in different ways and provide different features and capabilities.
delay is bad in all but the simplest of scenarios because it is pretty much like pressing the "pause button" on a video. When you do that (i.e. call delay), pretty much nothing else will happen.
I hope that helps.
It can do 2 things at the same time, because it has 2 CPU cores. But using 2 CPU cores takes experience and careful engineering. For example if one CPU core tries to read a variable at the same time as the other cpu core is writing to the variable, all kinds of problems can occur, and avoiding all those problems takes knowledge and careful planning. With all due respect, I don't think you are at that level of knowledge and experience. So for you, whether the microprocessor has one core or two is pretty much irrelavent!
Âs long as you try to see in millis() something similar as delay()
it is very hard to understand because non-blocking timing based on millis() works very different.
As soon as you stop thinking
"replace delay() with millis()"
your mind gets opened to how non-blocking timing works
and then it becomes easy to understand.
Give this everyday example of baking a pizza and waiting fpr the pizza be ready to eat a chance to read it. And I promise you, you will start to understand how non-blocking timing works
best regards Stefan
imagine asking for information on if anyone used esp32's and they are talking about level of knowledge and experience. i may not know everything yes about coding but there are many ways to do 1 thing hence exploring esp32's. every time I come on a forum to ask questions it seems people are always trying to show you how much they know instead of actually guiding people. chatgpt is much better at explaining things than some of you it seems without getting personal.
you just confused me. i think I will go ask chatgpt. thank you for the help tho.
thank you for the link you provided more help than anyone here
thank you Stefan I just wanted to know if anyone used esp32's that's all and what was the transition like really.
I think you answered your own question.
Well you did not get the answer that you expected.
From their level of experience real experienced users can give you an idea of what is easier to learn.
And I second that. Learning to code multi-tasking with the FreeRTOS on an ESP32 is three times harder than learning non-blocking timing.
From beeing a newbe and having heard an ESP32 can do multiple things while using delay() is not enough information if this approach is really suitable.
As you have read you can do exact two things while using delay()
and then it is no longer very attractive to follow this approach.
Additionally you have to take care to not access variables at the same time from core1 and core 2 of an ESP32
And as experienced users know both FreeRTOS and non-blocking timing based on millis()
they can indeed say what is easier to learn.
It is definitely non-bocking timing based on millis()
The usual approach of this poor coded blink without delay-example makes it indeed harder to understand than it must be.
Anyway
if I try to use a scale how hard different things are to learn
if you found learning to use non-blockung timing based on millis()
difficulty-level 5
(I did not understand millis() after reading about it for 10 hours and experimenting another 5 hours)
learning FreeRTOS will take you 30 hours of reading and 15 hours of experimenting
to get the basics and another 50 hours to get things coded in a way that it works reliably
and as soon as you want to do a third thing you are back on
guess what?
non-blocking timing anyway
learning non-blocking timing based on millis() with the tutorial recommended above will take you 0,5 hours of reading and 1 hour of experimenting to understand it
These numbers are meant as relative. multiply or divide the learning time for FreeRTOS or millis() by that number that you have tried to understand it so far.
best regards Stefan
@drewiepooh The ESP32 has a lot going for it and is a faster more powerful mcu than the Nano. Whatever you have learnt about millis on your Nano can be seamlessly transfered to your ESP32 and you did mention you had "been through this" when advised about Blink Without Delay etc., this is useful information and good to keep in your toolbox.
Using the 2 cores of an ESP32 and implementing tasks is on another level but if it interests and motivates you then go for it, two processes in parallel is a great feature. Here is another link that may give you a little extra motivation.
Yes, I use the ESP32 fairly often. And if I want "to perform multiple things at the same time" I usually do it on ESP32 just like I do it on Nano. In most cases this is much more easy than using RTOS.
And don't say now that I won't answer your question. If you only want information about FreeRTOS, then ask accordingly. You only asked about ESP32, and you can multitask there just as you can on the Nano. The advantage of ESP32 is that it is faster and has more resources.
@drewiepooh
1. How do you like to define the following statements/vocabularies:
(1) doing two tasks at the same time.
(2) doing two tasks simultaneously.
(3) doing two tasks concurrently.
(4) doing two tasks in parallel.
2. Do you think that each of the above four statements does refer to a multi-tasking job?
3. Which one of the four tasks of Section-1 cannot be done by a human being? Can that be done by Arduino NANO? If not, why it is not? Can that be done by an ESP32? If yes, why it is yes?