1
00:00:00,690 --> 00:00:07,860
Hi and welcome to a new section in this course, this section is the first one where I'll be doing practical

2
00:00:07,860 --> 00:00:13,800
demonstrations and showing you how to use micro python with a variety of peripherals.

3
00:00:14,010 --> 00:00:20,010
And of course, we'll start with the classic blink example in this and in the next lecture.

4
00:00:20,550 --> 00:00:25,980
Just a couple of things before we begin since, as I said, it is the first practical demonstration.

5
00:00:26,250 --> 00:00:31,890
Just want to talk to you a little bit about how I've set up these experiments, both on the hardware

6
00:00:31,890 --> 00:00:35,190
side and in terms of the software that we're using.

7
00:00:35,640 --> 00:00:41,730
So on the hardware side, to begin with, I'll be using just a generic SB 32 board.

8
00:00:41,850 --> 00:00:46,710
This one is the one with the 19 pins on each side.

9
00:00:47,070 --> 00:00:51,420
There's nothing special about this board is a cheap one that I found on eBay.

10
00:00:51,810 --> 00:00:58,050
It is a generic SB 32, and that's how you'll find it as well in Thony when you download and install

11
00:00:58,050 --> 00:00:58,820
the firmware.

12
00:00:59,130 --> 00:01:04,800
I'm not using external flash or anything like that now for my peripherals.

13
00:01:04,800 --> 00:01:08,910
I'm using too many boards attached, one next to each other.

14
00:01:08,910 --> 00:01:11,130
So I've got double the amount of space.

15
00:01:11,550 --> 00:01:18,720
And you can see here that I have wired the power rails to the three point three volt pin.

16
00:01:19,020 --> 00:01:26,640
So this pin right here and the ground pin and I've just taken those pins and connected them to the to

17
00:01:26,640 --> 00:01:33,480
the ground rail and to the three point three fourth rail and again with wires, I've connected the additional

18
00:01:33,480 --> 00:01:35,130
two power rails.

19
00:01:35,700 --> 00:01:42,270
Also, whenever possible, I will be using a sticker here with the number of the pin to which a component

20
00:01:42,270 --> 00:01:45,810
like Enilda or later on a potential on that or a button is connected to.

21
00:01:45,810 --> 00:01:52,110
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

22
00:01:52,110 --> 00:01:53,640
component is connected to.

23
00:01:54,360 --> 00:02:02,970
So having said all that, I'm going to like in my ears to back onto the boards and connect.

24
00:02:04,590 --> 00:02:05,580
Legazpi Cable.

25
00:02:05,790 --> 00:02:09,450
All right, let's have a look at what's happening on the software side.

26
00:02:09,780 --> 00:02:16,650
So in general, each experiment I'll be starting with thrown in a blank slate like this, nothing is

27
00:02:16,650 --> 00:02:17,160
loaded.

28
00:02:17,520 --> 00:02:26,000
You can see that I've got typically my scripts in a local directory and then you can navigate inside

29
00:02:26,020 --> 00:02:26,400
thony.

30
00:02:26,400 --> 00:02:33,890
You can navigate the directory where you have downloaded the scripts from the courses GitHub repository

31
00:02:34,200 --> 00:02:36,420
to in most cases, like in this case here.

32
00:02:36,630 --> 00:02:44,460
I'll be opening up the example script, having a look around, just become familiar with the way that

33
00:02:44,460 --> 00:02:45,000
it works.

34
00:02:45,210 --> 00:02:51,410
And then I will be there's a couple of ways to copy the script onto your ISP.

35
00:02:51,420 --> 00:03:02,100
Three to one way is to open up a new file, then copy the contents of the local file onto the new file,

36
00:03:02,100 --> 00:03:06,000
and then from here you can save it to your ISP for it to do that in a moment.

37
00:03:06,270 --> 00:03:11,400
Another way by which you can do that, you can close that another way by which you can do that is to

38
00:03:11,400 --> 00:03:14,610
go to file and then say save a copy.

39
00:03:15,000 --> 00:03:20,880
And then again, as long as your 32 is connected, then it's going to give you an option to save the

40
00:03:20,880 --> 00:03:25,830
copy on to the device or on to your local computer file system.

41
00:03:26,280 --> 00:03:27,300
So let's have a look at those.

42
00:03:27,600 --> 00:03:34,200
You can see that Mike is referring to is connected via USB, but it's not appearing yet in Sony.

43
00:03:34,230 --> 00:03:39,870
So I'm going to click on this button here just to trigger the connection of the device.

44
00:03:39,870 --> 00:03:46,710
And now it's a simple by default, when you upload the firmware for microprobe and onto your especially

45
00:03:46,710 --> 00:03:55,140
to the only file present is the boot p y file, which looks like that it doesn't do anything in general.

46
00:03:55,140 --> 00:04:02,090
I'm not going to be doing anything with dot p way because I want to be able to click on the run current

47
00:04:02,100 --> 00:04:10,740
script button up here, hit F5 to arbitrarily execute a Python script that is stored on my ISP 32 instead

48
00:04:10,740 --> 00:04:15,030
of having two power cycle in order to trigger whatever code is inside.

49
00:04:15,360 --> 00:04:16,500
But P y.

50
00:04:16,830 --> 00:04:25,470
But just remember that once you are happy with the operation of a script, then you can always change

51
00:04:25,470 --> 00:04:34,520
that script name to be P y and then you'll be able to execute it just by powering up your ISP 32.

52
00:04:35,070 --> 00:04:35,580
Alright, right.

53
00:04:35,590 --> 00:04:43,560
So now that we have the ISP 32 micro python device connected and you can see the listing of its file

54
00:04:43,560 --> 00:04:50,880
system here inside thony, then I can go ahead with step number two and copy my script across to the

55
00:04:50,880 --> 00:04:51,840
East 32.

56
00:04:52,320 --> 00:04:55,410
So I'm going to follow the copy method.

57
00:04:55,410 --> 00:05:03,300
So I'm just going to say save copy and then choose from a Python device and I'll give it the same name.

58
00:05:03,300 --> 00:05:11,700
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

59
00:05:11,700 --> 00:05:12,480
file system.

60
00:05:12,850 --> 00:05:24,330
So this is really the blink or 21. P why right now it appears right here going to double click on it

61
00:05:24,330 --> 00:05:25,200
to open it up.

62
00:05:25,200 --> 00:05:35,310
And here's my second tab with my Python script as it is saved on my ISP through to device and to highlight

63
00:05:35,310 --> 00:05:42,330
the difference in storage location between the two files, you can see that the local file system computer

64
00:05:42,330 --> 00:05:50,490
file system file does not have the square brackets around its file name while the ISP three to one or

65
00:05:50,490 --> 00:05:56,730
the file that is stored on the ISP three to filesystem per square brackets around its file name.

66
00:05:57,370 --> 00:06:04,770
So now you can get rid of the local file system, copy of the file and just work with the one that is

67
00:06:04,770 --> 00:06:06,390
stored on the ISP three two.

68
00:06:07,170 --> 00:06:13,260
With each one of the demonstration files, I tried to provide sufficient documentation in its header.

69
00:06:13,650 --> 00:06:19,800
So in general the header will look like this is going to have the number title for the script in the

70
00:06:19,800 --> 00:06:25,710
demonstration, a description of what it does, a listing of its components and then the documentation.

71
00:06:25,920 --> 00:06:34,050
So here we are using the PIN and the Slocum's function so you can find documentation about those two

72
00:06:34,050 --> 00:06:36,360
in the rules that are provided here.

73
00:06:36,900 --> 00:06:44,070
And in the case of the sleep function, for example, which is quite interesting, you click on this,

74
00:06:44,070 --> 00:06:49,440
you are or you copied across to your browser and it will take you to the appropriate part of the macro

75
00:06:49,440 --> 00:06:52,450
python or documentation side.

76
00:06:53,130 --> 00:07:01,680
Now, this function is interesting because this is the regular python or C Python time module.

77
00:07:02,040 --> 00:07:03,520
It's got the you in.

78
00:07:03,560 --> 00:07:10,220
In front of it to indicate that this is a micro python version of the time module and the difference

79
00:07:10,220 --> 00:07:20,330
between the full C Python time module and the new time module is that the module is optimized to make

80
00:07:20,330 --> 00:07:23,540
it work better, more efficiently on a micro python device.

81
00:07:23,990 --> 00:07:26,820
So it's missing a few functions.

82
00:07:26,840 --> 00:07:34,430
It's a bit more efficient in terms of memory usage and therefore will be using your time instead of

83
00:07:34,430 --> 00:07:42,290
time to introduce a delay, as you can see here of QWERTY while Loop and I've got a delay here to get

84
00:07:42,290 --> 00:07:47,730
the ability to blink on and off as similarly with the pins GPO server.

85
00:07:47,810 --> 00:07:52,670
Look, I'm going to use it especially to part of the documentation for this.

86
00:07:52,670 --> 00:07:56,120
And you can see that here as Pins and KBIO.

87
00:07:56,330 --> 00:08:03,830
And this is an example of how to use pins in the security of using micro python to be able to turn them

88
00:08:03,830 --> 00:08:04,710
on and off.

89
00:08:04,710 --> 00:08:08,210
We can also see how you can turn on the pull up resistor.

90
00:08:08,270 --> 00:08:13,820
We've been making use of this function in a later example, led a lecture in this section.

91
00:08:14,360 --> 00:08:24,390
So here you learn that you can turn on a bill just by calling the function of the PIN object.

92
00:08:24,650 --> 00:08:29,930
Here we've got a PIN object called P0 and that's how you create this object.

93
00:08:30,200 --> 00:08:39,170
You can turn it off by calling the function or you can use the value function and pass a one or a zero

94
00:08:39,170 --> 00:08:40,840
to it to turn it on and off.

95
00:08:41,330 --> 00:08:46,750
You can also check for the current value of a bill.

96
00:08:47,120 --> 00:08:50,080
We're going to show you how to use it in the very next lecture here.

97
00:08:50,330 --> 00:08:57,290
But it's a very convenient for you to see whether the GPA stand on and off without having to keep track

98
00:08:57,290 --> 00:09:00,050
of its state in an additional variable.

99
00:09:00,860 --> 00:09:09,590
So you can see there's a few ways by which you can manipulate the process using micro python on an E.S.P

100
00:09:09,590 --> 00:09:10,200
32.

101
00:09:10,220 --> 00:09:15,860
Of course, you use the same techniques to achieve the same kind of functionality on other market python

102
00:09:15,860 --> 00:09:18,860
devices like the Raspberry Pi Pekoe, for example.

103
00:09:19,640 --> 00:09:20,900
Or add back to a sketch.

104
00:09:21,170 --> 00:09:22,370
Again, it's pretty simple.

105
00:09:22,640 --> 00:09:30,260
All we do is to import the PIN functions from the machine module, the slip on the school.

106
00:09:30,260 --> 00:09:36,830
And as for microseconds from the time module, you can also import sleep instead of sleep image.

107
00:09:36,830 --> 00:09:40,940
And then we'll be talking about seconds instead of microseconds.

108
00:09:41,210 --> 00:09:49,340
Personal preference here, which one you want to go with creating then the ality object which represents

109
00:09:49,340 --> 00:09:55,280
the ality connected to your 21 and this is an output pin.

110
00:09:55,790 --> 00:10:02,750
And then the method that I'm using this example is to just use a loop, which is very similar to how

111
00:10:02,750 --> 00:10:11,810
you do this on an arduino and then turn on the ALYDA sleep for five hundred milliseconds and turn it

112
00:10:11,810 --> 00:10:15,350
off, sleep for another five hundred milliseconds, etc..

113
00:10:15,770 --> 00:10:25,430
If you had chosen to import sleep instead of sleep and this, then this function here would look like

114
00:10:25,430 --> 00:10:25,910
this.

115
00:10:26,150 --> 00:10:33,050
And if you wanted to have a five hundred millisecond or half a second delay, you would just use decimals.

116
00:10:33,050 --> 00:10:34,110
You'd go like that.

117
00:10:34,130 --> 00:10:35,690
So this would be half a second.

118
00:10:36,590 --> 00:10:37,790
Let's go back to the original.

119
00:10:39,510 --> 00:10:46,170
With the emphasis now, instead of saying early on or off, you could also say ality taught value one

120
00:10:46,170 --> 00:10:50,070
or ability to add value zero, whichever you prefer, is fine.

121
00:10:51,380 --> 00:11:00,440
All right, so I'm going to save that totally saved and click on the play button here or hit F5 on your

122
00:11:00,440 --> 00:11:04,850
computer to upload this script and.

123
00:11:06,450 --> 00:11:07,470
As you can see, it works.

124
00:11:08,430 --> 00:11:09,290
No problems at all.

125
00:11:11,700 --> 00:11:17,400
OK, so this was quite easy now in the next lecture, I want to show you an alternative way of getting

126
00:11:17,400 --> 00:11:18,900
this reality to blink.

127
00:11:18,900 --> 00:11:26,430
But in this alternative case, instead of using the loop like we did here, we are going to use a timer,

128
00:11:26,430 --> 00:11:32,720
which, as you can imagine, is a much more efficient way to use the resources of your.

129
00:11:32,760 --> 00:11:37,300
I could literally just go right ahead and have a look at this kwatinetz scenario.
