1
00:00:00,720 --> 00:00:07,980
But in this lecture, I show you how to use the permit 280 with your E.S.P, 32 using micro python.

2
00:00:08,730 --> 00:00:16,590
Now, unlike in the previous lecture, we are to learn how to use the DHT 22 using a driver that comes

3
00:00:16,590 --> 00:00:18,990
with the micro python firmware.

4
00:00:19,440 --> 00:00:25,440
The two hundred and eighty does not have an integrated driver, which means that you need to go out

5
00:00:25,440 --> 00:00:32,910
to find one that works with your set up and then imported into your S.P.C.A. stored in the flash memory

6
00:00:32,910 --> 00:00:34,650
so that your script can use it.

7
00:00:35,250 --> 00:00:41,250
So this is the main difference between the approach that we used in the previous lecture with the 22

8
00:00:41,550 --> 00:00:50,760
and the one that we use now with the BMY 280 is that we're going to use a third party micro python driver

9
00:00:51,210 --> 00:00:52,350
for this sensor.

10
00:00:53,010 --> 00:00:59,550
In most cases, this is the approach that you have to take with pretty much any other peripheral to

11
00:00:59,550 --> 00:01:00,990
your ESP 32.

12
00:01:01,230 --> 00:01:07,680
You'll have to use Google or some other search engine to look for an available driver for the device

13
00:01:07,680 --> 00:01:08,550
that you want to use.

14
00:01:09,150 --> 00:01:20,430
In my case, I find that awesome micro python dot com contains an excellent list of drivers or libraries

15
00:01:20,430 --> 00:01:21,540
for Macra Python.

16
00:01:21,810 --> 00:01:24,120
Not all of them work in my experience.

17
00:01:24,120 --> 00:01:31,890
But you've got a good chance that whatever hardware you want to use, you will find a micro python driver

18
00:01:31,890 --> 00:01:42,030
in this list, in particular for the BMY 280, he could look for sensors and say around.

19
00:01:43,660 --> 00:01:54,190
Here you'll find that the BMY 280 has a few options, so there's 280 this 180 as a 280 with the 266.

20
00:01:55,090 --> 00:01:55,660
There's another one here.

21
00:01:55,660 --> 00:01:59,620
So there's a bunch of potentially working drivers here.

22
00:02:00,040 --> 00:02:04,930
There's no sure way to know which one is actually going to work, because some of these, for example,

23
00:02:04,930 --> 00:02:09,390
may have been written in the past for previous versions of the marker Python firmware.

24
00:02:09,640 --> 00:02:12,580
They may not be working perfectly for your current setup.

25
00:02:12,820 --> 00:02:17,670
So it's a matter of just trying out some of those and figure out which one eventually works.

26
00:02:18,130 --> 00:02:26,240
In my case, I found that this one works perfectly with my setup, with my SB 32, and I believe that

27
00:02:26,260 --> 00:02:29,020
it is this one here, perhaps.

28
00:02:30,270 --> 00:02:30,860
That chick.

29
00:02:31,720 --> 00:02:32,820
Now that.

30
00:02:37,390 --> 00:02:38,790
Not this one either.

31
00:02:39,230 --> 00:02:41,260
It's by Robert 8H.

32
00:02:45,120 --> 00:02:46,390
Like this one here.

33
00:02:46,680 --> 00:02:55,170
So the name here does not really indicate the author or the source, but as a matter of trial and error,

34
00:02:55,170 --> 00:02:57,440
eventually you will find the one that works for you.

35
00:02:57,960 --> 00:03:06,660
So once you have access to the source code of the driver that you want to use, the process includes

36
00:03:06,870 --> 00:03:09,660
taking a copy of the driver.

37
00:03:09,690 --> 00:03:15,810
So in my case, I have determined that a lot of trial and error that being made to 80 underscore float

38
00:03:15,810 --> 00:03:16,270
dot p..

39
00:03:16,290 --> 00:03:18,270
Why is the driver that works?

40
00:03:18,690 --> 00:03:24,870
You want to go and copy the raw version of this driver?

41
00:03:25,910 --> 00:03:27,770
Just copy the whole text.

42
00:03:29,750 --> 00:03:33,980
Then you can go and create a new file.

43
00:03:34,030 --> 00:03:35,750
Anthony Paiste.

44
00:03:37,080 --> 00:03:37,890
The code in.

45
00:03:40,040 --> 00:03:44,850
Then go ahead and save it on the device.

46
00:03:44,870 --> 00:03:51,290
In my case, I've already got the source code saved under this file name here, so I won't do it again.

47
00:03:51,500 --> 00:03:57,650
But you type in the phone in the file name is important because you will use this file name to import

48
00:03:58,010 --> 00:04:00,500
the library into your script.

49
00:04:01,130 --> 00:04:15,240
He'd cancel here and get rid of that a new tab and you'll see that this driver is stored on my Microplace

50
00:04:15,310 --> 00:04:15,860
device.

51
00:04:15,860 --> 00:04:22,100
My guess 32 under this file name, he can take a little bit of time to have a look around, become familiar

52
00:04:22,100 --> 00:04:24,620
with the features of this source code.

53
00:04:24,830 --> 00:04:30,010
An interesting variable here is the address and the default address of the sensor.

54
00:04:30,230 --> 00:04:33,890
It is 76 in most cases that is going to work.

55
00:04:33,890 --> 00:04:40,280
It is going to work with my sensor because I haven't shorted any of the pads here in order to change

56
00:04:40,280 --> 00:04:41,600
the default address.

57
00:04:41,610 --> 00:04:44,510
So I'm going to go with the one that is configured here.

58
00:04:44,530 --> 00:04:47,030
I can see the operating modes.

59
00:04:47,570 --> 00:04:53,540
So how many samples do you want to take in order to improve the accuracy of the readings further down?

60
00:04:53,540 --> 00:05:00,260
Using the name of the class will be using that later in our input statement, you know, script, you

61
00:05:00,260 --> 00:05:02,450
can see the constructor here as well.

62
00:05:03,350 --> 00:05:05,870
So the parameters for the constructor and so on.

63
00:05:06,710 --> 00:05:11,210
So there's also a few functions that you may want to use a bit later.

64
00:05:11,210 --> 00:05:18,260
There's a few ways by which you can extract the environmental data from the sensor and you can learn

65
00:05:18,260 --> 00:05:22,730
all that, not through the documentation, even if it does exist in this case.

66
00:05:23,510 --> 00:05:25,730
Go back to the root of this repository.

67
00:05:25,730 --> 00:05:30,860
You'll see that there is a little bit of documentation and it's telling you how to use the driver.

68
00:05:31,100 --> 00:05:34,160
But if it doesn't, you can always go and have a look at the source code.

69
00:05:34,160 --> 00:05:38,120
Python is very often self explanatory, so you can do that.

70
00:05:39,020 --> 00:05:42,290
So become familiar with the driver.

71
00:05:43,500 --> 00:05:46,890
And then go ahead and construct your own sketch.

72
00:05:47,160 --> 00:05:51,900
I have some information here about my setup, which you can copy.

73
00:05:52,650 --> 00:05:58,630
The most important thing to remember here is a type of R-squared, see that we are using.

74
00:05:58,890 --> 00:06:02,430
So I'm actually going to remove this because it's not totally true.

75
00:06:02,430 --> 00:06:04,730
And I'm going to explain what I mean by that.

76
00:06:05,320 --> 00:06:14,310
Notice that the E.S.P 32 has a hardware R-squared interface, and this is something that, of course,

77
00:06:14,310 --> 00:06:19,080
you can use with your sensor or with any other squishy device that you want.

78
00:06:19,440 --> 00:06:28,470
But the micro python firmware has an ice quixey implementation that allows you to also use software

79
00:06:28,620 --> 00:06:29,670
ICE see.

80
00:06:29,940 --> 00:06:30,920
So let's have a look at it.

81
00:06:30,930 --> 00:06:36,620
And I've got a link to this page here in my header right here.

82
00:06:38,230 --> 00:06:44,950
Right, so go and have a look at this, the ice could see implementation in micropayment for the SB

83
00:06:44,950 --> 00:06:53,790
32 allows you to use either a hardware ice creates the interface or a software ice Quixey interface

84
00:06:54,250 --> 00:07:03,250
in our example and be using soft ice quazi, which allows me to nominate any to SEAL and Steet.

85
00:07:03,550 --> 00:07:11,470
And those will work perfectly well with my current high squidgy device to be in the sensor in later

86
00:07:11,470 --> 00:07:16,610
lectures, in particular in the lectures on display at an OLED display.

87
00:07:16,610 --> 00:07:21,560
So I'll be using the hardware interface just to get a little bit better and more consistent performance

88
00:07:21,560 --> 00:07:25,120
that students will be using a higher speed device.

89
00:07:25,120 --> 00:07:25,980
The display.

90
00:07:26,320 --> 00:07:31,030
But here I want to show you how you can go about using soft ice Quixey instead.

91
00:07:31,030 --> 00:07:38,890
I squit see in my script I've used the Jupiter for for the FDA.

92
00:07:38,890 --> 00:07:45,220
They've a pin and then you're twenty two for the clock and.

93
00:07:46,380 --> 00:07:54,500
It just looks like this this is how you can create the ice Quixey object by calling the soft I swear

94
00:07:54,510 --> 00:08:03,620
to see constructor, they pass the two tipoffs for clock in data and the frequency doesn't really matter.

95
00:08:03,670 --> 00:08:07,170
You can go for a variety of frequencies and it will still work.

96
00:08:07,770 --> 00:08:10,410
So here I'm going for four hundred kilohertz.

97
00:08:12,440 --> 00:08:21,770
OK, the next thing that I'm doing here in line 35 is to import the driver to remember that the name

98
00:08:21,770 --> 00:08:27,320
for the driver is being made two hundred and eighty underscore float, which is you can see right here,

99
00:08:27,620 --> 00:08:33,910
you import this module by using the file name, excluding the dot p y extension.

100
00:08:34,370 --> 00:08:41,170
So that's how you imported that, because this is quite an extensive name to be using it in our code.

101
00:08:41,420 --> 00:08:47,190
I rename it by using the S keyword as PMA two hundred and eighty.

102
00:08:47,510 --> 00:08:55,010
So from that point on, which I'll be able to use the code inside the driver by using the BMY 280 dot

103
00:08:55,010 --> 00:08:57,620
notation instead of this whole thing.

104
00:08:58,600 --> 00:08:58,800
Right.

105
00:08:58,870 --> 00:09:00,920
So if I had just said import this.

106
00:09:02,050 --> 00:09:09,190
Without doing the renaming here, I would have to use this notation to make reference to code inside

107
00:09:09,280 --> 00:09:10,060
the driver code.

108
00:09:11,080 --> 00:09:11,710
All right.

109
00:09:12,810 --> 00:09:22,350
Let's go back to the original and another thing to notice here is that because this line is quite long,

110
00:09:22,350 --> 00:09:29,240
if I make if I really arrange the parameters one next to each other.

111
00:09:29,550 --> 00:09:33,990
You said that it takes a lot of space horizontally in Python.

112
00:09:33,990 --> 00:09:41,700
You can split lines like this so that you've got one parameter per line just makes everything fit a

113
00:09:41,700 --> 00:09:42,400
little bit better.

114
00:09:43,140 --> 00:09:48,450
So I'm using the square see object that I created in line 37.

115
00:09:48,630 --> 00:09:55,020
And then I'm also setting the mood in the address, again, using the constants that I have found in

116
00:09:55,020 --> 00:09:56,310
the drive itself.

117
00:09:56,760 --> 00:09:59,070
So here are the operating modes.

118
00:09:59,070 --> 00:10:05,880
Constants are usually eight bit here or the eight sample shown in the sample option.

119
00:10:06,000 --> 00:10:09,300
And then for the address I am using the default.

120
00:10:09,300 --> 00:10:10,320
The trees are clear.

121
00:10:11,520 --> 00:10:18,150
If your eyes could see device is quite a different address, then of course you can adjust that to the

122
00:10:18,150 --> 00:10:19,400
appropriate correct address.

123
00:10:19,920 --> 00:10:23,140
These two parameters just point to defaults anywhere.

124
00:10:23,160 --> 00:10:31,020
So instead of this whole thing could have just said this and it would work just by passing the ice Quixey

125
00:10:31,650 --> 00:10:36,150
object and leaving the rest of the parameters to the default values.

126
00:10:39,410 --> 00:10:45,920
OK, that's about it with the set up, the rest of the code should be fairly familiar instead of using

127
00:10:45,920 --> 00:10:46,680
an infinite loop.

128
00:10:46,700 --> 00:10:53,670
I'm going to use a timer here and I'm taking one reading every 1000 milliseconds, every one second.

129
00:10:53,690 --> 00:11:02,050
And when the clock ticks, the hardware timer will call the sensor ESR function right here.

130
00:11:03,830 --> 00:11:07,180
There's a couple of ways by which you can grab data from the sensor.

131
00:11:07,490 --> 00:11:14,420
First is to call the values property on the object, on the B in the object, and that is going to print

132
00:11:14,420 --> 00:11:16,190
out all three values.

133
00:11:16,520 --> 00:11:19,850
Or you can be a bit more selective and you can pick one value at a time.

134
00:11:20,300 --> 00:11:26,510
So here's the temperature, here's the humidity, and here is the story.

135
00:11:26,540 --> 00:11:29,420
Here's a pressure and then here's the humidity.

136
00:11:29,900 --> 00:11:36,890
Now, one thing that I want to mention here is that this parameter of this variable, I should say,

137
00:11:37,100 --> 00:11:42,720
returns a python tuple so of good information about what that is.

138
00:11:42,740 --> 00:11:46,750
In case you're not familiar with tuples, but think of a table.

139
00:11:46,760 --> 00:11:54,480
There's an array, but in a regular array, each cell must contain data of the same data type.

140
00:11:54,500 --> 00:12:00,910
So you either have, for example, an array of integers or an array of strings, et cetera.

141
00:12:01,370 --> 00:12:06,270
A top off, on the other hand, can contain data of different types.

142
00:12:06,270 --> 00:12:15,940
So each cell in a couple can be a number, can be a string, can be another array.

143
00:12:15,950 --> 00:12:21,920
Even so, you can use the same notation as if this was an array.

144
00:12:22,190 --> 00:12:29,270
But the difference is that, as I said, it contains items of different types and unlike an array as

145
00:12:29,270 --> 00:12:29,450
well.

146
00:12:29,480 --> 00:12:32,680
Another difference is that a table is immutable.

147
00:12:32,690 --> 00:12:35,300
So once you set it, you can change its values.

148
00:12:35,870 --> 00:12:41,000
So if you're curious, just go to this location and read more about tabs.

149
00:12:42,650 --> 00:12:43,300
So this about it.

150
00:12:43,310 --> 00:12:46,340
Let's go ahead and try this program out.

151
00:12:46,340 --> 00:12:52,280
I've just saved it and I'm going to run it on the device and that's what comes out.

152
00:12:55,490 --> 00:12:57,480
Right, so you can see that.

153
00:12:59,000 --> 00:12:59,570
The.

154
00:13:01,040 --> 00:13:07,040
Print statement in line 45 returns this line.

155
00:13:07,610 --> 00:13:10,410
Can we stop the execution?

156
00:13:10,430 --> 00:13:14,540
I'm going to click on the stop button here, because this is not an infinite loop.

157
00:13:14,540 --> 00:13:15,380
It's a timer.

158
00:13:15,710 --> 00:13:17,450
So hitting control.

159
00:13:17,480 --> 00:13:18,830
See, it's just touch and go.

160
00:13:18,830 --> 00:13:25,190
If I hit control on the exact moment when this function is executing, then the program will stop.

161
00:13:25,190 --> 00:13:29,690
Otherwise it will not catch it at a moment where the problem is actually running.

162
00:13:31,250 --> 00:13:36,740
Anyway, so line forty five prints out this table, so that's what a table looks like, parentheses,

163
00:13:36,740 --> 00:13:38,930
and then he's got the items.

164
00:13:39,170 --> 00:13:42,640
This is item zero item on and item two.

165
00:13:43,280 --> 00:13:48,140
And if I want to print out the individual components of the tuple, the individual cells of the couple

166
00:13:48,140 --> 00:13:51,430
and the values, then I go with this array notation.

167
00:13:51,890 --> 00:13:53,960
So this should be a meat value zero.

168
00:13:54,230 --> 00:13:55,690
And it looks like this.

169
00:13:55,700 --> 00:13:57,760
It includes the C symbol as well.

170
00:13:58,780 --> 00:14:06,280
He's a pressure for being sworn in the humidity with the percentage sign for used to.

171
00:14:07,990 --> 00:14:15,100
OK, now, if you're curious as well, have a look at the driver, could you expand this window a little,

172
00:14:16,340 --> 00:14:17,020
you know?

173
00:14:18,160 --> 00:14:19,540
So I am calling.

174
00:14:20,660 --> 00:14:24,980
The values function search for values in here.

175
00:14:27,630 --> 00:14:33,850
So the values function is in line two hundred and forty, and that's what comes back to the caller.

176
00:14:34,230 --> 00:14:38,220
So you can modify this, of course, if you don't want the symbols to appear.

177
00:14:38,700 --> 00:14:45,540
You can just remove them in the source code of the driver, but you can modify the couple that is returned

178
00:14:45,540 --> 00:14:49,010
by just making the appropriate change in 1955.
