Raspberry Pi Weather Station

ExplainingComputers
3 Jan 202121:42

Summary

TLDRThis video tutorial demonstrates how to transform a Raspberry Pi into a functional weather station using a Bosch BME 280 sensor. The host guides viewers through the process of setting up the sensor, installing necessary libraries, and writing Python code to collect temperature, pressure, and humidity data. The video also addresses common issues like sensor inaccuracies due to heat from the Raspberry Pi and shows how to record and analyze the collected data over time using LibreOffice Calc, with the ultimate goal of monitoring and potentially predicting weather patterns.

Takeaways

  • πŸ˜€ The video is about converting a Raspberry Pi into a weather station using a Bosch BME 280 sensor.
  • πŸ› οΈ The sensor hardware is mounted on a breakout board from Pimoroni and costs Β£12.60.
  • πŸ” The BME 280 sensor provides temperature, pressure, and humidity sensing and is supported by a Python library and sample code.
  • πŸ”— Links to the data sheet and GitHub repository for the sensor are provided for further information and examples.
  • πŸ”§ Wiring the sensor to a Raspberry Pi involves soldering female right-angle headers or using jumper leads to extend the sensor away from the Pi.
  • πŸ“¦ The video mentions an alternative BME 280 module from Adafruit with different wiring but the same implementation and operation.
  • πŸ”„ To enable sensor access on Raspberry Pi OS, the IΒ²C serial communications interface must be enabled and specific libraries installed via terminal commands.
  • πŸ’» The sample code provided by Pimoroni is used to read and display sensor data, with initial issues resolved by discarding the first incorrect reading.
  • 🌑️ The video discusses a common issue with sensor temperature readings being skewed due to heat from the Raspberry Pi's system on a chip, and how to mitigate it.
  • πŸ“ The video demonstrates how to modify the code to record weather data over time using LibreOffice Calc and append readings to a spreadsheet.
  • πŸ”’ Enabling SSH on the Raspberry Pi allows for remote access and execution of the weather data collection script from a laptop or other devices.

Q & A

  • What is the purpose of the video?

    -The purpose of the video is to demonstrate how to turn a Raspberry Pi into a weather station using a temperature, pressure, and humidity sensor.

  • Which sensor is used in the video to create the weather station?

    -The sensor used is based on the Bosch BME 280, mounted on a breakout board from Pymironi.

  • What is the cost of the sensor hardware mentioned in the video?

    -The sensor hardware, which includes the sensor and two 5-pin headers, is priced at 12 pounds 60.

  • What is the physical size of the BME 280 component?

    -The BME 280 component is very small, approximately 2.5 millimeters square.

  • What is provided on the board's webpage to support the sensor?

    -The board's webpage provides a Python library for the board, sample code, and a link to the data sheet for the BME 280 module from Bosch.

  • Is there an alternative module for the BME 280 sensor?

    -Yes, a slightly different module for the BME 280 sensor is available from Adafruit for 14.95, which would require slightly different wiring.

  • How is the sensor connected to the Raspberry Pi in the video?

    -The sensor is soldered with a female right-angle header directly onto the sensor board and then connected to the Raspberry Pi's GPIO pins.

  • What Raspberry Pi model is used in the video?

    -A Raspberry Pi 3 Model B Plus is used in the video, but any model of Raspberry Pi can be used for the weather station project.

  • What command is used in the video to install necessary libraries for the BME 280 module?

    -The command used is 'sudo pip install' to install the primary BME 280 module library and the SMBus library.

  • What issue occurs with the first reading from the sensor?

    -The first reading from the sensor is often incorrect, which the video suggests is due to the sensor warming up.

  • How is the incorrect temperature reading issue resolved in the video?

    -The issue is resolved by separating the sensor from the GPIO connectors to prevent the Raspberry Pi's system on a chip from warming the sensor and giving incorrect readings.

  • How is the Raspberry Pi set up to be accessed remotely in the video?

    -SSH is enabled on the Raspberry Pi, and the default password is changed for security. The video also demonstrates using an SSH client like PuTTY to access the Pi remotely.

  • What software is used in the video to create a spreadsheet for recording weather data?

    -LibreOffice Calc is used to create and manipulate the spreadsheet for recording weather data.

  • How frequently are the weather data readings taken in the final setup of the video?

    -The weather data readings are taken every 10 minutes in the final setup.

  • What is the final outcome of the experiment shown in the video?

    -The final outcome is that the Raspberry Pi successfully collects real weather data, which can be used to monitor and potentially predict weather conditions.

Outlines

00:00

🌑️ Setting Up a Raspberry Pi Weather Station

The video begins with the host introducing a project to convert a Raspberry Pi into a weather station using a temperature, pressure, and humidity sensor based on the Bosch BME 280. The sensor is mounted on a breakout board from Pymeroni, which is priced at 12 pounds, 60. The host demonstrates how to unpack the sensor, highlighting its small size and the availability of a Python library and sample code on GitHub for data acquisition. The target devices for the sensor include a variety of consumer electronics and home weather stations. The host also compares the Pymeroni board with an alternative from Adafruit and explains the wiring process for attaching the sensor to a Raspberry Pi, emphasizing the importance of positioning the sensor away from heat sources for accurate readings.

05:00

πŸ”§ Initial Testing and Code Adjustments

The host proceeds with the initial setup and testing of the sensor using sample code provided by Pymeroni. After installing necessary libraries and enabling the I2C interface on the Raspberry Pi, the host runs the sample code and observes the sensor readings. However, the first reading is inaccurate, which the host attributes to the sensor's proximity to the Raspberry Pi's warm system on a chip. To resolve this, the host decides to separate the sensor from the Raspberry Pi using jumper leads. After making this adjustment, the sensor provides accurate temperature and humidity readings, while the pressure readings are consistent with an external weather site, validating the sensor's functionality.

10:00

πŸ“ Executing Code Remotely and Setting Up SSH

The host moves on to make the code executable from the terminal and set up the Raspberry Pi for remote access via SSH. After enabling SSH and changing the default password for security, the host demonstrates how to remotely log in to the Raspberry Pi using an SSH client like PuTTY. Once logged in, the host executes the sensor-reading script remotely and observes the updated temperature, pressure, and humidity readings, which now reflect the outdoor conditions in a garage. This setup allows for the potential of having multiple Raspberry Pis reporting weather data remotely.

15:01

πŸ“Š Recording and Analyzing Weather Data

The host then focuses on recording the weather data over time using LibreOffice Calc. The script is modified to include date and time stamps along with the sensor readings, and these are appended to a spreadsheet. The host shows how to install the 'openpyxl' library to manipulate the spreadsheet within Python. The script is tested, and the data is successfully recorded in the spreadsheet. The host also discusses the importance of saving the spreadsheet regularly. The video demonstrates how to retrieve and analyze the collected data, highlighting the utility of the spreadsheet for monitoring and potentially predicting weather trends.

20:02

🌦️ Collecting Real-World Weather Data

In the final segment, the host places the Raspberry Pi with the sensor outdoors to collect real-world weather data. After several hours, the host reviews the collected data in a spreadsheet, observing trends such as a drop in temperature and an increase in humidity, which suggests impending rain. The host reflects on the success of the project, having used the Raspberry Pi to gather authentic weather data. The video concludes with the host contemplating future projects, such as attempting to control the weather with a Raspberry Pi, and ends with a call to action for likes and subscriptions.

Mindmap

Keywords

πŸ’‘Temperature Pressure and Humidity Sensor

This refers to a device that can measure and provide data on the temperature, atmospheric pressure, and humidity levels of the environment. In the video's context, it is used to turn a Raspberry Pi into a weather station, highlighting its role in gathering environmental data crucial for weather monitoring.

πŸ’‘Bosch BME 280

The Bosch BME 280 is a specific type of sensor module capable of measuring temperature, pressure, and humidity. It is the core component of the sensor hardware discussed in the video, mounted on a breakout board, and is central to the project of creating a DIY weather station.

πŸ’‘Breakout Board

A breakout board is a printed circuit board (PCB) that facilitates the connection of an integrated circuit (IC) to a wider range of devices by breaking out the IC's pins into a more accessible format. In the script, the Bosch BME 280 is mounted on a breakout board from Pymironi, making it easier to interface with the Raspberry Pi.

πŸ’‘Raspberry Pi

The Raspberry Pi is a series of small, low-cost, single-board computers used for various applications, including as a platform for learning programming and for running small-scale servers. In the video, a Raspberry Pi is utilized to process and interpret data from the BME 280 sensor to function as a weather station.

πŸ’‘IΒ²C (Inter-Integrated Circuit)

IΒ²C is a multi-master, single-bus communication protocol used for attaching low-speed peripherals to a bus in short distance communications. In the video, enabling the IΒ²C interface on the Raspberry Pi is necessary to communicate with the BME 280 sensor module.

πŸ’‘Python Library

A Python library is a collection of modules that provide additional functionality to Python programs. In the context of the video, a Python library for the BME 280 sensor is mentioned, which is essential for interfacing with the sensor and retrieving data from it.

πŸ’‘Sample Code

Sample code is a piece of code provided as an example to illustrate how a particular programming task can be accomplished. The script discusses sample code provided by Pymironi for the BME 280 sensor, which is used to demonstrate how to read temperature, pressure, and humidity data.

πŸ’‘Data Sheet

A data sheet is a document that provides detailed information about a product, including specifications, capabilities, and how to use it. The Bosch BME 280 data sheet is mentioned in the script as a resource for learning more about the sensor's technical details and how to implement it in projects.

πŸ’‘SSH (Secure Shell)

SSH is a cryptographic network protocol for operating network services securely over an unsecured network. In the video, enabling SSH on the Raspberry Pi allows for remote access and control over the device, which is useful for running the weather station program without needing to be physically present.

πŸ’‘Spreadsheet

A spreadsheet is a computer application for data organization, often used for calculation, data analysis, and visualization. In the script, a spreadsheet application like LibreOffice Calc is used to record and organize the weather data collected by the Raspberry Pi over time.

πŸ’‘Remote Access

Remote access refers to the ability to connect to and control a computer from another location, typically over a network. The video describes setting up the Raspberry Pi for remote access so that the weather station can be monitored and controlled from the comfort of a warm indoor environment.

Highlights

Introduction of a project to turn a Raspberry Pi into a weather station using a Bosch BME 280 sensor.

The sensor is mounted on a breakout board from Pymeronic, priced at 12 pounds 60.

Unboxing the sensor hardware reveals the tiny BME 280 component and its support links, including a Python library.

Comparison with an alternative BME 280 module from Adafruit, priced differently and with different wiring.

Demonstration of soldering female right angle headers onto the sensor board for Raspberry Pi GPIO connection.

Instructions for enabling the I2C interface on Raspberry Pi OS for sensor communication.

Installation of necessary libraries for the BME 280 module using a terminal command.

Review of sample code provided by Pymeronic for initial sensor testing.

Observation of inaccurate initial sensor readings and the discovery that the first reading is often incorrect.

Identification of the issue with sensor temperature readings being affected by the heat of the Raspberry Pi's system on a chip.

Solution to the heat issue by separating the sensor from the Raspberry Pi using jumper leads.

Execution of the sensor reading code in the terminal and making it executable for remote access.

Enabling SSH on Raspberry Pi for remote access and changing the default password for security.

Demonstration of remotely accessing the Raspberry Pi using an SSH client like PuTTY.

Explanation of how to record weather data over time using LibreOffice Calc spreadsheet.

Modification of the code to append sensor readings to a spreadsheet for long-term data analysis.

Inclusion of a try-finally block in the code to ensure the spreadsheet is saved before exiting.

Testing the code to ensure it appends data to the spreadsheet correctly with a shortened wait time.

Real-world application of the Raspberry Pi weather station, collecting outdoor data and analyzing trends.

Future plans to possibly control the weather with a Raspberry Pi in upcoming videos.

Transcripts

play00:01

[Music]

play00:12

welcome to another video

play00:14

explaining computers

play00:17

this time i'm going to take this

play00:19

temperature pressure and humidity sensor

play00:21

and use it to turn a raspberry pi into a

play00:24

weather

play00:25

station so let's go

play00:28

and get started

play00:34

right let's take a closer look at our

play00:37

sensor hardware

play00:38

which is based on a bosch bme 280 which

play00:41

is mounted on a breakout board from

play00:43

pymeroni and this sells for 12 pounds

play00:46

60.

play00:48

so if we ask mr scissors to come in and

play00:50

snip

play00:51

the top of the packaging across like

play00:53

that i think that'll let us in

play00:55

like that when in theory we can now open

play00:57

up our little bag

play00:59

hopefully i got this right yes we have

play01:01

and we can take out

play01:03

what we have here which is the sensor

play01:06

and

play01:06

two five pin headers and

play01:09

we just turn the center around you can

play01:11

see the actual bme 280 component

play01:14

that provides temperature pressure and

play01:15

humidity sensing is the rounded metal

play01:18

box with a hole in it

play01:19

which is only about 2.5 millimeters

play01:21

square so

play01:22

it really is very tiny indeed

play01:26

if we look at the board's web page here

play01:28

on the primary website

play01:29

you can see they don't just sell the

play01:31

module they also support it well which

play01:32

is always

play01:33

great to see there's various links down

play01:35

here so for example there's a python

play01:37

library available

play01:38

for the board so we know we've got the

play01:40

libraries available to get data from the

play01:42

sensor that's clearly

play01:43

very significant and there's also some

play01:45

sample code

play01:46

they label it here a few nice little

play01:48

examples which is again great to see

play01:50

takes us across to github we'll have a

play01:51

look at some of this sample code in the

play01:53

next segment

play01:54

of the video and there's also a link

play01:57

here

play01:57

to the data sheet for the module from

play02:00

bosch so we can learn all about the bme

play02:02

280. i find it fantastic with this

play02:05

wonderful data sheet for this tiny

play02:06

little module

play02:07

always great to see things like that i

play02:09

like this type of stuff as you've

play02:10

probably gathered and if we go down here

play02:12

you can see the target devices for using

play02:14

this sensor

play02:14

are shown therefore that zoom in a bit

play02:16

on that which includes

play02:18

mobile phones and tablets and navigation

play02:21

systems

play02:21

and cameras and flying toys and watches

play02:24

and also home weather stations which is

play02:25

what we're using the sensor for

play02:27

here it's worth noting that a bme 280

play02:31

sensor

play02:32

is also available in a slightly

play02:33

different module from adafruit for

play02:36

14.95 as you can see so the wiring would

play02:39

be slightly different what i'm going to

play02:40

show you here because it's a different

play02:42

configuration of module

play02:43

but the implementation and operation of

play02:45

the project will be exactly the same

play02:47

using this adafruit

play02:48

component talking of wiring i'm going to

play02:52

solder the supplied

play02:53

female right angle header directly onto

play02:56

the sensor board

play02:57

which will allow us to attach it

play02:58

straight onto a raspberry pi's gpio pins

play03:01

one three five seven and nine with the

play03:03

sensor positioned away from the heat

play03:05

generated by the system on a chip but

play03:08

alternatively we could solder some

play03:10

jumper leads onto the module

play03:12

some leads like these and indeed we

play03:14

could use these like these to extend the

play03:16

center away from the pie

play03:17

if we need to do that in the future

play03:20

so i'll get on with some soldering which

play03:23

is always a great thing to try and show

play03:24

you

play03:25

on camera but here we are it seems to be

play03:27

working reasonably well

play03:28

anyway and with it complete we can now

play03:31

mount the sensor onto a raspberry pi

play03:34

and here i've chosen a raspberry pi 3

play03:37

model b

play03:38

plus which remains an absolutely classic

play03:40

piece of hardware

play03:41

a really nice pie but any model of

play03:43

raspberry pi can be used for this

play03:45

weather station

play03:46

project

play03:52

right i've now got the pi all connected

play03:55

up and running

play03:56

and here in raspberry pi os there's a

play03:58

couple of things we need to do

play04:00

to allow us to access the bme 218 module

play04:03

and the first of these is to enable the

play04:05

i squared c

play04:06

serial communications interface and we

play04:09

can do this by going to

play04:10

a menu here go to preferences we'll do

play04:12

it graphically via raspberry pi

play04:14

configuration and if it comes up there

play04:17

we are we go to interfaces

play04:19

i squared c is there we will enable that

play04:21

and click on

play04:22

ok secondly we need to go to a terminal

play04:26

which i've already opened up here and

play04:27

i've put in the command we need

play04:29

what this command does is to install a

play04:31

couple of libraries

play04:32

specifically the primary bme 280 module

play04:35

library and also a library called

play04:36

sm bus and if you're looking at this

play04:39

code and thinking what's going on

play04:40

it's doing a super user do to execute

play04:42

and install it's also got a pip in here

play04:44

and pip is a package management system

play04:47

for installing python software so that's

play04:48

why we've got sudo pip

play04:50

install rather than just sudo install

play04:52

anyway

play04:53

that's what we need to enter so i'll

play04:54

just execute that and hopefully

play04:56

things will happen and there we are

play05:00

that's all the

play05:01

install which is a pretty good and so

play05:03

now we can go to some sample code to try

play05:05

everything out so i'll

play05:07

close this down and i've got opened up

play05:09

the genie programmers editor here

play05:11

and here is the first piece of sample

play05:13

code provided by primarily caller

play05:15

all values pipe and what we can see here

play05:18

basically it imports

play05:19

some libraries it imports the time

play05:21

library it then imports some functions

play05:22

from sm bus

play05:24

and from the bme 280 library as well

play05:27

you can see it sort of hedges its bets

play05:28

here obviously doesn't know which

play05:29

version of sm bus we might have so it

play05:31

looks for

play05:32

one of two different versions of that

play05:34

particular module it needs

play05:35

and then it prints out what it's doing

play05:37

and then it goes down here to as you can

play05:39

see to initialize the sensor

play05:41

with that code there executes a while

play05:44

loop which is going

play05:45

on forever it's while true true is

play05:46

always true so this loop will go on

play05:48

indefinitely do we crash out of the

play05:49

program and it's going to get values for

play05:51

temperature pressure humidity

play05:53

by using a get command on the bmv 280

play05:55

and it's going to print them out with a

play05:57

bit of formatting in terms of the

play05:58

decimal places

play06:00

so this is very exciting i've not tried

play06:02

this already sometimes i've tried things

play06:03

in advance in a video i've not tried

play06:05

them here so let's run this code and see

play06:06

what happens

play06:10

and there we are we're reading data from

play06:13

our sensor

play06:14

although it seems to be a bit strange

play06:15

the first line of data looks about right

play06:17

certainly in terms of the temperature

play06:19

in this room and then after the first

play06:20

reading everything seems to got a bit of

play06:22

skew they're not quite sure what is

play06:24

going on

play06:24

but we are at least gathering data from

play06:27

the sensor

play06:28

looks like things can work so i think

play06:30

this gives us a good foundation

play06:31

for the rest of the project

play06:39

right here i am back again it's now the

play06:42

next day

play06:43

i've been doing some experimentation and

play06:45

also writing a slightly different

play06:46

version of

play06:47

the code and for start i've decided to

play06:50

tidy up the importing of libraries at

play06:51

the start of a code

play06:53

you might remember it did look like this

play06:54

where it checked to see whether it would

play06:56

use

play06:56

sm bus or some bus 2 from the smbus

play06:58

library i've discovered it's always sm

play07:00

but it's using so i thought we might as

play07:02

well tidy things up that just kept me

play07:04

rather happy having some slightly neater

play07:05

code

play07:07

i've also discovered that the first

play07:08

reading you get from the sensor is

play07:10

always

play07:10

wrong so what i'm doing here is getting

play07:13

some data from a sensor

play07:14

waiting for a second ignoring that

play07:16

entirely and then getting on with

play07:17

reading some actual data

play07:19

but when we do that let's run it up

play07:21

again we still have issues

play07:23

as yesterday here we've got our

play07:25

temperature our pressure

play07:27

and humidity and the pressure here looks

play07:30

to be about right

play07:31

i've checked that against a weather site

play07:33

i found in nottingham which suggests it

play07:34

should be about

play07:35

a 999 or which is at the location

play07:38

they're testing

play07:39

so the facts we're reading here are 995

play07:41

that suggest that's pretty good

play07:43

they suggest that the value for humidity

play07:46

is about 99

play07:47

it's raining most of the time we're not

play07:48

in today that's very different to what

play07:50

we're measuring here but here we're

play07:51

measuring at the moment

play07:53

internal humidity in a room that's

play07:55

warmed up in the winter so you get much

play07:57

much lower humidity over here

play08:01

this is a problem though this is a

play08:03

temperature of 30.85 degrees something

play08:05

like that in this room that's not true

play08:07

this rumor called a thermometer

play08:08

is about 21 degrees so this figure is

play08:11

way

play08:12

off and the reason for that i've worked

play08:15

out and also read about

play08:16

is if you think about it rather obvious

play08:18

it's because the sensor is plugged onto

play08:20

the raspberry pi

play08:21

and it's separated from the system on a

play08:22

chip but not by that much

play08:24

and the pi system on the chip is

play08:26

currently here running at what 48

play08:28

degrees and it therefore warms the air

play08:30

below the center and there's some

play08:31

conduction of heat

play08:32

around the board and up the gpio pins

play08:34

which also warms the sensor

play08:36

now there's two things we can do about

play08:38

this there's various stuff you can find

play08:40

online which actually

play08:41

is you're dealing with the issue using

play08:43

code here are the primarily bits of

play08:45

sample code there's one here called

play08:47

compensated temperature which builds on

play08:49

a review

play08:50

over here which is of the enviro hat

play08:52

which uses the same sensor

play08:54

another board from primarily a bit more

play08:56

sophisticated board

play08:57

and this basically deals with the issue

play08:59

by taking the pi's temperature

play09:01

and using a scale factor and working out

play09:03

what the actual temperature

play09:04

of the world around the sensor actually

play09:06

is we could do that

play09:08

but to be honest i think that's rather a

play09:10

daft better because you're never going

play09:11

to get the actual best temperature

play09:13

and so what i'm going to do is this

play09:16

yes as you can see we've now got the

play09:18

sensor on a jumper lead separated out

play09:20

from gpio connectors here

play09:22

so the system on a chip generating its

play09:24

warmth can't influence the sensor warm

play09:26

it up and give us incorrect

play09:28

readings and indeed if we look back to

play09:30

the raspberry pi's desktop and run the

play09:33

code

play09:34

we see accurate results the temperature

play09:36

now reflects the temperature on the

play09:37

thermometer

play09:38

in this room and the humidity results

play09:41

reflect what you'd normally expect to

play09:42

see

play09:43

in an inside room in the winter clearly

play09:45

that's gone up significantly

play09:47

because we don't have nervous system on

play09:48

a chip drying the air

play09:50

around the sensor

play09:57

now so far we've been executing the code

play10:00

here in the genie editor

play10:01

but it would be good if we could execute

play10:03

it in the terminal and also do so

play10:05

remotely so we'll close down genie and

play10:08

we'll open up a terminal

play10:10

and we'll do a list ls there to see

play10:11

where we are and we'll change to a

play10:14

python code where i'll keep my python

play10:16

code

play10:17

as you would guess and the file we've

play10:19

been working on most recently is this

play10:21

one bme 280 cjb

play10:23

a a so to make that executable i'll do a

play10:26

ch

play10:27

mod and a plus x and the file name which

play10:30

is a

play10:31

vm e280 and just because some of you

play10:33

want me to do so

play10:34

i'll press the tab key to complete

play10:36

rather than typing the whole lot

play10:38

and press enter and that will have taken

play10:40

place and if we now do a list again

play10:42

you will see it's now in green so it's

play10:43

an executable file

play10:45

and to check it works we'll do that and

play10:48

we'll type again the file name bme and

play10:50

autocomplete

play10:51

and enter and hopefully yes it's running

play10:55

we've once again got

play10:56

our temperature pressure and humidity

play10:59

readings so

play11:00

with that working we'll stop this with a

play11:02

control c

play11:03

and we'll close down the terminal and

play11:05

we'll now set up the pi to be accessed

play11:07

remotely so to do this we'll go to a

play11:10

preferences

play11:11

and pi configuration and first of all

play11:13

we're going to turn on something called

play11:15

ssh

play11:16

means of accessing the pi over a network

play11:18

which is down here so we'll enable

play11:20

ssh and ok

play11:24

there we are and because we've enabled

play11:26

ssh we should really change the pi's

play11:28

default

play11:29

password which at the moment will be

play11:30

raspberry based on the user name pi

play11:32

so we go in here and we go to a change

play11:35

password

play11:37

if you don't change your password after

play11:38

you've turned on ssh you'll get lots of

play11:40

messages telling you to do so you might

play11:42

as well do it anyway

play11:44

and i'm now going to shut down the

play11:46

raspberry pi

play11:47

and take it outside and put it in my

play11:49

garage or my garage depending on how you

play11:51

want to pronounce it

play11:52

and as you can see it's now running

play11:54

headlessly it's just connected

play11:56

to a power supply and so if we go across

play11:59

to my

play11:59

laptop instantaneously i'm now back

play12:02

indoors where it's much warmer

play12:03

and here i've installed a small piece of

play12:05

software called putty which is an ssh

play12:08

client which you can obtain for free

play12:09

from the address i'm showing you on the

play12:11

screen

play12:12

so we launch putty there we are we enter

play12:15

the hostname

play12:17

raspberry pi like that which is the

play12:19

default hostname for the pi

play12:20

it'll be that unless you've changed it

play12:22

and if we click on open

play12:25

there we are it's come up and just

play12:26

before i put my login details in i'll

play12:28

quickly change the font settings so you

play12:30

can see things better

play12:31

on video so we'll log in as a username

play12:34

pi and the password i just entered when

play12:36

i changed the password which was

play12:38

i think that hopefully there we are

play12:41

we're now logged in

play12:42

i'll do a clear just to make the screen

play12:44

nice and neat and if we now do a

play12:46

list as before we change to

play12:50

python code just as we just did on the

play12:53

pi

play12:53

itself list there we can see there's our

play12:56

file

play12:56

we should be able to execute it with a

play12:59

bme

play13:00

can we autocomplete here we can and

play13:02

enter on that

play13:03

and is it going to run it is and

play13:07

as you can see it's a bit colder

play13:10

outside isn't it and seems to be

play13:13

dropping presumably the sanctuary is

play13:14

acclimatizing to where it is but it's

play13:16

now down to 11.8 11.4

play13:19

or 11.84 i can't read numbers you can

play13:21

see what it is it's clearly colder

play13:23

outside

play13:23

and the humidity is massively higher so

play13:26

clearly we've now got to a point where

play13:28

we can have a raspberry pi remotely

play13:30

potentially lots of raspberry pi's

play13:31

remotely reporting in

play13:33

their data on temperature and pressure

play13:36

and humidity

play13:37

and from that we could try to predict

play13:39

the weather we could see

play13:40

if for example the pressure here which

play13:42

is measured in a hectopascals in case

play13:45

you were you're wondering

play13:46

if the pressure was falling rapidly it

play13:48

means it's likely to rain or potentially

play13:50

snow if it's very cold

play13:52

over here and generally if the humidity

play13:54

is high and rising

play13:55

it's also more likely to rain

play14:04

greetings here i am back again with a

play14:07

monitor keyboard and mouse connected to

play14:10

pi and we're now going to set things up

play14:12

to record

play14:13

weather data over time and because we're

play14:16

working here in a full

play14:17

desktop operating system we happen to

play14:19

have available a spreadsheet in the form

play14:21

of

play14:21

libreoffice calc so we launch up

play14:24

libreoffice calc

play14:26

there we are and what i've done is to

play14:28

create a spreadsheet

play14:29

which i've got down here i've been

play14:31

playing around with error spreadsheets

play14:32

apps to final one

play14:33

and doesn't look very exciting at the

play14:34

moment all it's got at the moment as you

play14:36

can see is five column headings for date

play14:38

time temperature pressure and humidity

play14:41

so

play14:42

what we're going to do is to alter our

play14:43

code so it'll actually put our readings

play14:46

into the spreadsheet

play14:47

where we can look at them manipulate

play14:48

them chart them whatever we wish to do

play14:51

so let's close that down and go back to

play14:53

the genie

play14:54

programming editor there it is

play14:58

and this is our new code let's go back

play15:00

to the top you can see what's going on

play15:02

and first of all we're importing

play15:04

libraries the ones we imported

play15:06

previously

play15:06

but i'm also here importing date time

play15:09

and date time i'm taking dates from that

play15:11

as well

play15:12

which we'll be using in a second and i'm

play15:14

also importing a library called

play15:15

open pi xl and this allows us to

play15:18

manipulate spreadsheets

play15:20

in python and to use this library we

play15:23

first have to install it

play15:24

and so earlier i opened up a terminal

play15:27

and issued the command

play15:28

sudo pip install open pi xl which

play15:31

run through so we had the module on the

play15:33

system

play15:35

anyway here we are back in the code

play15:37

whereas previously we're initializing

play15:38

the sensor

play15:39

taking your first reading and getting

play15:41

rid of it to overcome that first reading

play15:43

being rubbish

play15:44

issue and then after that we're loading

play15:46

in our spreadsheet as you can see

play15:48

and the spreadsheet is here that's

play15:50

whether xlsx

play15:51

sitting in home pipe python code etc and

play15:54

we're setting the sheet to be the first

play15:56

one in

play15:56

the workbook we then get to our loop

play15:59

which is sitting down here

play16:01

where we're going to read the sensor as

play16:02

we did previously although here i'm

play16:04

rounding the values for temperature

play16:06

pressure and humidity when we first take

play16:08

them

play16:08

rounding them to one decimal place which

play16:10

makes life easier in a spreadsheet

play16:11

later on and then we're also collecting

play16:14

the data today

play16:15

and now which is going to be the time

play16:18

i thought we'd then let the news know

play16:20

what is going on we're going to print

play16:21

out

play16:22

we're adding this data to the

play16:23

spreadsheet the date the time and

play16:25

again the things we're actually reading

play16:28

temperature pressure and humidity

play16:30

and then we're going to append the data

play16:32

to the spreadsheet by setting up the row

play16:34

of data which is going to be the date

play16:35

time

play16:36

temperature pressure and humidity and we

play16:38

append it to

play16:39

the spreadsheet we then save the

play16:42

spreadsheet always important to keep

play16:43

saving your spreadsheet when you're

play16:44

adding data

play16:45

and then after that we're going to wait

play16:47

here for 10 minutes

play16:48

which is 600 seconds finally

play16:51

you might notice i've actually put the

play16:53

loop inside a try

play16:55

finally combination and the reason for

play16:57

that is because we're going to have to

play16:58

break into this with control

play16:59

c and we might break in before the

play17:01

spreadsheet's been saved

play17:03

and so because of that was a try finding

play17:05

things set up it means whatever happens

play17:07

it'll execute what's listed on the

play17:08

finally which here is to save the

play17:10

workbook and of course to print

play17:11

goodbye so let's just test this out and

play17:14

because testing doesn't want to take

play17:16

forever i'll change 600 seconds

play17:18

to say i don't know three seconds just

play17:20

to show you what's going on

play17:21

so i'll put that in there and we'll save

play17:24

this and if we execute

play17:25

this code fairly similar to what

play17:28

happened before of course

play17:30

but it basically now tells us it's

play17:31

adding this data to the spreadsheet

play17:33

date time this could be better formatted

play17:35

but it's good enough for now i mainly

play17:37

care about what's going into the

play17:38

worksheet

play17:39

you can see it's adding this stuff in

play17:41

let's do a couple of others

play17:43

another one that'll do and i'll control

play17:46

c

play17:46

to get out of that we'll now go back to

play17:49

our spreadsheet

play17:51

and we'll load it in very exciting isn't

play17:54

it

play17:55

and you will hopefully see

play17:58

yes there we are the data has come into

play18:01

the spreadsheet it's stored date time

play18:03

temperature pressure and humidity and of

play18:05

course we can look at our data here we

play18:07

can chart it if we wanted to this

play18:08

is becoming quite a useful tool for

play18:10

monitoring and potentially predicting

play18:12

the weather so now i'd like to try this

play18:15

out for real so i'm going to select

play18:17

this data and get rid of it select the

play18:18

rows and do a

play18:20

delete effectively reset our spreadsheet

play18:23

we'll save

play18:24

that and we'll come out of this go back

play18:27

to our code and change our time sleep

play18:29

back to

play18:30

600 for those 10 minute increments file

play18:34

and save and i'm now going to shut down

play18:36

the pi

play18:37

and return it to an outdoor location

play18:47

right the pie is now again out in the

play18:49

cold

play18:50

whilst i'm in the warm inside on my

play18:52

windows laptop

play18:53

where i've logged into the pi navigated

play18:55

to the python code

play18:57

directory and you can see we need to run

play18:59

the code here which is a

play19:00

weatherspread.pi i didn't make that

play19:02

executable before so i'm doing it now

play19:04

here

play19:05

remotely by ssh which should be fine

play19:07

there we are

play19:08

let's just list again and you'll see yet

play19:10

it's turned green so

play19:11

let's now execute that code with

play19:15

that and uh like that and execute

play19:18

and we'll see hopefully the pi is going

play19:20

to be giving us some data in a second

play19:22

there we are

play19:23

it knows what time it is oh look it's

play19:25

not very warm is it

play19:26

6.4 degrees centigrade anyway we now

play19:29

know that the next measurement won't be

play19:30

taken for 10 minutes

play19:32

and so i'm now going to leave the pie

play19:33

for a few hours to get on

play19:35

collecting data

play19:39

and here i am back again just over

play19:42

three and a half hours later data's

play19:45

being collected consistently it seems

play19:47

all this

play19:48

lovely data and by the magic of

play19:50

filmmaking we'll go across to a

play19:52

spreadsheet with the data

play19:53

in it there of course various ways this

play19:55

could happen we could download the data

play19:56

from the pi over the network

play19:58

we could get pi to save the data to a

play20:00

usb drive and take it off the pi that

play20:02

way

play20:02

or we could boot up the pi with a

play20:04

keyboard and monitor mouse attached and

play20:06

launched libreoffice calc which is what

play20:08

i've done

play20:08

here and i do find this very interesting

play20:11

this is

play20:12

real weather data isn't it what a

play20:14

weather station

play20:15

should be doing it's allowing us to look

play20:16

at trends in data over time

play20:18

and we can see that the temperature has

play20:20

dropped as it's got darker and colder

play20:22

across the afternoon the pressure has

play20:24

been pretty consistent

play20:26

but the humidity the humidity is

play20:28

definitely increasing here i think it's

play20:29

going to rain fairly soon it's gone from

play20:31

what 72 to 89 humidity i think that

play20:35

suggests

play20:35

we're going to see some rain but anyway

play20:38

in terms of our experiment

play20:40

this has clearly worked we've managed to

play20:42

use the pie to collect some real

play20:44

weather data

play20:51

well there we are we've delved into the

play20:54

use of a raspberry pi

play20:56

for monitoring and potentially

play20:57

predicting the weather

play21:00

in a future video i might try and go

play21:02

further and attempt to use a raspberry

play21:04

pi

play21:04

to actually control the weather although

play21:07

i suspect we'll have to wait for the

play21:09

release of the raspberry pi

play21:10

5 before we're able to do that

play21:14

but now that's it for another video if

play21:16

you've enjoyed it you've seen here

play21:18

please press that like button

play21:19

if you haven't subscribed please

play21:21

subscribe and i hope to talk to you

play21:23

again

play21:24

very soon

play21:41

you

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Raspberry PiBME 280Weather StationData CollectionDIY ProjectTemperature SensorHumidity SensorPressure SensorPython CodingRemote Access