Raspberry Pi Pico W: Wireless Weather Station

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome to another video from explainingcomputers.com this time we're going to take a look at this the raspberry pi pico w microcontroller this was released at the end of june 2022 and in this video we're going to be using the board with a bme 280 sensor to make a wireless weather station so let's go and get started so here we have the new raspberry pi pico w and i'll also bring in an original pico for comparison there we are and both of these boards are based on raspberry pi's own rp2040 microcontroller chip which has a dual core arm cortex m0 plus processor that can be clocked up to 133 megahertz as well as 264 kilobytes of ram both boards also have two megabytes of onboard flash storage a micro usb 1.1 connector that can be used to power the board and for programming the flash and they also have 40 pads for gpio connectivity where on the original pico we've already got some headers connected to this board which is why it's slightly taller however as the name suggests the raspberry pi pico w also has a wireless module and this contains an infineon cyw43439 chip that offers 2.4 gigahertz 80211ny54 as well as bluetooth 5.2 adding this extra component has inevitably increased the price with the pico w costing six dollars compared to four dollars for the original pico raspberry pi have also launched a pico h with pre-soldered headers that sells for five dollars as well as a pico wh for seven dollars which as i'm sure you'd guess has both pre-soldered headers and the wireless module so there we are we now have a raspberry pi pico with onboard wi-fi and bluetooth so let's now get this board up and running a raspberry pi pico can be programmed in many different languages including c plus plus micro python and even basic as i illustrated in my last pi picot video however here we're going to be using micro python which we need to install on the board to do this we need to download an appropriate usb flashing format or uf2 file and we can get this from the raspberry pi website where the documentation for the pico is absolutely fantastic anyway what we want right now is the uf2 files if we scroll down here you will find we've got micro python uf2 files for both the original pico here and also for the pico w which is the one we're going to download and if i click on this file to download it you'll see in fact i've downloaded it already and when i did so i noticed that the file name here includes the word unstable which made me slightly nervous so what i did after that was to go across to the micro python website where you can also get hold of the same file for the picow scroll down here and we can see all the different nightly builds and all of these files we look at the bottom of the screen here they're all labeled as unstable and i searched around a bit and found this post on the raspberry pi website in the forums and this talks about this issue and there's a very helpful contribution here which explains that until we get version 1.2 of a micro python the file is going to be labeled as unstable because it's a nightly build so there's nothing wrong with the file we have downloaded anyway that's all sorted out it's now got the file available it's sitting here on the folder on my desktop and we need to get this across to the pico w and when i purchased my picow i also bought this kit of goodies to go with it so let's open up this tin and we find inside we've got an appropriate cable as well as some headers which we'll be using later in the video but for now we need to take the cable and plug this uh micro usb connector into the pico like that and then we need to hold down the boot select switch like this and to take the other end of the cable there it is and to plug this into our computer and as we can see it's been recognized down here let's open up another window like that and we'll open up the pico and we can now take the uf2 file over there copy the file and paste it across to the pico like this there we go it'll go across very exciting always fun to be using usb 1.1 connection and there we are it has finished and now the drive will disappear because the pico has been programmed with that file and what we now need to do is to open up a program which we can use to access the pico and the program we're going to use is going to be sony which you can obtain from the sony website over here sony.org it's available for windows mac and linux but here we're in windows where i've already installed and run up sony over here and we look at the bottom right corner we see it currently says python 3.79 but if we click down here we can now select the raspberry pi pico because it is plugged in there we are and oh look we're now working on the raspberry pi pico let's give ourselves a bit more space down there and if we want to we can test things are working we can execute a python command which of course will have to be print hello like that because what else would we do and there we are we printed a low everything seems to be working and so what i'm now going to do is to close this down to disconnect the pico and return to the hardware side of our project right in addition to the pico w we're going to use a bosch bme 280 sensor to read temperature pressure and humidity this particular board with a bme 280 sensor on it is from pymeroni it costs 13 pounds 80 and if we flick it over we can see the bme 280 it's the tiny little thing down here this said although i'm using this particular board there are lots of different versions of this available for example there's one from adafruit for 14.95 and if we wanted to we could just connect four wires directly from this board to the pico to make a very very compact unit but i expect to use this raspberry pi picow in lots of different projects and so what i'm going to do is to solder on these headers to allow the picot to be mounted on a breadboard so let's get on with that molten metal operation here we go and with a whisp or two of drifting flux our picow has gained two headers and can now be inserted into a little breadboard next we need to wire things up with two jumper cables connecting the bme-280 to 3.3 volt power and the ground rail there were then two further cables linking the sensor's serial clock line or scl and serial data line or sda to gp1 and gp0 respectively in order to communicate with the sensor we're going to configure this pair of pins to provide access to on the picos 2 i squared c interfaces and talking of which it's now time to delve into the wonderful world of code greetings here i am back again in thony connected to the pico where i've written a small program as you can see and i'm going to save this on the pico by going to a file and to a save and we're going to save onto the picot itself and we're going to call it main dot pi because main.pi is the name you give a file if you wanted to auto run on the picker and in a second we'll take a look at this code i'll show you what it does but before we do that before we can execute this code before we can use it we need to install the library for the bme 280 sensor on the pico and to do that we'll go to tools and manage packages here in sony and we'll type bme280 and search for it over here and there we are the library we want is the one down here micro python bme 280. we'll click on that and we will install there we are going across the pico all done so now let's take a look at the code which will in part use that library and as you can see it starts out by importing some modules it imports pin and i squared c so we can use those in the code it imports sleep and it imports bme to 80. and then we initialize i squared c as you can see using the pins i talked about earlier gp0 and gp1 and we set a frequency for communication and then after that we have an infinite loop while true will always be true where as you can see we read from the sensor and we read from it three variables temperature pressure and humidity by taking bme dot values zero one and two which give us temperature pressure and humidity and then i put all of these values together in a string which has got some labels so it's got temperature then the temperature variable humidity humidity etc if we scroll across it finishes off with pressure as you can see and then if we come back down here we then print out reading and then wait for 10 seconds and the loop continues and i would note i could have done this in a more efficient manner i didn't have to define three variables and add them down here i could have put the b and b values parts here directly into this definition of the reading but i thought it was easier to see what was going on by defining the values first and the reason i put everything into one string will become clear in the next segment of the video anyway for now let's see if this works so we'll go to run like that under run the current script and it looks like it works there we are let's just uh get some more space on the stream we can see that it's given us one reading as we can see and once 10 seconds has gone by there we are we have a second reading which is uh almost exactly the same and this will continue but wouldn't it be even better if rather than putting the data here on the console with the pico connected to the pc if the data was instead transmitted by the pico over wi-fi so we could access it in a web browser and guess what that's what we're now going to do right here i am back with some revised code and just before i go through it i want to make a couple of points firstly i want to make it clear i can't possibly cover everything in this code in detail in the rest of this video because there's a lot of big concepts involved in getting the pi picow connected to a wi-fi network and serving an html page and linked to that i want to make it clear that my code here draws heavily on code from the raspberry pi foundation particularly code they develop in this tutorial here very good tutorial about connecting your pi pico w to a wireless network and interacting with it and of course i'll give you a link to this in the video description but this said we'll come back to the code here and say a few things it does start as last time by importing modules here including network and socket and then it defines ssid and password the details required to connect to a wi-fi network which of course will be unique to a particular network and then it initializes i squared c as previously this bit of code should probably be lower down here but it'll work there so i'll leave it where it is we then define various functions first of all the function to connect to the wireless network this has got little loop in it as it tries to connect we know that connecting to a wi-fi network is never instantaneous so it keeps on trying until it's connected and then returns the ip address it's been given there's then another function for opening a socket using that ip address and then another function for a web page and this function takes a value which is reading which you might remember is the string we set up in the last piece of code to amalgamate the readings from the sensor and what this basically does is to have a basic piece of html here which defines document type opens html has a head as you can see with in particular this critical piece of code in to force the page to refresh every 10 seconds and then in the body of the html we just got one paragraph which includes the content in our reading string we then have further down an even bigger function defined this goes through an infinite loop and it basically reads the sensor as previously and then serves the web page and then finally all this basically is setting things up defining things at the bottom of the code the picow is told to connect to the network and report its ip to open the socket and to serve the web page so that's the theory but i'm sure you want to know if it works so we'll give ourselves a bit of space down in the console down there and we will run this code like this and there we are and first of all the pico will try and connect to a network where it says waiting for connection go on find a connection it'll do it if we talk nicely to it there we are it's connected at 192.168.106. so we go across to a web browser and we go to that ip address 192.168.106. it's remembered it from previously in my tests and there we are it still amazes me but it works we're actually transmitting data wirelessly from the pico serving it as a web page and picking it up on another computer on the network and as we can see every now and then it's updating every 10 seconds we're getting revised measurements so we can stay fully up to date with temperature humidity and pressure this said right now we've got the pico connected to our desktop pc so that's not terribly exciting so what i'm now going to do is to disconnect the pico from the pc connect it to a usb power bank so it can boot up the main.pi code totally independently guess what i am now outside but don't worry i've brought a computer with me the raspberry pi pico w running from a usb power bank as you can see and i presume the board has booted up i can't tell i should have implemented an led really shouldn't i better never mind i didn't so we'll assume it's running okay and we'll go back inside and here i am reunited with the desktop pc we don't have sony running this time of course no need for that we can go straight to the web browser and put in the right address 192168 and it wants to be oh look it's remembered it down there and yes it's working i shouldn't be so surprised should i but there we are we've got the pie pico outside all by itself running on a battery and sending us temperature humidity and pressure readings i'm pleased with that that's a good result i can't think of anything else to say so it must now be time to bring this video to a close the pico w is a fantastic addition to the raspberry pi family and presents us with all kinds of opportunities for making our own iot our own internet of things devices and i also plan on using the board in a future video to control a robot over wi-fi but now that's it for another video if you've enjoyed what you've seen here please press that like button if you haven't subscribed please subscribe and i hope to talk to you again very soon [Music] you
Info
Channel: ExplainingComputers
Views: 224,963
Rating: undefined out of 5
Keywords: Raspberry Pi Pico W, Pi Pico W, Pico W, Raspberry Pi microcontroller, Pico weather station, WiFi weather station, Raspberry Pi Pico WiFi, Pi Pico WiFi, Christopher Barnatt, Barnatt, BME280, BME 280, Pi Pico BME280, Pi Pico BME 280
Id: 3q807OdvtH0
Channel Id: undefined
Length: 17min 13sec (1033 seconds)
Published: Sun Aug 14 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.