1
00:00:01,170 --> 00:00:08,790
In this election can show you how to set and use the real time clock or ROTC unit that is integrated

2
00:00:08,790 --> 00:00:14,670
into the E.S.P 32, which is basically a clock which keeps a very accurate account of the time.

3
00:00:15,180 --> 00:00:20,940
I want you to go to lectures and two experiments to demonstrate in the first one, which is this one

4
00:00:20,940 --> 00:00:26,850
here, which is going to show you the simplest way to work with the RTC simply to manually set it and

5
00:00:26,850 --> 00:00:29,490
then to get the time and date out of it.

6
00:00:30,360 --> 00:00:35,150
In the second lecture, which is coming up right after this one, I'm going to show you how to use the

7
00:00:35,160 --> 00:00:46,050
A.P. time library, as well as a Internet based real time clock service in order to acquire automatically

8
00:00:46,560 --> 00:00:53,540
accurate time from an atomic clock and use that to set your be 32 D.C..

9
00:00:54,150 --> 00:00:58,490
So let's keep things simple and begin with our first example.

10
00:00:58,860 --> 00:01:07,020
So the inability to, as I said, contains a real time clock and the micro python implementation that

11
00:01:07,020 --> 00:01:10,420
allows you to control it and to use it is very simple.

12
00:01:10,770 --> 00:01:12,690
So let's begin with the documentation.

13
00:01:12,690 --> 00:01:17,790
I am looking at the micro python documentation, quick reference for the SB 32.

14
00:01:17,790 --> 00:01:21,750
And down here you'll see a reference for the real time clock ATC.

15
00:01:22,200 --> 00:01:26,940
Click on that and you'll see an example of how you can use the ATC.

16
00:01:27,240 --> 00:01:29,430
You just create the ATC object.

17
00:01:29,430 --> 00:01:38,400
Then you use this initial data to set the date in time manually and then you can get the IDC date in

18
00:01:38,400 --> 00:01:42,060
time by calling day time, but without a parameter.

19
00:01:42,210 --> 00:01:47,730
And that will give you back a couple that contains the individual components for the date and the time.

20
00:01:48,330 --> 00:01:55,080
One thing or that I want to show you here in the E.S.P eight two six six real time clock documentation

21
00:01:55,350 --> 00:02:00,930
is that it also contains an example of how to use the A.P. time library.

22
00:02:01,200 --> 00:02:07,110
And therefore, as long as you're connected to a local network via Wi-Fi and from there to the Internet

23
00:02:07,110 --> 00:02:13,710
to this library will automatically go out and find a Interpeace server and synchronize the RTC.

24
00:02:13,980 --> 00:02:18,810
So the ISP 32 internal clock with the atomic clock on the Internet.

25
00:02:18,930 --> 00:02:21,250
But I'm going to show you how to do this in the next lecture.

26
00:02:22,170 --> 00:02:28,720
Now, another thing that I would like to mention here before moving on is that as per the years prior

27
00:02:28,740 --> 00:02:38,670
to documentation, when you put your inability to even to deep sleep, the RTC is still powered, which

28
00:02:38,670 --> 00:02:47,280
means that your clock will not lose its information and you will not need to reset it again after E.S.P

29
00:02:47,320 --> 00:02:48,400
32 wakes up.

30
00:02:48,810 --> 00:02:57,480
So for as long as your ISP 32 is powered, whether it is running properly or normally or is in light

31
00:02:57,480 --> 00:03:05,070
or deep sleep, then the clock will retain its data and the clock will continue ticking and keep the

32
00:03:05,070 --> 00:03:05,430
time.

33
00:03:06,300 --> 00:03:06,600
All right.

34
00:03:06,600 --> 00:03:08,820
Let's move on to the example script.

35
00:03:08,820 --> 00:03:09,510
Very simple.

36
00:03:09,510 --> 00:03:13,440
As you can see, I'm importing ATC from the machine module.

37
00:03:14,270 --> 00:03:15,380
I've got sleep.

38
00:03:15,390 --> 00:03:17,910
And this just to add a little bit of delay here.

39
00:03:17,920 --> 00:03:20,640
Every time I'm printing out the current time.

40
00:03:21,270 --> 00:03:28,050
And as per the example that you saw in the documentation of this, create the RTC object by calling

41
00:03:28,050 --> 00:03:35,990
the ATC constructor and then I am going to manually set the time and date.

42
00:03:36,510 --> 00:03:38,220
So here is a tough week.

43
00:03:38,220 --> 00:03:45,240
And she, of course, added she thought daytime and then the single parameter that daytime receives

44
00:03:45,660 --> 00:03:51,270
is a table that contains the individual components of the time, the days of the year, the month,

45
00:03:51,870 --> 00:03:57,450
the date, and then the day of the week and then the time.

46
00:03:57,870 --> 00:04:01,500
So hours, minutes, seconds and subsequence right here.

47
00:04:02,130 --> 00:04:08,880
So this is approximately the time now is going to change this to a six and for the second, such as

48
00:04:08,880 --> 00:04:09,660
make the zero.

49
00:04:11,390 --> 00:04:14,450
All right, then we're done here with the set up.

50
00:04:15,080 --> 00:04:19,710
The clock is now set and I've got an infinite loop every one second.

51
00:04:19,730 --> 00:04:25,130
It's going to get the date time by calling daytime or the ATC object without a parameter.

52
00:04:25,520 --> 00:04:30,330
And I'm going to print out the raw content of the daytime variable.

53
00:04:30,350 --> 00:04:36,230
It's just a couple is going to come out and then I'm breaking down the individual components of this

54
00:04:36,230 --> 00:04:40,040
table so I can extract the year, the month and so on.

55
00:04:40,550 --> 00:04:43,370
And then down here I'm doing the same thing, but extracting the time.

56
00:04:44,390 --> 00:04:46,280
So let's run this.

57
00:04:46,310 --> 00:04:49,790
I'm just going to save it and click on the play button.

58
00:04:50,660 --> 00:04:51,240
There you go.

59
00:04:51,500 --> 00:04:53,240
Here's what the table looks like.

60
00:04:55,020 --> 00:04:56,040
It should be bigger

61
00:04:58,800 --> 00:05:03,510
and we're just going to look at the first one, here's a current date a year, month and day of the

62
00:05:03,510 --> 00:05:08,230
week, just control C actually to stop.

63
00:05:08,270 --> 00:05:08,530
Right.

64
00:05:09,980 --> 00:05:20,000
So 28 year, month, day and day of the week of the week, as you see here, I just added a zero and

65
00:05:20,000 --> 00:05:23,270
then the clock will automatically just give me that.

66
00:05:23,780 --> 00:05:25,520
It seems like Monday is zero.

67
00:05:26,300 --> 00:05:28,250
Tuesday is one and so on.

68
00:05:29,930 --> 00:05:30,950
And then I've got the time.

69
00:05:31,910 --> 00:05:36,440
So the time started at the moment where I've said it.

70
00:05:36,800 --> 00:05:39,860
And then we've got the seconds, just counting.

71
00:05:41,460 --> 00:05:44,160
And as you can see, the time is correct.

72
00:05:46,430 --> 00:05:53,720
If I just canceled the execution of the program, if I import.

73
00:05:54,920 --> 00:05:59,880
To and create the RTC object, just like in the program.

74
00:06:01,980 --> 00:06:06,900
And then get the current day time from the ATC.

75
00:06:09,890 --> 00:06:10,700
Print it out.

76
00:06:15,800 --> 00:06:22,550
You can see that it is giving me the correct date and time at this moment, seven, 21 one.

77
00:06:22,640 --> 00:06:23,780
Yes, that's correct.

78
00:06:24,700 --> 00:06:30,770
So ATC is retained in hardware, regardless of whether my program is running or not.

79
00:06:31,730 --> 00:06:32,060
All right.

80
00:06:32,060 --> 00:06:34,110
So this was quite easy.

81
00:06:34,130 --> 00:06:43,370
How about we move on to the next lecture and learn how to acquire a very precise date and time from

82
00:06:43,370 --> 00:06:50,430
an atomic clock on the Internet so that you can use that to set your real time clock on the battery

83
00:06:50,450 --> 00:06:50,690
to.
