1
00:00:00,750 --> 00:00:07,590
Hi and welcome to a new section in this discourse, in this section of several lectures where I'll show

2
00:00:07,590 --> 00:00:13,590
you some topics that are specifically related to working with Michael Python on the E.S.P.

3
00:00:13,590 --> 00:00:19,980
Thirty two, for example, in this first lecture of the section, I'll show you a couple of ways by

4
00:00:19,980 --> 00:00:27,720
which he can interact with the micro python show and run interactive programs or even execute programs

5
00:00:27,720 --> 00:00:31,230
that are already stored on the file system.

6
00:00:31,590 --> 00:00:38,520
Then in the next lecture, I'll show you how to upload and download files using thony from your computer's

7
00:00:38,640 --> 00:00:45,990
file system to the security file system and vice versa, and how to do things such as interrupt a running

8
00:00:45,990 --> 00:00:47,280
program and so on.

9
00:00:47,910 --> 00:00:50,330
So let's begin here with the shell.

10
00:00:50,650 --> 00:00:55,020
The shell, of course, is running on the E.S.P 32 note on Sony.

11
00:00:55,380 --> 00:00:58,350
Sony just gives us access to the shell.

12
00:00:58,530 --> 00:01:02,880
And it's just one of the various ways by which you can access said we're going to show you how to do

13
00:01:02,880 --> 00:01:04,050
that with Sony.

14
00:01:04,050 --> 00:01:06,600
And this is something that you've already seen in previous lectures.

15
00:01:06,960 --> 00:01:13,680
But I'm going to show you an alternative here where I use a program called Serial, which gives me access

16
00:01:13,680 --> 00:01:18,510
to the exact same schill running on the E.S.P 32.

17
00:01:19,110 --> 00:01:21,900
So I'm going to keep those two side by side.

18
00:01:21,900 --> 00:01:29,040
And of course, only one of the two tools can be connected to the micro python show on the E at a time.

19
00:01:29,040 --> 00:01:32,490
And right now I have connected Thorney to the show.

20
00:01:32,490 --> 00:01:39,600
You can see that micro python device is available here on the left side of the Tony Idy and of course,

21
00:01:39,600 --> 00:01:42,600
the shopfront right here waiting for my command.

22
00:01:43,560 --> 00:01:53,220
So to demonstrate a couple of things here, I have connected a rate ality to Gibril twenty one and then

23
00:01:53,220 --> 00:02:02,670
via a two hundred and twenty ohm resistor current the meeting resistor to ground the C here, the cathode

24
00:02:02,820 --> 00:02:08,370
of the LDA goes towards ground and let me just put that back in place.

25
00:02:09,360 --> 00:02:09,960
All right.

26
00:02:11,210 --> 00:02:17,990
When you work with the show exclusively and let's imagine that we are not doing this on phonier right

27
00:02:17,990 --> 00:02:24,920
now, so we don't have access to this file browser in particular here, one of the modules that you

28
00:02:24,920 --> 00:02:29,960
want to be familiar with is the OS or the operating system.

29
00:02:29,960 --> 00:02:36,220
So this module is a core module with Python or that is C Python.

30
00:02:36,680 --> 00:02:43,310
And in this case, because we are working with Micro Python, there is a micro operating system where

31
00:02:43,310 --> 00:02:51,230
you OS or micro OS services module, which contains a subset of the functions that you'll find in the

32
00:02:51,230 --> 00:02:54,330
full blown C OS module.

33
00:02:54,650 --> 00:02:59,720
The functions are listed here looking at the macro python documentation and you can see some of those,

34
00:02:59,840 --> 00:03:06,620
for example, that you named the the micro main function gives you a table that contains those items

35
00:03:06,620 --> 00:03:16,820
in it that helps you identify which device your script is working with, this random object with random

36
00:03:16,820 --> 00:03:18,250
numbers, et cetera, et cetera.

37
00:03:18,260 --> 00:03:24,590
But the one that I find interesting and we're going to use in the moment is this one here list directory.

38
00:03:24,600 --> 00:03:31,460
So I'm going to use this directory to see what files are already running on my show, and then I'll

39
00:03:31,460 --> 00:03:33,290
show you how to execute those files.

40
00:03:34,750 --> 00:03:40,310
We can create directories or remove files, et cetera, so we can have a look at this location to see

41
00:03:40,700 --> 00:03:46,520
what kind of functions are available to inside the OS services module.

42
00:03:47,120 --> 00:03:48,060
So this is very useful.

43
00:03:48,080 --> 00:03:48,980
Let's try it out.

44
00:03:49,020 --> 00:03:53,480
I'm going to import U.

45
00:03:53,660 --> 00:03:58,770
S first, and then I'm going to do a listing to see what files are available.

46
00:03:58,790 --> 00:04:03,470
Of course, we can see those files here, but I'm going to do that one on the show.

47
00:04:04,040 --> 00:04:06,230
So let's pick this command.

48
00:04:06,410 --> 00:04:13,940
It's this just copy and paste in here, open close parentheses.

49
00:04:14,180 --> 00:04:17,560
And you can see that in the root directory of these three files.

50
00:04:17,960 --> 00:04:25,940
Of course, the whole world wide contains this script and I can just type it in the shell and run it

51
00:04:25,940 --> 00:04:26,720
interactively.

52
00:04:26,730 --> 00:04:30,960
I just say hello here and it will come back.

53
00:04:31,460 --> 00:04:38,930
Now, let's say that instead of you typing the interactive comment into the show, you want to execute

54
00:04:38,930 --> 00:04:42,770
an existing file like the Arrow and the score will be Wi-Fi.

55
00:04:42,800 --> 00:04:43,100
Right.

56
00:04:43,670 --> 00:04:44,670
So how do you do that?

57
00:04:45,080 --> 00:04:53,180
There's a python command called Exec File, which I find very useful for exactly this purpose.

58
00:04:53,210 --> 00:04:56,000
So I'm going to copy the name of the file.

59
00:04:58,330 --> 00:05:06,820
And pasted in here, you can see as I clicked on this item in the array, the object inspector came

60
00:05:06,820 --> 00:05:11,560
out and he told me what the contents of this array are, just pretty interesting.

61
00:05:11,560 --> 00:05:16,430
And you get such beautiful partnership data and we close it for now.

62
00:05:16,840 --> 00:05:24,520
So I have used a file past the argument, which is the name of the file and enter, and that would just

63
00:05:24,520 --> 00:05:30,880
execute the program that is contained inside this file here.

64
00:05:31,570 --> 00:05:37,090
So let's go over to the alternative, which is just another way of connecting to the exact same shell

65
00:05:37,090 --> 00:05:39,100
in achieving the exact same thing.

66
00:05:39,580 --> 00:05:42,490
So the first thing to do here is to disconnect.

67
00:05:43,600 --> 00:05:48,970
And release my especially two and then I'm going to connect.

68
00:05:50,240 --> 00:05:57,950
Heat control command to deal on my computer, but you can also do the terminal connect and that will

69
00:05:57,950 --> 00:06:02,630
connect you to the shell hit enter to get the prompt and the prompt.

70
00:06:03,020 --> 00:06:05,500
And I can do the exact same thing as I did in Sony.

71
00:06:05,510 --> 00:06:17,000
So import your as so micro OS and then try out the directory Alistaire function where it is code completion

72
00:06:17,000 --> 00:06:23,860
as well as I can hit tab and I'll get a code completion feature activated.

73
00:06:24,530 --> 00:06:28,360
So these are the three of the two files plus the directory.

74
00:06:28,370 --> 00:06:36,680
At this level there is no differentiation between a file in the directory and I'll use exec file to

75
00:06:36,680 --> 00:06:37,520
execute.

76
00:06:38,270 --> 00:06:43,190
Hello World P y and it works.

77
00:06:43,310 --> 00:06:44,110
No problem at all.

78
00:06:45,430 --> 00:06:54,430
So I'm going to disconnect from Serial and continue with a couple of other experiments in the.

79
00:06:56,530 --> 00:06:58,440
She provided by Sony.

80
00:06:59,500 --> 00:07:06,520
So let's click on Stop to actually start and the connections a bit counter, but still potentially to

81
00:07:06,520 --> 00:07:09,800
stop and restart the back end so easily.

82
00:07:10,150 --> 00:07:11,440
Three, two is connected again.

83
00:07:11,440 --> 00:07:12,430
You can see it here.

84
00:07:12,890 --> 00:07:14,190
It is good to go.

85
00:07:15,910 --> 00:07:22,510
This is a look at another example here that involves the ability to now copy some code from the Python

86
00:07:22,510 --> 00:07:26,350
file here on my local file system onto the shelf.

87
00:07:27,010 --> 00:07:34,360
So first of all, there is the machine module, which contains various modules, including Pend, that

88
00:07:34,360 --> 00:07:36,580
allows me to work with pins.

89
00:07:36,580 --> 00:07:42,910
And I've got a lot more information about this in Sections seven and on which where I'm going to go

90
00:07:42,910 --> 00:07:44,460
deep into those modules.

91
00:07:44,460 --> 00:07:46,060
So for now, don't worry too much about them.

92
00:07:46,060 --> 00:07:51,120
Just play along and see how this works then.

93
00:07:51,460 --> 00:07:55,230
Actually, I'm not going to import any time or micro time.

94
00:07:55,240 --> 00:07:56,810
I'm not going to worry about that for now.

95
00:07:57,130 --> 00:07:59,740
Next thing to do is to create the ality object.

96
00:08:01,990 --> 00:08:10,360
Connect the object to PIN twenty one and configure it as an output, then I'm going to use Alyda on.

97
00:08:13,270 --> 00:08:25,690
To turn on the radio and really off to turn it off, very simple, so you can now control hardware resources

98
00:08:25,690 --> 00:08:30,640
from the shell, but the show also allows you to create blocks of code.

99
00:08:30,650 --> 00:08:34,030
So, for example, here there's a block of code, there's an infinite loop.

100
00:08:34,630 --> 00:08:41,200
This is going to execute forever because the condition here is true.

101
00:08:41,210 --> 00:08:42,010
It doesn't change.

102
00:08:42,370 --> 00:08:48,040
So it's going to turn on the ality, hold it on for half a second and then turn it off and leave it

103
00:08:48,040 --> 00:08:49,230
off for another second.

104
00:08:49,630 --> 00:08:54,520
And this will give you the opportunity to show you how to work with loops on the comment on the shell

105
00:08:54,670 --> 00:08:56,370
and also how to interrupt them.

106
00:08:57,100 --> 00:09:06,250
So because we're using the Sleeth function here, I need to import sleep from the MICRA time module.

107
00:09:06,370 --> 00:09:09,220
So there's sleep and I'm just going to take this.

108
00:09:09,430 --> 00:09:18,070
So while true, don't forget the the two dots, in the end I can see that the shell is waiting for me

109
00:09:18,400 --> 00:09:22,990
with indentation type something in that is going to be part of this wire block.

110
00:09:23,590 --> 00:09:26,800
So Nelida on.

111
00:09:28,010 --> 00:09:40,240
Then sleep or have a second and then the early days of and sleep for another half a second.

112
00:09:40,850 --> 00:09:41,740
So now I'm done.

113
00:09:42,130 --> 00:09:45,900
I've got to go back up and put the parentheses there.

114
00:09:46,300 --> 00:09:48,880
So there is some intelligence in the show.

115
00:09:48,880 --> 00:09:50,710
So you see that the show didn't panic.

116
00:09:51,070 --> 00:09:58,360
I was just able to use the Iraqis to go back up one line and add the missing parentheses.

117
00:09:58,360 --> 00:10:03,670
And they showed that show, knew there was something wrong there because they did had the Korei highlight

118
00:10:03,670 --> 00:10:04,300
like that.

119
00:10:04,930 --> 00:10:10,290
So you know that you need to close the parentheses to match the opening parentheses.

120
00:10:11,170 --> 00:10:15,670
So done with that line and I'm actually done with the blog.

121
00:10:15,670 --> 00:10:17,350
So I'm going to hit Enter one more time.

122
00:10:17,650 --> 00:10:26,020
And now the entity is blinking on of half a second each time and you can see them not having the prompter

123
00:10:26,020 --> 00:10:26,670
down here.

124
00:10:26,680 --> 00:10:33,370
I don't see the prompter because my micro python instance is busy blinking this time.

125
00:10:33,940 --> 00:10:38,350
So my DP 32 can't really do anything else right now.

126
00:10:38,440 --> 00:10:45,700
It's locked up in this infinite loop to stop the infinite loop and to be able to do something else like

127
00:10:45,700 --> 00:10:47,020
upload or download a file.

128
00:10:47,410 --> 00:10:56,440
I need to either go in to run and say interrupt execution or just hit control, see, which is what

129
00:10:56,440 --> 00:10:56,860
I'll do.

130
00:10:58,000 --> 00:11:03,760
And that we interrupt the execution and break out of the loop forcefully, but it does break out of

131
00:11:03,760 --> 00:11:07,040
the loop, the memory is not quite it's still there.

132
00:11:07,060 --> 00:11:12,370
So I can still go back or turn on or off senility.

133
00:11:12,940 --> 00:11:14,890
So the objects are still in memory.

134
00:11:16,410 --> 00:11:17,070
And.

135
00:11:20,030 --> 00:11:26,330
And she can see I am able to use the shield to write simple programs, test concepts out, and then

136
00:11:26,330 --> 00:11:34,160
go in to my script and work on larger programs as part of a file one or more files.

137
00:11:34,850 --> 00:11:39,380
So this was a demonstration of the things that you can do with the show, regardless of how you are

138
00:11:39,380 --> 00:11:44,540
connected to the show, either using phony or some other tool.

139
00:11:44,900 --> 00:11:51,440
In the next lecture, I'll show you how to do file management operations using phony phony.

140
00:11:51,450 --> 00:11:58,940
It's a very convenient file manager, these two windows here which allow you to send files back and

141
00:11:58,940 --> 00:12:04,380
forth between your host computer and the spirit listening post.
