DIY IoT Weather Station: Full Project - ESP32 BME280 MicroPython - Temperature Pressure Humidity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys a couple of weeks ago i was watching a video by melinda carr which is someone i really like on youtube she does a lot of construction stuff but she was doing a video on mushrooms or mycelium which is really the roots of mushrooms and how they were being used to con they can essentially grow construction materials packing materials things like that with mycelium you should watch the video i'll link it down below it is made up of two ingredients mushrooms and hemp pretty cool but it has to be in a really temperature and humidity controlled area or the way that they grow these things and that got me thinking and reminded me of someone that was asking me about making a uh using the esp32 and the bme 280 to make uh something to monitor his humidor but it was too complicated for so he went another route but then i was just thinking hey you know with all the stuff that we've done in the last year or so we could put all that stuff together and come up with a whole iot project so it's going to be based around this amazing little thing right here actually this is a carrier board you can't even see the thing that's on there okay it's the bme 280 which will measure temperature pressure and humidity so we can make our little weather station like we did before uh now don't confuse that with the other what is it the bmp 280 which won't measure humidity they have a little bit different shape so that this one make sure you know like if you're getting on ebay you want to get the one that's kind of this square rather than the rectangular one just to make sure you're getting the right stuff anyway so we're going to use that cool little device and i'm going to use hold on in my pocket in my pocket aha yes p 32 mini this is the v2 which is probably what i'll use i've been prototyping with the v1 but this is the v2 don't forget you can get these things on the store right they're pretty cool this is the smallest prototype board that's out there i think but anyway i'm going to use this and then i just was down i'm coming back from the shop and i made this little case right here with a little we can hang it up on something just made out some plexiglass so we're going to put all that stuff together that'll be the device and then we will connect this device what we'll make our measurements and then we'll send the data up to easy iot if you don't know about easy iot uh see the link below and go re you know watch the video on easy iot and then that will put the data in the cloud and then we'll the last thing we'll do is a little app that we can use to pull the data down i mean using the easy iot sdk but the development kit software development kit but we'll make a little app and we'll chart our stuff so this will be a whole um iot project from the device uh you know making the measurements pushing the data to the cloud up to easy iot and then being able to pull the data down and do something with it so it's a full iot project so let me get back up to the house and i'll start showing you all the things that we're going to do okay one thing i forgot to say is that this project is something that you can do you can get a bme 280 you can get an esp32 and you can use my software and get this thing running and then you can go from there and it doesn't have to be one of my esp32s it can be uh i mean you can i'm going to use a mini but you could use a fun board or you can use any generic esp-32 and then you can get this going you'll have yourself an iot project and then you can start modifying it from there make it do exactly what you want so this is a great place to start and you just gotta love spring this is uh my neighbor's dairy farm look how beautiful that is okay guys let me show you the device setup so this is what i've been programming or prototyping with okay so i've got an esp32 mini right here now you don't have to use um you know my stuff i mean you can use a fun board all right i got a lot of these left on the store uh you can also use one of these generic uh devices that you get off of ebay it doesn't come with a dude sitting on there but so you can use one of these one of these anything that will run python uh our micropython will will work just fine okay so that the setup is really easy so for me i don't have a usb connector on this like you do on on the on these things back here i'm trying not to bang the camera so i'm a little uncoordinated here all right these have usb but i don't have usb so this is my serial coming in data that's my return line this is the ground and then this is power coming in from my usb line usb to serial converter there okay so that's all that is so you know this we can just ignore this for now okay and then we got the device over here now let's take a look at this device all right so that is the bme the little can right there let's see if we can get i'm not gonna get it to focus and point at the same time oh there we go all right so that can right there that's the bme uh 280 and you'll notice that it is square okay so that's different from the bmp well anyway i don't even know where one is i had one oh it's in my pocket still all right so this is the one you want to watch out for on ebay do you see you see how that can right there it's kind of rectangular shaped right so you want to watch out for that on ebay because they'll tell you it's a bme but it won't be it'll be a b the bmp instead okay all right so this little guy this is the carrier board that comes with it it's the three volt carrier board you don't want the five volt carrier board you want the three volt carrier board all right and then you'll see that it has five connections all right so we've got the vcc ground uh the clock the data and then these last two are for spi all right they're the clock select i mean the chip select and the data out all right we're not doing that we're doing i2c instead so we're only going to use these four we need power we need ground power 3 volts we need ground we need clock and we need data that's the only four wires that we need okay so let me plug this baby back in there it is all right so that's what we have coming out of here right now here is our power here is our ground and that's our clock and that's our data now we're doing something a little bit special because sometimes these things can need to be reset they need a power reset so instead of going straight to the three volts or this is five but we could take three off of here if we wanted but instead of going right to there and going right to ground we're actually using some input output pins so we're using two input output pins and that way if this thing gets jacked up then we can turn the power off and do a full power on reset of this thing now the reason we can do that on these i o pins is because this thing uses no power all right so you can you can pull 30 milliamps off or yeah 30 milliamps off of these no problem but this is using like less than one or two or you know it's it's a tiny tiny amount so we don't have to worry about that all right so for in this case i think i've got hold on i'm gonna mess up the camera yeah i'm on um let's see i'm on 26 25 14 13. all right so this is 26 and 25. now those are your standard i2c communication pens on the esp32 for one of the i2c channels that's why we're using those and then this is on 14 and this is on 13. so you'll see in the software that one of the things that we do is turn these pins on so we they we change from inputs to outputs we set this one high and we set this one low and that turns this thing right here on and it allows us so something goes wrong and we recycle the whole thing then we shut the power off turn the power back on and we get this thing set up fresh again okay so that is the whole thing right there the bme connected with these four wires to these four pins and then your standard esp32 setup however however you accomplished that now if you're unfamiliar with the esp32 and programming it and micro python i got to get started video right so go check out that get started video i'll put a link down there i guess i'm gonna have a lot of links for this for this project okay all right that is the whole setup now when we're done i'm gonna use this and then i'm gonna use this and i'm gonna put this i don't know i'd even try to see if this thing will fit oh no oh yeah it'll fit all right just barely it'll fit in there so we're going to put that in there and then i'm going to recycle the one from ben's project this is the old bme 280 that we had from ben's project and we'll put that on look at this i already got some holes right here we'll glue this baby on there and that'll fit on there and then that'll be in there and i've got a little hole down here that we're going to run a power cord into that thing and then we're just going to hang this on the wall outside okay look at this last thing i was doing i broke i broke this thing last thing can you believe that that pissed me off i shouldn't say that i was really put out anyway that was the last thing but it's not going to affect it it's still going to be sealed up i can still use the nuts and screw it but anyway that stuff happens all right that is the total physical setup that we got so the next thing we're going to do is start looking at the software so let's go do that okay getting started now this is my get lip get lab directory and it is going to be exactly the same as if you went to clayton's pcb shop on gitlab right so this stuff that we're looking at right here is exactly the same as this so we're going into micro python and then we're going into weather stations there's ben's old weather station which we have retired and here's our new diy iot weather station all right now there's two parts of it the desktop part we'll get to in a minute that's just a way demoing how we could look at the data just an example and then this is what's going to happen what's happening on the esp32 that i'm using for prototyping this and the one that i'm going to put into the case okay all right so here we go now if you aren't oh you know what i i'd put that video of uh beaker's web server so that's what all that beeping is over there speakers web server beeping okay anyway um if you're not familiar with micro python then go and look at the video that i introduced you know how to put micropython on your esp32 and all that so check the links below in the description all right so here's what it takes to run this now it looks like a lot now of course replace that's just how we're going to load the stuff up there so that's not actually going on your device main is the script that does brings everything together now the other scripts that we're using are this one uh we're running it with i2c okay so this is just a little uh library that hooks up and does the i2c so we create this an i2c bus and that's what we use to connect to the bma280 okay now here is the bma e280 library and i will tell you right now it's a bit tedious so i have set it up see it says right there it's set up for weather mode now this is an amazing little chip i mean it can i use it for a drone and you can actually measure the distance by raising and lower it lowering it you know a half a meter you can detect that and the drone can you know know that it's changing altitude they're very sensitive but it's not set up that way this is set up for weather which is uh a lot simpler okay so there's a lot of stuff you can read all this stuff um but the main thing after we set it up we're just going to be calling the get data or we're not actually going to call that we're going to call this weather function so we have a weather function that gives you european weather if you want american weather you have to use the us function right so we we do our weather a little differently here we do inches of mercury instead of millibars and you know stuff like that okay so uh so we'll anyway this is a tedious library look at all this math this is for converting the raw values you know so there's all kind of stuff enjoy enjoy it if you if you want to look through there go for it but we won't worry about that now okay so that's the sensor bme and then the last thing we'll use is this easy iot and this is a special version of easy iot that is just for micropython it's a little bit smaller so we'll be using the post data and then later on in the desktop we'll be using the get data but that's all that we're going to do is post data and get data now if you're unfamiliar with easy iot it's just a simple application for you to write data to the web and get it back down again so there's a video for that i'll put the link below okay so those are the the supplemental programs or the extra programs the library that we're going to use the i2c bus to run the bme and then we're going to push it to easy iot and that's our cloud location all right so the thing that we need to know then is about maine and that's where we do all of the good stuff is right here in maine okay so when you pop open your main once you download this stuff then you're going to have to put in a wi-fi ess id and password so that the esp32 can connect to your wi-fi location all right and then you should have a key and a secret that you'll get from easy iot i'm using the example key in secret so everybody can take a look at it and then you have to say you know what group and what device you're going to use for easy iot because it you know the fields on easy iot are a group device and then you got your four data fields right so we're just going gonna say this is the weather group and clayton one so when we look at the data uh you know like let me see if we can we can look at the data right quick um yeah so if we look at some easy iot data this is where we see that i've been posting uh stuff up there right so uh that is the group and that is the device and then i'm putting three pieces of data i'm not putting any anything in the last piece of data okay so in maine you want to go ahead and put your it doesn't matter what it is i mean there's limitations you'll you'll see when you work with the easy iot and watch the easy iot video there's limitations to length but you put that stuff in there okay now we are using the i2c the clock is on 25 pin 25 and the data is on pin 26 and this is the frequency that we're running at [Music] now you can change this if you like but these this is the uh one of the hardware i2c channels so that's why we're using it now the bme remember i was saying that we had a positive and negative pin that we're actually using so the negative pin is pin 13 the positive pin is pin 14. if you use different pins make sure they're output pins and then you can change these numbers to match the bme address by default is 118 on on the i2c bus there's another option but you know don't you're probably not going to use that okay set your local altitude when you are talking about barometric pressure you have to adjust it to your altitude above sea level okay so this is in meters so this is me i'm roughly 222 meters above sea level okay um bme weather i'm doing it in us right because i want it in inches of mercury instead of millibars and i want it in fahrenheit instead of celsius but if you're not in the united states you're probably going to want to set this to false okay all right those are the variables that you have to set and then we just go in to the program itself okay so here's our basic imports these are micropython imports these are libraries so here's our i2c bus library here's our bme library and here's our easy iot mini library okay and then we have one main loop right here okay uh let's see okay so we have this big loop you know this is our main function we have this big loop and it has a catch down here and if it messes up then it sleeps for 10 seconds and tries to do it again so that would be on a major error and the reason what that does is it it's going to reset up the wi-fi reset up easy iot it's going to cycle the bme 280s power and set up the i2c bus again and then go into the to the inner loop or the minor loop okay so that's our major loop and our our catch is here so if anything goes wrong it goes through and starts everything up correctly okay so here's what happens we set up the wi-fi so easy iot does a scan it prints out all the available wi-fi and then it uses your wi-fi and you know your ess id and password to set it up so it's this stuff right here okay and it connects to your network the next thing we do is we set the easy iot key in secret you should be using your own if you use the example one that's okay but everybody's going to be using the example one i use the example one for example stuff and it'll just get pushed out of there really quick so your data is not gonna last very long if you're using your own then you can you know have up to 10 24 1024 lines of data in there at a time okay all right now here's where we're cycling the power on the bme 280 so we're making both those pins inputs which turns them off we give it a little bit of time to stabilize and then we're making the pens outputs and this pin we make it negative and this pin we make it positive and that turns it on and then we sleep a little bit to give it time for everything to stabilize so that is our hard re you know hard reset on the bme 280. all right then we're gonna set up the i2c bus just using the variables that we have up up here uh these these variables right there so that sets up the i2c bus uh we do it i i'm i have it you don't have to do this but it does a scan and we'll print out the address right and tell you how many devices it found on the i2c bus should only be one right because we only just have one on there all right and then we set up the bme so we tell it what the bus is or we give it the bus that we've already instantiated we tell it uh what address we're working on and we give it our altitude so that it can calculate stuff correctly and we don't need to do this zero feature that's for if you're using it for drones and stuff like that okay so now at this point everything is set up and now we go into a secondary loop where we're reading the data pushing it to easy iot going to sleep for a while okay so i've got it printing a bunch of stuff just so we can see it but what we're you know we're counting how many loops we've done uh now this is where we get the data from the bme 280 and this is something that the way we have it set up you got to call this and it wakes up the bme280 it makes it do a conversion get the data ready and then after we do that then we can read the data so if you set it up for weather or for us then it's going to use this function and if you haven't then it's going to use this and it'll turn you return it in metric units then it'll print that data and then it will just with this one line it's posting it up to easy iot so it's uh you know using the group and all that and we're doing temperature pressure and humidity as the first three pieces of data okay and then we are printing that yeah we pushed it up there to easy iot and then in this case we're sleeping for 10 minutes okay because you don't need to update your weather constantly if you do it too much you'll get booted off easy iot but but let's say for demo we'll we'll go to every four seconds instead of 10 minutes so i'll i'll just mod this just for a minute okay so we modded that um and that's it that's all that we're doing so we're waking up the device reading the data posting to easy iot and then waiting for a while now if you're on super low power you might want to put in a deep sleep here but for demonstration i'm not i'm not bothering with that okay and there's our catch things and and that's it okay so uh i guess we should well let's just okay so i'm doing a control c i'm in pico com connected to my device so i'm going to do a control ax and that gets us out of there and then we're going to use okay so we're using the replays program this is our port i'm on uh linux so i'm in dev tty usb2 and what we're gonna do is instead of these things that i have that i was doing specifically we're gonna do an a and that's just gonna load everything up on there okay so we're loading all of our programs now remember we changed this you shouldn't be doing it every four seconds but that that's what we changed to okay now if so this stuff doesn't look familiar to you like using picocom and these other things there's other ways that you can do it but if you check out my intro video to our tutorial for the esp32 then this will all become familiar all right so i'm using picocon to connect to my device all right we're ready and i'm going to do a control d which is a is a hard reboot and let's just see what happens all right so it booted and not really okay so we already did it all right so let's look at what's happening so we loaded main we loaded i2c bus we loaded the bme 280. uh this is easy iot and then we're printing out all the networks that are around here and then we're connecting to our network and then yes i have a special network for testing that's called your essid clever isn't it all right anyway so then it's checking the i2c and it says yep there's 118 and that's the default address on the i2c bus for the bme 280. they all have that as their default okay and then we're checking it checks out the bme is online the bma is ready and then here's our loops so loop one here's the data that we got we loaded it to iot and we sleep for 10 minutes not really we're only for set four seconds and then we're we're going back so this is the temperature of course this is sitting on my desk so it's in indoor temperature um but here's uh the temperature this is barometric pressure it's been like that for days now um and then here is the relative humidity which that's that's pretty low for here um so there we go all right so now we're going through our loops and that's about it this thing is up and running so really all you got to do now is get it in a case and you know you got to have the bme on the outside of the case and other parts on the inside of the case and then put it in a place where you can have power all right so that is pretty much it for the uh for the esp32 side so let's run over to the desktop and see what's happening there all right before we look at data we gotta make some real data okay so here's the case turned out okay if i hadn't broke it but everything else turned out okay okay there's the bme 280 inside there this piece was from ben's old weather station and then here's the esp mini in there and i just have a usb power thing there i'm gonna plug it in right here just so we can collect some data so i'm gonna hang it up right here my wife will not like that but this is for science so all right let's see plug it in green light comes on all right we should get a blue here in a second after it okay now we're connected to the internet we're getting data going okay it sent it to easy iot and then it should start flashing yeah now it's in its sleep cycle okay so we're gonna let this collect data for a little while then we'll look at it now we've had about well almost 24 hours minus a few because i didn't get this thing started till after dark but we've had about 24 hours of this thing going so let's go and look at some data on easy iot okay now we're going to do the desktop part which is the it's kind of the third part of the project okay so we started out by putting our device together prototyping it getting it programmed get everything working the way that we wanted to and then we put it in a case we put it outside we started collecting real data and pushing that data up to the cloud and the last thing that we want to do is actually use that data so we're going to pull it down or we're going to look at it we're going to pull it down we'll put a little plot but i mean there's whatever you want to do with it we'll put it in a little plot and that'll be the third part of the project so this is the this is a whole iot project from prototyping getting it running putting data up in the cloud bringing data down okay so let's get into the desktop apps now these are really simplified and to start out with i'll let me just delete these right quick we'll make new ones in just a second all right so these are just some simplified apps to kind of show you what's going on now this is easy iot uh this is the sdk that comes with easy iot and it's got all the functions that we need for you know posting data watching our data grow reading our data getting our data and that's what we use to interact with iot or easy iot whether we're on the desktop or whether we're on the esp32 either way okay we can use this library and then this is a little uh charting library that i've been fooling around trying to write and it makes charts and sp uses svg to make charts and i was going to add it to the to the esp32 server but i haven't gotten it going yet i mean it works but i'm not all the way done with it so anyway we're just going to use that as a little plotter to draw some charts okay and then our main thing is this right here which is just our little weather plot well first thing why don't we just um from the command line we can start python now this is not uh micro python this is you know real python and then we'll import easy iot and then we can just do for a simple way to do it is just get well we can get data we'll do that let's see if i can remember we'll get uh i don't know let's get 10 lines of data and we're just getting oh okay let me see gave it to us all at once we just need to do this there we go okay so uh these were the last lines of data so you can see that the only person that's using the example account which is what happens when you don't sign in and give it credentials is me right now and the new device we call it clayton ii clayton one was the prototype the one that's actually outside is clayton ii and it's been posting data for almost 24 hours so we'll be able to look at some nice charts but this is the data that's up there and we're just pulling it down so this is exactly what we'll do in the chart script here in just a minute okay so let's get out of python there and let's open up the little chart script that i have right here so this is nothing fancy i'm just demonstrating what can be done so here's our imports web browser will just throw the charts up into a web browser start them in a web browser so we're mainly we're importing easy iot and we're importing microchart now for easy iot we have to put in our credentials in this case we're using example as the example account and let's see we need to put in our group because what we really want to do is select i don't want to select you know maybe i'm putting up data for a lot of devices and different groups and it's all going up there and i don't i want to just select a certain type of data not just everything like we did here so we'll specify to use the group weather and clayton 2. all right and then here's just the name of the file that we'll create okay so what are we doing we're setting our key in secret right here and then right here we are getting our data we're telling it to get 1024 or basically as many much as you can and we're telling it that this is the group we should use the one we set right here and this is the device that we should use the one we set right here okay and then we're getting the data we're sorting the data and then uh we're going let's go we'll just print it you don't really need to do that but we can print it just so we can see it and then we'll tell how many rows it is and then here's where we're going through a format we're splitting it up into temperature data pressure data humidity data and we're making some labels that we want to use in our chart and then this is where we make the plot give it our titles and all that sort of thing and then we'll tell it to open in the web browser and then pressure data doesn't change a lot so in order to see it actually changing i went ahead and made a second plot just using the pressure data right there okay and then we'll open that in the web browser as well and that's it okay that's all that this thing does so it's just it's going to easy iot it's collecting our most recent data and it's going to make a chart out of it so i'm just going to run this and there it goes all right let's let's get back here for a second and see what it did so this is the this is the data this is the stuff that pulled down said it pulled 128 rows i might have a limit on the example account of how many rows you can pull but anyway pulled 128 rows and then it plotted it so let's uh let's take a look so we'll start here all right so this is in gmt day in the hour so this was this was last night when i put the thing out outside so you can see it was already late you know getting into the evening and the temperature was already down to 55 that's fahrenheit okay so the temperature was down pre the relative humidity was up because when your temperature goes down relative humidity goes up all right and then uh during the day it went up and got you know over wow i didn't realize i got that hot okay so it got it's kind of a nice balmy spring day there you know in the high 70s all right and of course as it heats up the temp the relative humidity goes down and then we've dropped back down so we're we're around 60 degrees outside right now and of course the humidity is up now this green line is the the pressure and you see you can't compared to these others you can't see it changing so i plotted it by itself and then here's the change so this was you know i was kind of up and then down and back up today i don't i don't understand pressure exactly but uh in terms of how it works with the weather but that's it okay so this is uh this is what iot does this is what it's for it's for collecting data and sending it to the cloud now there's there's one piece of iot that we didn't cover and that would be going in the opposite direction like sending a command out but if you read the easy iot instructions uh in gitlab then you will see how to do that as well so that's it that is our iot project all together [Music] mushrooms and hemp
Info
Channel: Clayton Darwin
Views: 2,591
Rating: undefined out of 5
Keywords: DIY, Homemade, esp32, bme280, micropython, python, iot
Id: 7pfe67Cnxo0
Channel Id: undefined
Length: 41min 1sec (2461 seconds)
Published: Tue Apr 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.