But in this lecture, I show you how to use the permit 280 with your E.S.P, 32 using micro python.
Now, unlike in the previous lecture, we are to learn how to use the DHT 22 using a driver that comes
with the micro python firmware.
The two hundred and eighty does not have an integrated driver, which means that you need to go out
to find one that works with your set up and then imported into your S.P.C.A. stored in the flash memory
so that your script can use it.
So this is the main difference between the approach that we used in the previous lecture with the 22
and the one that we use now with the BMY 280 is that we're going to use a third party micro python driver
for this sensor.
In most cases, this is the approach that you have to take with pretty much any other peripheral to
your ESP 32.
You'll have to use Google or some other search engine to look for an available driver for the device
that you want to use.
In my case, I find that awesome micro python dot com contains an excellent list of drivers or libraries
for Macra Python.
Not all of them work in my experience.
But you've got a good chance that whatever hardware you want to use, you will find a micro python driver
in this list, in particular for the BMY 280, he could look for sensors and say around.
Here you'll find that the BMY 280 has a few options, so there's 280 this 180 as a 280 with the 266.
There's another one here.
So there's a bunch of potentially working drivers here.
There's no sure way to know which one is actually going to work, because some of these, for example,
may have been written in the past for previous versions of the marker Python firmware.
They may not be working perfectly for your current setup.
So it's a matter of just trying out some of those and figure out which one eventually works.
In my case, I found that this one works perfectly with my setup, with my SB 32, and I believe that
it is this one here, perhaps.
That chick.
Now that.
Not this one either.
It's by Robert 8H.
Like this one here.
So the name here does not really indicate the author or the source, but as a matter of trial and error,
eventually you will find the one that works for you.
So once you have access to the source code of the driver that you want to use, the process includes
taking a copy of the driver.
So in my case, I have determined that a lot of trial and error that being made to 80 underscore float
dot p..
Why is the driver that works?
You want to go and copy the raw version of this driver?
Just copy the whole text.
Then you can go and create a new file.
Anthony Paiste.
The code in.
Then go ahead and save it on the device.
In my case, I've already got the source code saved under this file name here, so I won't do it again.
But you type in the phone in the file name is important because you will use this file name to import
the library into your script.
He'd cancel here and get rid of that a new tab and you'll see that this driver is stored on my Microplace
device.
My guess 32 under this file name, he can take a little bit of time to have a look around, become familiar
with the features of this source code.
An interesting variable here is the address and the default address of the sensor.
It is 76 in most cases that is going to work.
It is going to work with my sensor because I haven't shorted any of the pads here in order to change
the default address.
So I'm going to go with the one that is configured here.
I can see the operating modes.
So how many samples do you want to take in order to improve the accuracy of the readings further down?
Using the name of the class will be using that later in our input statement, you know, script, you
can see the constructor here as well.
So the parameters for the constructor and so on.
So there's also a few functions that you may want to use a bit later.
There's a few ways by which you can extract the environmental data from the sensor and you can learn
all that, not through the documentation, even if it does exist in this case.
Go back to the root of this repository.
You'll see that there is a little bit of documentation and it's telling you how to use the driver.
But if it doesn't, you can always go and have a look at the source code.
Python is very often self explanatory, so you can do that.
So become familiar with the driver.
And then go ahead and construct your own sketch.
I have some information here about my setup, which you can copy.
The most important thing to remember here is a type of R-squared, see that we are using.
So I'm actually going to remove this because it's not totally true.
And I'm going to explain what I mean by that.
Notice that the E.S.P 32 has a hardware R-squared interface, and this is something that, of course,
you can use with your sensor or with any other squishy device that you want.
But the micro python firmware has an ice quixey implementation that allows you to also use software
ICE see.
So let's have a look at it.
And I've got a link to this page here in my header right here.
Right, so go and have a look at this, the ice could see implementation in micropayment for the SB
32 allows you to use either a hardware ice creates the interface or a software ice Quixey interface
in our example and be using soft ice quazi, which allows me to nominate any to SEAL and Steet.
And those will work perfectly well with my current high squidgy device to be in the sensor in later
lectures, in particular in the lectures on display at an OLED display.
So I'll be using the hardware interface just to get a little bit better and more consistent performance
that students will be using a higher speed device.
The display.
But here I want to show you how you can go about using soft ice Quixey instead.
I squit see in my script I've used the Jupiter for for the FDA.
They've a pin and then you're twenty two for the clock and.
It just looks like this this is how you can create the ice Quixey object by calling the soft I swear
to see constructor, they pass the two tipoffs for clock in data and the frequency doesn't really matter.
You can go for a variety of frequencies and it will still work.
So here I'm going for four hundred kilohertz.
OK, the next thing that I'm doing here in line 35 is to import the driver to remember that the name
for the driver is being made two hundred and eighty underscore float, which is you can see right here,
you import this module by using the file name, excluding the dot p y extension.
So that's how you imported that, because this is quite an extensive name to be using it in our code.
I rename it by using the S keyword as PMA two hundred and eighty.
So from that point on, which I'll be able to use the code inside the driver by using the BMY 280 dot
notation instead of this whole thing.
Right.
So if I had just said import this.
Without doing the renaming here, I would have to use this notation to make reference to code inside
the driver code.
All right.
Let's go back to the original and another thing to notice here is that because this line is quite long,
if I make if I really arrange the parameters one next to each other.
You said that it takes a lot of space horizontally in Python.
You can split lines like this so that you've got one parameter per line just makes everything fit a
little bit better.
So I'm using the square see object that I created in line 37.
And then I'm also setting the mood in the address, again, using the constants that I have found in
the drive itself.
So here are the operating modes.
Constants are usually eight bit here or the eight sample shown in the sample option.
And then for the address I am using the default.
The trees are clear.
If your eyes could see device is quite a different address, then of course you can adjust that to the
appropriate correct address.
These two parameters just point to defaults anywhere.
So instead of this whole thing could have just said this and it would work just by passing the ice Quixey
object and leaving the rest of the parameters to the default values.
OK, that's about it with the set up, the rest of the code should be fairly familiar instead of using
an infinite loop.
I'm going to use a timer here and I'm taking one reading every 1000 milliseconds, every one second.
And when the clock ticks, the hardware timer will call the sensor ESR function right here.
There's a couple of ways by which you can grab data from the sensor.
First is to call the values property on the object, on the B in the object, and that is going to print
out all three values.
Or you can be a bit more selective and you can pick one value at a time.
So here's the temperature, here's the humidity, and here is the story.
Here's a pressure and then here's the humidity.
Now, one thing that I want to mention here is that this parameter of this variable, I should say,
returns a python tuple so of good information about what that is.
In case you're not familiar with tuples, but think of a table.
There's an array, but in a regular array, each cell must contain data of the same data type.
So you either have, for example, an array of integers or an array of strings, et cetera.
A top off, on the other hand, can contain data of different types.
So each cell in a couple can be a number, can be a string, can be another array.
Even so, you can use the same notation as if this was an array.
But the difference is that, as I said, it contains items of different types and unlike an array as
well.
Another difference is that a table is immutable.
So once you set it, you can change its values.
So if you're curious, just go to this location and read more about tabs.
So this about it.
Let's go ahead and try this program out.
I've just saved it and I'm going to run it on the device and that's what comes out.
Right, so you can see that.
The.
Print statement in line 45 returns this line.
Can we stop the execution?
I'm going to click on the stop button here, because this is not an infinite loop.
It's a timer.
So hitting control.
See, it's just touch and go.
If I hit control on the exact moment when this function is executing, then the program will stop.
Otherwise it will not catch it at a moment where the problem is actually running.
Anyway, so line forty five prints out this table, so that's what a table looks like, parentheses,
and then he's got the items.
This is item zero item on and item two.
And if I want to print out the individual components of the tuple, the individual cells of the couple
and the values, then I go with this array notation.
So this should be a meat value zero.
And it looks like this.
It includes the C symbol as well.
He's a pressure for being sworn in the humidity with the percentage sign for used to.
OK, now, if you're curious as well, have a look at the driver, could you expand this window a little,
you know?
So I am calling.
The values function search for values in here.
So the values function is in line two hundred and forty, and that's what comes back to the caller.
So you can modify this, of course, if you don't want the symbols to appear.
You can just remove them in the source code of the driver, but you can modify the couple that is returned
by just making the appropriate change in 1955.