Raspberry Pi Project: Touch Weather Station using a DHT22 and a Raspberry Pi 3 with TKInter GUI.

Raspberry Pi Project: Touch Weather Station using a DHT22 and a Raspberry Pi 3 with TKInter GUI.


Dear friends welcome back! The summer is over and I am back with a new
project. Today we are going to test the new Raspberry
Pi 3 board, by building a simple but useful project. We are going to build a Touch Screen Weather
Station. Let’s start. A few months back, the Raspberry Pi 3 board
was released. It is a great new board because it now offers
WiFi and Bluetooth connectivity out of the box! It uses a quad core processor which operates
at 1.2Ghz and it has 1GB of RAM available. From the benchmarks I have seen, this board
is at least 3 times faster than the original Raspberry Pi. It can run Linux and offers 40 GPIO pins for
our projects. The impressive thing is its price. It costs around 40$ and Gearbest.com was kind
enough to send me a sample unit in order to test it and build projects with it. You can find a link for it in the description
of the video. In order to test it, I built this Weather
Station with it. As you can see, I have connected a 5’ inch
touch display and a DHT22 sensor and in the screen we can see live update of the temperature
and humidity. The temperature and the humidity values are
updated every two seconds. If I click anywhere on the screen, the applications
quits so we can use the Raspberry Pi for other purposes. This project is a nice first project to build
with a Raspberry Pi, because you will learn how write and run code on it, and you will
learn how to use the GPIO pins of it. But let’s now see how to build this project. The parts needed in order to build this project
are these: • A Raspberry Pi 3 or any other Raspberry
Pi board • A DHT22 Temperature and humidity sensor
• A 5” Touch Display • Some wires
You can find link for all the parts in the description of the video. Now, let’s connect all the parts together. First we have to connect the DHT22 sensor. We connect the pin with + symbol to GPIO pin
40 of the Raspberry Pi. Although Pin 40 is not connected to 3.3V we
will configure it to be HIGH in the code later. We connect the GROUND pin of the sensor to
GPIO pin 39. Lastly we connect the output pin of the sensor
to digital pin 38. The next step is to attach the display. It is very easy. You can also watch a detailed tutorial I have
prepared about this display by clicking on the card here. That’s it, now we can power up the Raspberry
Pi and load the code. Now that the Raspberry Pi is ready to use
download the code of the project from the link in the description of the video and place
it in a folder named WeatherStation. Along with the code you will find a file named
background.gif which is the background image for our project. Next we have to install a couple of libraries. First of all we have to download the DHT22
sensor library from adafruit. Unzip the library on the desktop, open the
Console and type the following 2 commands. sudo apt-get update
sudo apt-get install build-essential python-dev Next, run the commands
cd Desktop/Adafruit_Python_DHT-master to navigate to the library folder and then install the
library with this command. sudo python setup.py install
That’s it. The DHT library is ready to use. The next step is to install an imaging library. Type the following 2 commands and wait the
installation procedure to complete. After that we are ready to use the code. Navigate to the project folder with the command:
cd Desktop/WeatherStation Then just run the code with the command:
sudo python WeatherStation.py The program will run and after a few seconds
the temperature and the humidity readings will appear. You can exit the application by clicking anywhere
on the screen if you have installed the drivers for the touch display. Let’s now take a quick look at the code
to see how it works. The code uses the TKinter Graphical User Interface
package. We have used it in the past as well and I
have prepared a video on that, you can check it out by clicking on the card here. Watching that video will help you better understand
what’s going on here. At first we declare all the libraries that
we are going to use. Next we define the GPIO pin 40 as an output
and we set it to HIGH in order to provide power to the DHT22 sensor. Next we create a full screen image background
by loading the image file from the WeatherStation folder. After this, we create two text labels for
the temperature and the humidity. With this command we bind the click on the
screen or the mouse click with the exit function which exits the application. With this command we call the function readSensor
after two seconds. Note that the command is executed in a separate
thread in order not to lock the User Interface. The read sensor function calls itself every
two seconds. It reads temperature and humidity from the
sensor and updates the labels on the display. As you can see with a few lines of code, we
can build very impressive projects using the Raspberry Pi 3 board. The fact that the board now offers WiFi connectivity
out of the box, makes things more interesting. We can improve this project by adding online
data logging to it, and weather forecast using openweathermap API for example. We can also use different background images
depending on the weather conditions and so on. I will work more on the project soon, so stay
tuned. I would love to hear your opinion about this
project. How do you want to see it evolve? Please post your comments or ideas in the
comments section below. Thanks! If this is your first time here, I would love
to have you subscribed. In this channel I post videos about DIY projects
every Saturday. I love making things and I believe that anyone
can make things, anyone can become a maker. That’s why I created this channel, in order
to share my knowledge with the community and learn from the community. I hope you will join us. Until next Saturday, Watch, Learn, Build! [ Translating these subtitles? Add your name here! ]