In a previous lecture, they learned how to control the C.P.U clock frequency of your E.S.P 32, and
that is a way to reduce the power consumption of your microcontroller, which is particularly useful
when you are powering a gadget from a battery.
In this lecture, I'm going to show you an additional method of reducing power consumption, and that
is by putting your attitude to sleep when it's not needed to do any useful work.
So while the of two is sleeping, of course, its power consumption is much reduced according to the
documentation.
So we'll look at it here.
And I'm looking now at the quick reference for the ESB 32 in the Micro Python or Jaedicke accommodation.
You go down to deep sleep mode.
You see that there is a way here to place the microcontroller to deep sleep.
It can never do that indefinitely.
So if you don't provide a parameter here, then the microcontroller is going to be sleeping until you
reset it.
Or you can give it an amount of time in milliseconds and it's going to be in deep sleep in this case
for that amount of milliseconds and then reset itself if it's coming back from deep sleep and resume
its operation.
So there is also another type of sleep that is possible.
So if you have a look at again, looking at macro python org under the machine module, you'll see that
there are power related functions.
And apart from deep sleep, there's also light sleep option, which I have tested with the ease with
the data and it seems to be working properly with light sleep.
The MCU is not turned off.
Simply several of its subsystems are powered off, but other parts are still operating.
In particular, the RAM is not wiped out.
So that means that after a soft reset, your program can continue operating.
So that's the biggest difference between light sleep and deep sleep.
There's information, of course, here about the difference between these two sleep modes, and this
further information is specific to the ESB through to here, good to the IF documentation website,
and that is be free to look for the sleep mode so you can search for it or can follow the link that
I have provided here in the head of this, which is this link right here.
And that will give you detailed information about which parts of the market controller continue to operate
or which ones are powered down when you enter one type of sleep or the other.
OK, now I want to do a demonstration of these two sleep modes first on the shell, and then I am going
to copy my test program into the beta profile so that I can power my is be two from my power supply
and use my alma mater to measure the actual power consumption in these two different sleep modes.
So first, what I do have already connected my eyes with the idea of the shopfront here.
I will import machine.
So I can access the notes and the first type of sleep that I'm going to test this landslip, so I'm
going to copy this comment here and pasted in the schill and enter.
And as you can see, the security went to sleep for about a second, and that's why we've got a delay
in the prompt appearing again and then it came out of sleep.
Now, the interesting thing is this.
I remember that I've imported the machine.
I'm going to use this comment here now to check on the type of sleep that the security just woke up
from.
And that is No.
Four, right.
So let's check this out.
What is sleep number four?
Go into machine functions and the constant here.
You'll see these are the reset quarters and this is zero one, two, three, four, which means that
especially to reset course was not before it was soft reset.
So in other words, when you put your E.S.P three, two, two into the light sleep, then after that
comes back from a sleep, in this case 1000 milliseconds, then light sleeper will cause a soft reset
to itself so that it can then resume its operation.
If, on the other hand, I'll go for a deep sleep, which can go for deep sleep, Klickitat.
Paste that across.
I just wanted to point to that, that I was able to do actually work so work to get the reset course
because the ram was not wiped out and the machine module was still imported.
Now, look at what happens with a deep sleep.
So deep sleep for 10000 milliseconds, about 10 seconds.
So the longer the prompt is gone, I especially do is deeply sleeping now.
And 10 seconds later, you see that we've got a deep sleep reset, which is similar to just pressing
on the reset button manually, if I try to call for a.
Try to check the reset course like this, you see that the machine launched is not defined.
I have to first imported.
Because the rain was wiped out, essentially, the program will start operating from scratch if it was
actually deploy program.
So important machine now to take the risk, of course, you see, it's no full to actually be surprised.
That should have been.
Probably deep sleep research zero one, two, three should be three.
So I'm going to do this one more time.
Go for sleep, deep sleep.
Can you make that one second this time?
OK, recent import the machine module and check it recept course for interesting, I'm going to do a
hard reset and just by pressing the reset button.
Can see this type is power on the reset.
And of course, I try this the machine isn't Defitelio to import machine first and then check the course
and this one is going to be number one, right?
Dimethyltryptamine, forgiveness.
No one is a hard reset.
So that's how you can check on what was it that caused the reset.
I'm not sure why the report here for the reset course.
It remains to be for after I have done a deep sleep, but I've got to think about that.
I've done a bit of testing that earlier and it seemed to be working properly.
But just keep that in mind that the report coming back from the reset cause function may not differentiate
between light sleep and deep sleep.