Raspberry Pi and BMP280

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi my name is sian and i'll show you how to make a first step into creating your own smart home we will be using a temperature sensor to check the room temperature i'll introduce you to raspberry pi cover up the basics of using it and we will write a simple python program that will communicate with the temperature sensor if you want to work with me and finish up the whole project you will need a raspberry pi with all the accessories such as power adapter and microsd card a breadboard 4 jumper wires of type male female bmp 280 sensor and of course a laptop or pc to do all the coding and just a quick note before we begin under this link you can find a written version of this video and all the source code as well so now let's get into it raspberry pi a computer about the size of a credit card with a price tag as low as five dollars first unit was brought to the public in 2012 and now it is one of the best selling microcomputers in the world even though it is so tiny it still is quite powerful the most recent model has a quad-core cpu and up to 8 gigabits of ram its use scale is huge you can use it for many interesting projects starting from iot prototypes robots automating various things security smart home even hi-fi audio system all the way to machine learning and ai as a web server or even as a retro gaming console raspberry pi consists of a bunch of little chips and connectors the most important are cpu ram wi-fi and bluetooth module micro sd card slot ethernet connection along with 4 usb ports audio jack 2 micro hdmi ports and finally a gpio connector that you can use to control electric circuits and communicate with other electronic devices unlike arduino raspberry pi has a general purpose operating system that is installed on the microsd card that i mentioned earlier raspbian alongside with other linux distributions is the most commonly used operating system for raspberry pi but you can use windows iot core as well and how about programming the gpio controller that i mentioned earlier that is easy because the most common programming languages like python java c-sharp c c or even javascript have libraries for that now that you have at least a brief understanding of raspberry pi we can start with the project first of all we need to connect the temperature sensor to the raspberry pi for that we could use either the i square c or the spi protocol now how these two work that is quite complicated and definitely far behind the scope of this video so i won't explain it now and i will just tell you that we are going to use the i square c protocol and that will take care of all the data transferring between sensor and the raspberry pi the wiring itself is quite simple we need just four cables for that the first one red provides 3.3 volts that power the sensor data between raspberry pi and sensor are exchanged through that blue cable orange cable is for clock that we use to synchronize both devices and finally black cable is ground the three remaining unused pins on the temperature sensor are for spi protocol which is the other protocol that i mentioned earlier so pause the video connect the wires exactly the same as the diagram shows and also pay attention not to have the raspberry pi upside down that means that the ethernet and usb ports must be on the bottom otherwise wires would be connected wrong [Music] so now i'll show you how to install an operating system without even having to use an external monitor so put the micro sd card into your computer open up a browser of your choice and follow my steps head over to the raspberrypi.org website click on software here select the appropriate download link to download the raspberry pi imager that is an application that will make the whole installing process much easier optionally if you are on linux you can use the package manager as well now just a quick note you will probably see me using linux most of the time but no worries the process is the same on all platforms if there are going to be any differences in the process i'll let you know now open up the newly installed software choose raspberry pi os lite here select the microsd card where you want to install the operating system click on write and just wait for it to install and there is one last thing before we finish the installation open a boot partition and create an empty file without an extension named ssh and that's it now remove the microsd card from your computer and we can head over to the next step in order to communicate with the raspberry pi we need to connect to its terminal terminal is an interface between us the user and the computer a place where you can write text commands that are then executed directly on the layer of operating system so we are going to use the computers terminal to connect to the raspberry pi's terminal using a utility called ssh in order to do that both devices have to be on the same local network also we have to determine the raspberry pi's ip address to let the ssh know where it should connect the process of determining the ip address is different for everyone so i won't be explaining it but you can check out this link for great guide now the connection itself if you are using linux or mac os the system terminal will do just fine but if you are on windows you have to install a software called pewdie but for now let's just open up the terminal simply type ssh the hostname of target device that is pi in our case and the target ip address that you determined in the previous step here select yes to add the host to the list of trusted hosts now type in raspberry which is the default password now we are connected to raspberry pi's terminal before we can start programming we need to set up a few things starting with the system update to update the system type in studio update and that will search if there are any packages that need upgrade and as you can see there are 30 packages ready to be upgraded so type sudo upgrade with flag y to upgrade them and that will take some time when it's ready we can continue with making sure the ice crc interface is enabled and that is necessary in order to communicate with the temperature sensor so type in sudo raspy config and here using the keyboard arrows select interface options i square c and here yes to enable the ice crc interface now we can close the dialog by highlighting the finish option using tap the application that we are about to write for the temperature sensor is going to be done using the python programming language and that is because python has a lot of easy to use libraries that will make the whole process significantly easier also if you're not a programmer python is in my opinion the best programming language a beginner could pick so to check if you have python installed simply type python3 followed by dash version and if you get a result similar to mine that means that you have python 3 installed why python 3 you might ask well that is because there are two major versions of python python 2 and python 3. nowadays python 2 is pretty much deprecated but for some reason it is set as a default version in raspbian so we have to type python3 to force the system to use python version 3. as i said a while ago we are going to use a library that provides an easy way to communicate with the temperature sensor to use this library we need to install it first type in sudo apt install python 3 pip to install pip which is a package manager a utility for installing libraries for python you can verify the installation by typing pip3 followed by version now we can use pip to install the library for our temperature sensor finally we can start programming so make sure you're in a home directory by typing cd tilde cd stands for change directory and tilde is a shorthand to your home folder we can start off by creating a new folder called vault and that is where our source code is going to be so mkdirvault mkdir stands for make directory and move into that folder by typing cdvault here create a new python file called sensor.pi using the touch command and open that file with nano which is a simple terminal based text editor the programming is going to be really simple so have no worries first we have to import these libraries board takes care of the gpio pins bus io takes care of the communication that is happening on the ice square c line between raspberry pi and the temperature sensor and finally adafruit bmp-280 is a special library for the temperature sensor next we need to initialize the iscsi interface and create a controller for the temperature sensor and give it the i square c that we initialized on the line above and that's it really now we can create an infinite loop read the temperature and pause the loop for two seconds so that the temperature is refreshed every 2 seconds don't forget to import the time library and the programming is done it wasn't so hard was it exit nano by pressing ctrl x y to save changes and enter to exit now we can test the application as you can see everything works perfectly only in my opinion the measurement is unreasonably accurate which means there is a lot of decimal places and i don't really like it that way to fix that first stop the code execution by pressing ctrl c open up nano again save the temperature to a variable round it to two decimal places repeat the same exit process as last time and test the application once again as you can tell everything just works i even tried blowing at it with a heat gun and see the temperature is raising which proves the sensor to be working and that's it from my side today thank you for your attention i hope you enjoyed and maybe some of you will get your hands on raspberry pi and give the project a try in the next part i will help you with adding some features to improve the user experience and overall usability of our little project and that way teach you how to use code from github and create system services on linux in the meantime stay safe cheers [Music]
Info
Channel: Jan Hendrych
Views: 5,068
Rating: undefined out of 5
Keywords:
Id: apV93MXHwkA
Channel Id: undefined
Length: 13min 19sec (799 seconds)
Published: Mon Apr 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.