Hi and welcome to a new section in this discourse, in this section of several lectures where I'll show
you some topics that are specifically related to working with Michael Python on the E.S.P.
Thirty two, for example, in this first lecture of the section, I'll show you a couple of ways by
which he can interact with the micro python show and run interactive programs or even execute programs
that are already stored on the file system.
Then in the next lecture, I'll show you how to upload and download files using thony from your computer's
file system to the security file system and vice versa, and how to do things such as interrupt a running
program and so on.
So let's begin here with the shell.
The shell, of course, is running on the E.S.P 32 note on Sony.
Sony just gives us access to the shell.
And it's just one of the various ways by which you can access said we're going to show you how to do
that with Sony.
And this is something that you've already seen in previous lectures.
But I'm going to show you an alternative here where I use a program called Serial, which gives me access
to the exact same schill running on the E.S.P 32.
So I'm going to keep those two side by side.
And of course, only one of the two tools can be connected to the micro python show on the E at a time.
And right now I have connected Thorney to the show.
You can see that micro python device is available here on the left side of the Tony Idy and of course,
the shopfront right here waiting for my command.
So to demonstrate a couple of things here, I have connected a rate ality to Gibril twenty one and then
via a two hundred and twenty ohm resistor current the meeting resistor to ground the C here, the cathode
of the LDA goes towards ground and let me just put that back in place.
All right.
When you work with the show exclusively and let's imagine that we are not doing this on phonier right
now, so we don't have access to this file browser in particular here, one of the modules that you
want to be familiar with is the OS or the operating system.
So this module is a core module with Python or that is C Python.
And in this case, because we are working with Micro Python, there is a micro operating system where
you OS or micro OS services module, which contains a subset of the functions that you'll find in the
full blown C OS module.
The functions are listed here looking at the macro python documentation and you can see some of those,
for example, that you named the the micro main function gives you a table that contains those items
in it that helps you identify which device your script is working with, this random object with random
numbers, et cetera, et cetera.
But the one that I find interesting and we're going to use in the moment is this one here list directory.
So I'm going to use this directory to see what files are already running on my show, and then I'll
show you how to execute those files.
We can create directories or remove files, et cetera, so we can have a look at this location to see
what kind of functions are available to inside the OS services module.
So this is very useful.
Let's try it out.
I'm going to import U.
S first, and then I'm going to do a listing to see what files are available.
Of course, we can see those files here, but I'm going to do that one on the show.
So let's pick this command.
It's this just copy and paste in here, open close parentheses.
And you can see that in the root directory of these three files.
Of course, the whole world wide contains this script and I can just type it in the shell and run it
interactively.
I just say hello here and it will come back.
Now, let's say that instead of you typing the interactive comment into the show, you want to execute
an existing file like the Arrow and the score will be Wi-Fi.
Right.
So how do you do that?
There's a python command called Exec File, which I find very useful for exactly this purpose.
So I'm going to copy the name of the file.
And pasted in here, you can see as I clicked on this item in the array, the object inspector came
out and he told me what the contents of this array are, just pretty interesting.
And you get such beautiful partnership data and we close it for now.
So I have used a file past the argument, which is the name of the file and enter, and that would just
execute the program that is contained inside this file here.
So let's go over to the alternative, which is just another way of connecting to the exact same shell
in achieving the exact same thing.
So the first thing to do here is to disconnect.
And release my especially two and then I'm going to connect.
Heat control command to deal on my computer, but you can also do the terminal connect and that will
connect you to the shell hit enter to get the prompt and the prompt.
And I can do the exact same thing as I did in Sony.
So import your as so micro OS and then try out the directory Alistaire function where it is code completion
as well as I can hit tab and I'll get a code completion feature activated.
So these are the three of the two files plus the directory.
At this level there is no differentiation between a file in the directory and I'll use exec file to
execute.
Hello World P y and it works.
No problem at all.
So I'm going to disconnect from Serial and continue with a couple of other experiments in the.
She provided by Sony.
So let's click on Stop to actually start and the connections a bit counter, but still potentially to
stop and restart the back end so easily.
Three, two is connected again.
You can see it here.
It is good to go.
This is a look at another example here that involves the ability to now copy some code from the Python
file here on my local file system onto the shelf.
So first of all, there is the machine module, which contains various modules, including Pend, that
allows me to work with pins.
And I've got a lot more information about this in Sections seven and on which where I'm going to go
deep into those modules.
So for now, don't worry too much about them.
Just play along and see how this works then.
Actually, I'm not going to import any time or micro time.
I'm not going to worry about that for now.
Next thing to do is to create the ality object.
Connect the object to PIN twenty one and configure it as an output, then I'm going to use Alyda on.
To turn on the radio and really off to turn it off, very simple, so you can now control hardware resources
from the shell, but the show also allows you to create blocks of code.
So, for example, here there's a block of code, there's an infinite loop.
This is going to execute forever because the condition here is true.
It doesn't change.
So it's going to turn on the ality, hold it on for half a second and then turn it off and leave it
off for another second.
And this will give you the opportunity to show you how to work with loops on the comment on the shell
and also how to interrupt them.
So because we're using the Sleeth function here, I need to import sleep from the MICRA time module.
So there's sleep and I'm just going to take this.
So while true, don't forget the the two dots, in the end I can see that the shell is waiting for me
with indentation type something in that is going to be part of this wire block.
So Nelida on.
Then sleep or have a second and then the early days of and sleep for another half a second.
So now I'm done.
I've got to go back up and put the parentheses there.
So there is some intelligence in the show.
So you see that the show didn't panic.
I was just able to use the Iraqis to go back up one line and add the missing parentheses.
And they showed that show, knew there was something wrong there because they did had the Korei highlight
like that.
So you know that you need to close the parentheses to match the opening parentheses.
So done with that line and I'm actually done with the blog.
So I'm going to hit Enter one more time.
And now the entity is blinking on of half a second each time and you can see them not having the prompter
down here.
I don't see the prompter because my micro python instance is busy blinking this time.
So my DP 32 can't really do anything else right now.
It's locked up in this infinite loop to stop the infinite loop and to be able to do something else like
upload or download a file.
I need to either go in to run and say interrupt execution or just hit control, see, which is what
I'll do.
And that we interrupt the execution and break out of the loop forcefully, but it does break out of
the loop, the memory is not quite it's still there.
So I can still go back or turn on or off senility.
So the objects are still in memory.
And.
And she can see I am able to use the shield to write simple programs, test concepts out, and then
go in to my script and work on larger programs as part of a file one or more files.
So this was a demonstration of the things that you can do with the show, regardless of how you are
connected to the show, either using phony or some other tool.
In the next lecture, I'll show you how to do file management operations using phony phony.
It's a very convenient file manager, these two windows here which allow you to send files back and
forth between your host computer and the spirit listening post.