In this election can show you how to set and use the real time clock or ROTC unit that is integrated
into the E.S.P 32, which is basically a clock which keeps a very accurate account of the time.
I want you to go to lectures and two experiments to demonstrate in the first one, which is this one
here, which is going to show you the simplest way to work with the RTC simply to manually set it and
then to get the time and date out of it.
In the second lecture, which is coming up right after this one, I'm going to show you how to use the
A.P. time library, as well as a Internet based real time clock service in order to acquire automatically
accurate time from an atomic clock and use that to set your be 32 D.C..
So let's keep things simple and begin with our first example.
So the inability to, as I said, contains a real time clock and the micro python implementation that
allows you to control it and to use it is very simple.
So let's begin with the documentation.
I am looking at the micro python documentation, quick reference for the SB 32.
And down here you'll see a reference for the real time clock ATC.
Click on that and you'll see an example of how you can use the ATC.
You just create the ATC object.
Then you use this initial data to set the date in time manually and then you can get the IDC date in
time by calling day time, but without a parameter.
And that will give you back a couple that contains the individual components for the date and the time.
One thing or that I want to show you here in the E.S.P eight two six six real time clock documentation
is that it also contains an example of how to use the A.P. time library.
And therefore, as long as you're connected to a local network via Wi-Fi and from there to the Internet
to this library will automatically go out and find a Interpeace server and synchronize the RTC.
So the ISP 32 internal clock with the atomic clock on the Internet.
But I'm going to show you how to do this in the next lecture.
Now, another thing that I would like to mention here before moving on is that as per the years prior
to documentation, when you put your inability to even to deep sleep, the RTC is still powered, which
means that your clock will not lose its information and you will not need to reset it again after E.S.P
32 wakes up.
So for as long as your ISP 32 is powered, whether it is running properly or normally or is in light
or deep sleep, then the clock will retain its data and the clock will continue ticking and keep the
time.
All right.
Let's move on to the example script.
Very simple.
As you can see, I'm importing ATC from the machine module.
I've got sleep.
And this just to add a little bit of delay here.
Every time I'm printing out the current time.
And as per the example that you saw in the documentation of this, create the RTC object by calling
the ATC constructor and then I am going to manually set the time and date.
So here is a tough week.
And she, of course, added she thought daytime and then the single parameter that daytime receives
is a table that contains the individual components of the time, the days of the year, the month,
the date, and then the day of the week and then the time.
So hours, minutes, seconds and subsequence right here.
So this is approximately the time now is going to change this to a six and for the second, such as
make the zero.
All right, then we're done here with the set up.
The clock is now set and I've got an infinite loop every one second.
It's going to get the date time by calling daytime or the ATC object without a parameter.
And I'm going to print out the raw content of the daytime variable.
It's just a couple is going to come out and then I'm breaking down the individual components of this
table so I can extract the year, the month and so on.
And then down here I'm doing the same thing, but extracting the time.
So let's run this.
I'm just going to save it and click on the play button.
There you go.
Here's what the table looks like.
It should be bigger
and we're just going to look at the first one, here's a current date a year, month and day of the
week, just control C actually to stop.
Right.
So 28 year, month, day and day of the week of the week, as you see here, I just added a zero and
then the clock will automatically just give me that.
It seems like Monday is zero.
Tuesday is one and so on.
And then I've got the time.
So the time started at the moment where I've said it.
And then we've got the seconds, just counting.
And as you can see, the time is correct.
If I just canceled the execution of the program, if I import.
To and create the RTC object, just like in the program.
And then get the current day time from the ATC.
Print it out.
You can see that it is giving me the correct date and time at this moment, seven, 21 one.
Yes, that's correct.
So ATC is retained in hardware, regardless of whether my program is running or not.
All right.
So this was quite easy.
How about we move on to the next lecture and learn how to acquire a very precise date and time from
an atomic clock on the Internet so that you can use that to set your real time clock on the battery
to.