1
00:00:00,810 --> 00:00:07,470
This actually talk about micro python built in modules, these are modules that come with the micro

2
00:00:07,470 --> 00:00:13,950
python interpreter and they are accessible from the scripts running from your E three to you don't have

3
00:00:13,950 --> 00:00:20,170
to import or install any additional files to be able to use the built in modules.

4
00:00:20,700 --> 00:00:25,710
So let's have a quick look at the documentation to begin with and then I'll give you a short demonstration.

5
00:00:26,380 --> 00:00:31,100
Let's go to the latest version of the macro python, the competition.

6
00:00:31,110 --> 00:00:37,080
I'm looking at version one point fourteen here and the very top you'll see a section of micro python

7
00:00:37,080 --> 00:00:38,520
libraries in here.

8
00:00:38,520 --> 00:00:43,230
You'll see there's a few different subcategories of subsections.

9
00:00:43,590 --> 00:00:49,360
First of all, you've got the Python standard libraries and micro libraries right here.

10
00:00:49,380 --> 00:00:58,620
You've got libraries such as math or C UI, although we also use an S for the operating system and so

11
00:00:58,620 --> 00:00:58,830
on.

12
00:00:59,550 --> 00:01:06,090
Then after that, you've got micro python specific libraries such as Machine, which we are going to

13
00:01:06,090 --> 00:01:09,450
be using a lot, and the social network and so on.

14
00:01:09,810 --> 00:01:16,920
And then you've got libraries that are specific to the market and using in our case there is three 32.

15
00:01:17,250 --> 00:01:22,290
So you drill into that and you see that there's a couple of modules here that provide functions specific

16
00:01:22,590 --> 00:01:23,980
to the ISP 32.

17
00:01:24,540 --> 00:01:28,920
Now back to the beginning, just to talk a little bit more about what each one of these does.

18
00:01:29,310 --> 00:01:38,160
The Python standard libraries are libraries that you normally find in the regular or C Python programming

19
00:01:38,160 --> 00:01:38,670
language.

20
00:01:39,030 --> 00:01:44,460
And these are also modules in libraries that come with standard python.

21
00:01:45,090 --> 00:01:53,340
The implementation of those libraries into Micra Python is very close to you, but you cannot expect

22
00:01:53,670 --> 00:02:01,800
one to one correspondence between the functions available, for example, in the IO input output library

23
00:02:02,130 --> 00:02:06,480
in Python against that, that is available in micro python.

24
00:02:06,810 --> 00:02:15,360
So, for example, in this case, you see that I o or the Python Library starts with a U in front of

25
00:02:15,360 --> 00:02:24,540
it, which makes it micro IO and that indicates that this is the micro python version of the IO module

26
00:02:24,540 --> 00:02:26,630
that comes with C Python.

27
00:02:27,120 --> 00:02:32,990
So you can see here there is a reference to this Python input output or IO module.

28
00:02:33,240 --> 00:02:36,830
We're going to click on that and take us over to that documentation.

29
00:02:36,830 --> 00:02:42,030
And we are now looking at Python version three point five and this is the IO.

30
00:02:43,180 --> 00:02:51,820
Documentation of the condition for the library and you can see it right here against what you provides

31
00:02:51,820 --> 00:02:54,260
us in a micro python environment.

32
00:02:54,700 --> 00:03:02,500
So the basic functions will be available, but they will be optimized to operate on a limited performance

33
00:03:02,500 --> 00:03:06,670
environment, preserve memory, for example, and lower ship use cycles.

34
00:03:07,030 --> 00:03:10,090
And some functions might not even be available at all.

35
00:03:10,360 --> 00:03:19,420
So we've got the function open, for example, here, and it's a search for open mic that is also available

36
00:03:19,420 --> 00:03:19,780
here.

37
00:03:20,290 --> 00:03:22,200
And you can use it typically in the same way.

38
00:03:22,210 --> 00:03:28,080
So in Python, the function open requires a file to open.

39
00:03:28,120 --> 00:03:33,440
Then you've got the open modifier sort of mode of the operation of the file.

40
00:03:33,460 --> 00:03:38,470
So whether you'd like to read it, for example, or appended or write and so on, we talk more about

41
00:03:38,470 --> 00:03:39,020
this later.

42
00:03:39,370 --> 00:03:43,070
And then there's also the type of encoding that the file contains.

43
00:03:43,090 --> 00:03:49,840
Now, on the other side, on the micro python side, we have the name again, then the mode, as well

44
00:03:49,840 --> 00:03:52,580
as the third parameter here for the encoding.

45
00:03:52,600 --> 00:03:57,910
But just not notice what it says here or ports which provide access to the file system are required

46
00:03:57,910 --> 00:04:01,230
to support the mode parameter, this parameter right here.

47
00:04:01,510 --> 00:04:07,630
But whether the other arguments are supported, these arguments over here depend on the port, which

48
00:04:07,630 --> 00:04:14,680
means depending on which target device you are writing, your micro python program for, whether it

49
00:04:14,680 --> 00:04:18,240
is for the security or the weepie or something else.

50
00:04:18,970 --> 00:04:25,690
So you need to be a bit careful and consider your target as well when you use in those classes and those

51
00:04:25,690 --> 00:04:26,210
functions.

52
00:04:27,010 --> 00:04:32,650
So that's what's happening here with the Python standard libraries.

53
00:04:32,830 --> 00:04:35,550
And we've got micro python specific libraries.

54
00:04:35,830 --> 00:04:43,300
So these are libraries that only exist in the micro python world that don't exist in Python, for example,

55
00:04:43,300 --> 00:04:48,160
the machine module, which contains functions that relate to the hardware.

56
00:04:48,170 --> 00:04:53,880
You can do things such as reseeded in soft, reset it, disable or enable Arcus and so on.

57
00:04:54,040 --> 00:04:58,000
And these don't make sense, of course, for the regular C Python language.

58
00:04:58,270 --> 00:05:07,720
So if you go over to the C documentation and try to search for a machine module, you find it here,

59
00:05:07,870 --> 00:05:15,430
some machine module specifically designed for micro python and for the hardware tankage that it supports.

60
00:05:16,790 --> 00:05:24,830
Then we've got the port specific libraries, so these are libraries that specifically operate on target

61
00:05:24,830 --> 00:05:26,910
hardware devices and target microcontrollers.

62
00:05:27,380 --> 00:05:34,220
So we're talking about things such as PIB or Pay Board or the HP three to show that.

63
00:05:35,160 --> 00:05:41,610
We'll take us down here for us in our case, since we're using the hospital to click on the ASPCA to

64
00:05:41,910 --> 00:05:44,650
a specific library and you'll see that there is one.

65
00:05:45,240 --> 00:05:54,090
Its name is ASPCA two, which gives us functions such as to wake up one touch or an external pen sending

66
00:05:54,090 --> 00:06:01,590
an IQ or that reads the integrated thermometer to give us the real temperature.

67
00:06:01,590 --> 00:06:03,990
I'll give you an example of this in a moment and so on.

68
00:06:04,440 --> 00:06:12,330
So this is a library that only works on the E.S.P 32 and provides specific functions that only make

69
00:06:12,330 --> 00:06:14,270
sense on the age of two.

70
00:06:14,910 --> 00:06:18,950
So let's play a little with this particular library here.

71
00:06:19,120 --> 00:06:23,250
Just going to make a little bit of room here so we can have the two in the side by side.

72
00:06:23,790 --> 00:06:25,500
And I'm using the show.

73
00:06:25,500 --> 00:06:32,240
I'm connected to my ears to to use the ASPCA to board specific library.

74
00:06:32,250 --> 00:06:33,780
I just need to import it.

75
00:06:34,520 --> 00:06:37,710
So, as usual, I just say import E.S.P 32.

76
00:06:38,040 --> 00:06:43,620
I didn't have to install a file with the name E.S.P 32.

77
00:06:44,070 --> 00:06:48,870
Why said this integrated into the firmware that is running on the microcontroller.

78
00:06:49,500 --> 00:06:58,620
And I do something simple, like I get the internal temperature, internal temperature of my HP 32 right

79
00:06:58,620 --> 00:06:59,040
now.

80
00:06:59,370 --> 00:07:04,110
I'm just going to copy this, paste it in here and enter.

81
00:07:04,470 --> 00:07:07,200
And there is its temperature in Fahrenheit.

82
00:07:08,040 --> 00:07:09,780
So you can see very simple.

83
00:07:10,230 --> 00:07:14,070
Can you see the whole sensor with this case?

84
00:07:14,070 --> 00:07:20,010
I'm going to type it in and use code completion, open close parentheses.

85
00:07:20,010 --> 00:07:23,970
And that is the reading from the integrated magnetic code sensor.

86
00:07:25,140 --> 00:07:29,820
Very easy, as I said, the other thing that you can do here is you can be very specific.

87
00:07:29,820 --> 00:07:38,310
As I said, the memory of the two and other microcontrollers running micro python is fairly limited

88
00:07:38,310 --> 00:07:41,320
compared to that of a computer running python.

89
00:07:41,700 --> 00:07:49,140
So by me importing the whole of the ISP through tumultuously means that are imported all of those functions,

90
00:07:49,620 --> 00:07:54,030
even though I am only interested in using, for example, the real temperature function.

91
00:07:54,570 --> 00:08:02,430
So what I wanted, what I can do in order to be a bit more nimble with my use of resources, I can just

92
00:08:02,430 --> 00:08:07,110
import the specific function that I want to use so I can say.

93
00:08:10,180 --> 00:08:26,350
From E.S.P ferry to import real temperature like that, and now I can call real temperature by name

94
00:08:26,350 --> 00:08:33,120
like this without having to prevent the security dot, as I did earlier, because earlier I just imported

95
00:08:33,130 --> 00:08:38,900
a whole lot, just imported the real temperature function, which means that I can just call it by name

96
00:08:38,900 --> 00:08:40,550
and I'm getting back the same result.

97
00:08:41,140 --> 00:08:47,440
So the second instance, I have been a lot more precise about what it is that I want to import from

98
00:08:47,440 --> 00:08:48,370
a large module.

99
00:08:49,090 --> 00:08:50,890
You'll see later in the next lecture.

100
00:08:50,900 --> 00:08:58,960
Actually, some of the modules that you can import for your projects can be very large in size because

101
00:08:58,960 --> 00:09:05,790
they are designed to cover a multitude of situations and multitude of target hardware.

102
00:09:06,310 --> 00:09:13,000
So you can be specific about which parts of those modules you want to import in order to preserve memory.

103
00:09:14,160 --> 00:09:18,270
All right, so that's about it with the building modules.

104
00:09:18,310 --> 00:09:24,440
Let's go over to the next picture now and a look at that particular community, which was.
