Hi and welcome to a new section in this course, this section is the first one where I'll be doing practical
demonstrations and showing you how to use micro python with a variety of peripherals.
And of course, we'll start with the classic blink example in this and in the next lecture.
Just a couple of things before we begin since, as I said, it is the first practical demonstration.
Just want to talk to you a little bit about how I've set up these experiments, both on the hardware
side and in terms of the software that we're using.
So on the hardware side, to begin with, I'll be using just a generic SB 32 board.
This one is the one with the 19 pins on each side.
There's nothing special about this board is a cheap one that I found on eBay.
It is a generic SB 32, and that's how you'll find it as well in Thony when you download and install
the firmware.
I'm not using external flash or anything like that now for my peripherals.
I'm using too many boards attached, one next to each other.
So I've got double the amount of space.
And you can see here that I have wired the power rails to the three point three volt pin.
So this pin right here and the ground pin and I've just taken those pins and connected them to the to
the ground rail and to the three point three fourth rail and again with wires, I've connected the additional
two power rails.
Also, whenever possible, I will be using a sticker here with the number of the pin to which a component
like Enilda or later on a potential on that or a button is connected to.
So that all you've got to do is to look at any video frame and you'll be able to see where a particular
component is connected to.
So having said all that, I'm going to like in my ears to back onto the boards and connect.
Legazpi Cable.
All right, let's have a look at what's happening on the software side.
So in general, each experiment I'll be starting with thrown in a blank slate like this, nothing is
loaded.
You can see that I've got typically my scripts in a local directory and then you can navigate inside
thony.
You can navigate the directory where you have downloaded the scripts from the courses GitHub repository
to in most cases, like in this case here.
I'll be opening up the example script, having a look around, just become familiar with the way that
it works.
And then I will be there's a couple of ways to copy the script onto your ISP.
Three to one way is to open up a new file, then copy the contents of the local file onto the new file,
and then from here you can save it to your ISP for it to do that in a moment.
Another way by which you can do that, you can close that another way by which you can do that is to
go to file and then say save a copy.
And then again, as long as your 32 is connected, then it's going to give you an option to save the
copy on to the device or on to your local computer file system.
So let's have a look at those.
You can see that Mike is referring to is connected via USB, but it's not appearing yet in Sony.
So I'm going to click on this button here just to trigger the connection of the device.
And now it's a simple by default, when you upload the firmware for microprobe and onto your especially
to the only file present is the boot p y file, which looks like that it doesn't do anything in general.
I'm not going to be doing anything with dot p way because I want to be able to click on the run current
script button up here, hit F5 to arbitrarily execute a Python script that is stored on my ISP 32 instead
of having two power cycle in order to trigger whatever code is inside.
But P y.
But just remember that once you are happy with the operation of a script, then you can always change
that script name to be P y and then you'll be able to execute it just by powering up your ISP 32.
Alright, right.
So now that we have the ISP 32 micro python device connected and you can see the listing of its file
system here inside thony, then I can go ahead with step number two and copy my script across to the
East 32.
So I'm going to follow the copy method.
So I'm just going to say save copy and then choose from a Python device and I'll give it the same name.
I'm going to type it in and give it the same name as the name that the file is saved on my local computer
file system.
So this is really the blink or 21. P why right now it appears right here going to double click on it
to open it up.
And here's my second tab with my Python script as it is saved on my ISP through to device and to highlight
the difference in storage location between the two files, you can see that the local file system computer
file system file does not have the square brackets around its file name while the ISP three to one or
the file that is stored on the ISP three to filesystem per square brackets around its file name.
So now you can get rid of the local file system, copy of the file and just work with the one that is
stored on the ISP three two.
With each one of the demonstration files, I tried to provide sufficient documentation in its header.
So in general the header will look like this is going to have the number title for the script in the
demonstration, a description of what it does, a listing of its components and then the documentation.
So here we are using the PIN and the Slocum's function so you can find documentation about those two
in the rules that are provided here.
And in the case of the sleep function, for example, which is quite interesting, you click on this,
you are or you copied across to your browser and it will take you to the appropriate part of the macro
python or documentation side.
Now, this function is interesting because this is the regular python or C Python time module.
It's got the you in.
In front of it to indicate that this is a micro python version of the time module and the difference
between the full C Python time module and the new time module is that the module is optimized to make
it work better, more efficiently on a micro python device.
So it's missing a few functions.
It's a bit more efficient in terms of memory usage and therefore will be using your time instead of
time to introduce a delay, as you can see here of QWERTY while Loop and I've got a delay here to get
the ability to blink on and off as similarly with the pins GPO server.
Look, I'm going to use it especially to part of the documentation for this.
And you can see that here as Pins and KBIO.
And this is an example of how to use pins in the security of using micro python to be able to turn them
on and off.
We can also see how you can turn on the pull up resistor.
We've been making use of this function in a later example, led a lecture in this section.
So here you learn that you can turn on a bill just by calling the function of the PIN object.
Here we've got a PIN object called P0 and that's how you create this object.
You can turn it off by calling the function or you can use the value function and pass a one or a zero
to it to turn it on and off.
You can also check for the current value of a bill.
We're going to show you how to use it in the very next lecture here.
But it's a very convenient for you to see whether the GPA stand on and off without having to keep track
of its state in an additional variable.
So you can see there's a few ways by which you can manipulate the process using micro python on an E.S.P
32.
Of course, you use the same techniques to achieve the same kind of functionality on other market python
devices like the Raspberry Pi Pekoe, for example.
Or add back to a sketch.
Again, it's pretty simple.
All we do is to import the PIN functions from the machine module, the slip on the school.
And as for microseconds from the time module, you can also import sleep instead of sleep image.
And then we'll be talking about seconds instead of microseconds.
Personal preference here, which one you want to go with creating then the ality object which represents
the ality connected to your 21 and this is an output pin.
And then the method that I'm using this example is to just use a loop, which is very similar to how
you do this on an arduino and then turn on the ALYDA sleep for five hundred milliseconds and turn it
off, sleep for another five hundred milliseconds, etc..
If you had chosen to import sleep instead of sleep and this, then this function here would look like
this.
And if you wanted to have a five hundred millisecond or half a second delay, you would just use decimals.
You'd go like that.
So this would be half a second.
Let's go back to the original.
With the emphasis now, instead of saying early on or off, you could also say ality taught value one
or ability to add value zero, whichever you prefer, is fine.
All right, so I'm going to save that totally saved and click on the play button here or hit F5 on your
computer to upload this script and.
As you can see, it works.
No problems at all.
OK, so this was quite easy now in the next lecture, I want to show you an alternative way of getting
this reality to blink.
But in this alternative case, instead of using the loop like we did here, we are going to use a timer,
which, as you can imagine, is a much more efficient way to use the resources of your.
I could literally just go right ahead and have a look at this kwatinetz scenario.