med. This time were 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 were going to be using the board with a bme 280 sensor to make a wireless weather station so lets go and get started. So here we have the new raspberry, pi, pico, w and ill. Also bring in an original pico for comparison there we are, and both of these boards are based on raspberry pis, 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, weve already got some headers connected to this board, which is why its slightly taller, men, as the name suggests, the raspberry pi pico, w also has a wireless module, and this contains an infineon cyw434chip 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, Som, as im sure youd 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 lets 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. Imidlertid, here were 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 weve got micro, python, uf2 files for both the original pico here and also for the pico w, which is the one were going to download. And if i click on this file to download it youll see in fact ive 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: theyre 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 theres 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 its a nightly build so theres, nothing wrong with the file we have downloaded anyway. Thats all sorted out. Its now got the file available its 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 lets open up this tin and we find inside weve got an appropriate cable as well as some headers which well 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 its been recognized down here, lets open up another window like that and well 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 itll 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 were going to use is going to be sony which you can obtain from the sony website over here, sony.

org its available for windows, mac and linux. But here were in windows where ive 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 were now working on the raspberry pi pico lets, 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 im 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 were 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 its the tiny little thing down here. This said, although im using this particular board, there are lots of different versions of this available, for example theres 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 im going to do is to solder on these headers to allow the picot to be mounted on a breadboard so lets 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. Næste, we need to wire things up with two jumper cables, connecting the bme 280 til 3.3 volt power and the ground rail. There were then two further cables linking the sensors serial clock line or scl and serial data line or sda to gp1 and gp0 respectively. In order to communicate with the sensor were going to configure this pair of pins to provide access to on the picos 2, i squared c interfaces and talking of which, its now time to delve into the wonderful world of code greetings here. I am back again in thony, connected to the pico, where ive written a small program, som du kan se, and im going to save this on the pico by going to a file and to a save and were going to save onto the picot itself and were 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 well take a look at this code. Ill 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 well, go to tools and manage packages here in sony and well type bme280 and search for it over here and there we are.

The library we want is the one down here: mikro, python, bme, 280., godt, click on that and we will install there. We are going across the pico. All done so now. Lets take a look at the code which will in part use that library and, som du kan se, 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, som du kan se, 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, som du kan se, we read from the sensor and we read from it three variables: temperature pressure and humidity by taking bme dot values, Nul, 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 its got temperature, then the temperature variable humidity, humidity, etc. If we scroll across it finishes off with pressure as you can see, og derefter, 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 didnt 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 lets see if this works so well go to run like that under run the current script and it looks like it works there. We are lets just uh get some more space on the stream. We can see that its 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 wouldnt 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 thats, what were 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. Først, i want to make it clear: i cant possibly cover everything in this code in detail in the rest of this video, because theres 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, ill. Give you a link to this in the video description. But this said well 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 itll work there so ill 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 its connected and then returns the ip address its been given. Theres 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, Som, 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, som du kan se, 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, Endelig, 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 thats the theory but im sure you want to know if it works so well give ourselves a bit of space down in the console Down thereand 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. Itll do it. If we talk nicely to it there, we are its connected at 192.168.106., so we go across to a web browser and we go to that ip address 192.168.106., its remembered it from previously in my tests and there we areit still amazes me, but it works were 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 its updating every 10 seconds were getting revised measurements.

So we can stay fully up to date. With temperature, humidity and pressure, this said right now: weve got the pico connected to our desktop pc, so thats not terribly exciting. So what im 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 dont worry ive brought a computer with me. The raspberry pi pico w running from a usb power bank, som du kan se, and i presume the board has booted upi cant tell ishould have implemented an led, really shouldnt. I better never mind. I didnt so well assume its running. Okay and well go back inside, and here i am reunited with the desktop pc. We dont 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 its remembered it down there and yes, its working, i shouldnt be so surprised. Should i but there we are weve, got the pie pico outside all by itself running on a battery and sending us temperature humidity and pressure readings. Im pleased with that thats a good result, i cant 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.