Step by step guide on how to create a weather station on Raspberry Pi


⛄Weather StationπŸ’¦


I am only 10 and I have experience of Raspberry Pi. If you have young children or yourself which would love to programme and use the Raspberry pi then we can help.

Today we are going to build a weather station which can be used outside. 

TIP: If you have a case on your pi I would advise you to take it off.☺️

STEP ONE

πŸ‘½ Weather Underground (wu)is a public weather service. That helps you upload data to the WU database.On this page that appears yow will have to enter a email address and username. Assembly is really easy. Just mount the Sense HAT on top of the Raspberry Pi, put it all in the case, and power it up.




STEP TWO

By default, the Raspbian image only utilizes a part of the SD card’s storage (3GB); if the card you used for your Raspbian installation is larger than 3GB, you’ll need to expand the file system to use the whole disk, to make sure you’ll have room for the additional software used in this project.


In the Raspberry Pi Configuration utility shown in the photo below, click the Expand File system button to enable the Pi to use the whole SD card for storage. Making this change will require rebooting your Pi, so don’t be surprised.




STEP THREE
If you want, use this opportunity to change the host name for the Pi device, so you can easily find it on the network later. You can see I’ve named mine pi_weather. If you’re a U.K.-based reader, you’re done; click the OK button and let the Pi reboot.

If you’re outside the U.K., switch to the Localisation tab and make sure the settings are properly configured for your locale, time zone, and keyboard. Click OK and reboot.

Next you’ll need to update the Pi’s core software. Open a terminal window and execute the command:

If you want, use this opportunity to change the host name for the Pi device, so you can easily find it on the network later. You can see I’ve named mine pi_weather. If you’re a U.K.-based reader, you’re done; click the OK button and let the Pi reboot.

If you’re outside the U.K., switch to the Localisation tab and make sure the settings are properly configured for your locale, time zone, and keyboard. Click OK and reboot.

Next you’ll need to update the Pi’s core software. Open a terminal window and execute the command:

sudo apt-get update

This command updates the Pi’s indexes of available software packages. Next, execute:

sudo apt-get upgrade




This command fetches and installs the latest and greatest versions of the Raspbian OS and other software packages installed on the Pi. It will take quite a while.

Install ProjecT Software
The Sense HAT uses its own Python libraries. To install them, go to the terminal window and execute the command:

sudo apt-get install sense-hat

Next, create a directory for the project files:

cd ~
mkdir pi_weather_station
cd pi_weather_station

Then copy the project’s Python source code to the new directory with this command:

wget https://github.com/johnwargo/pi_weather_station/archive/master.zip

and extract the files with this command:

unzip -j master.zip

ConfigurE Project Software
In order to upload data to the Weather Underground service, our Python app needs access to the station ID and station access key you created earlier in the setup process. Open the project’s config.py file in your text editor of choice then populate the STATION_ID and STATION_KEY fields with the appropriate values from your Weather Underground Personal Weather Station:

class Config:
# Weather Underground
STATION_ID = “YOUR_STATION_ID”
STATION_KEY = “YOUR_STATION_KEY”

The project’s main Python app, weather_station.py, has two configuration settings that control how it works. To change these values, open the file in your text editor and look for these lines near the top:

# specifies how often to upload values from the Sense HAT (in minutes)
UPLOAD_INTERVAL = 10 # minutes

The app reads the temperature sensor on the Sense HAT every 10 seconds, for use in calculating ambient temperature. But we don’t want to upload data to Weather Underground that frequently. So, the UPLOAD_INTERVAL variable controls how often the app sends measurements to WU. To change this interval, just change the value to the right of the equal sign.

If you’re testing the app and don’t want your data uploaded to WU until you’re ready, change the value for WEATHER_UPLOAD to False (in Python, case matters, so it has to be False, not false):

# Set to False when testing the code and/or hardware
# Set to True to enable upload of weather data to Weather Underground
WEATHER_UPLOAD = False

Test the Project’s Python App
To run your weather station Python application, open a terminal window, navigate to the folder where you copied the project files and execute the following:

python ./weather_station.py

The terminal window should quickly sprout the following output:

##################################
# Pi Weather Station #
# By John M. Wargo (www.johnwargo.com) #
##################################

Initializing Weather Underground configuration
Successfully read Weather Underground configuration values
Station ID: YOUR_STATION_ID
Initializing the Sense HAT client
Initialization complete!

If you see something like that, you’re golden. If not, figure out what any error messages mean, fix things, then try again. At this point, the application will start collecting data every 10 seconds and uploading it to the Weather Underground every 10 minutes (unless you changed the app’s configuration to change the upload interval).

Start the App Automatically
Finally, you must configure the Raspberry Pi so it executes the Python app on startup. In a terminal window, navigate to the folder where you extracted the project files. Then make the project’s Bash script file executable by executing the following command:

chmod +x start-station.sh

Next, open the Pi user’s session autostart file using the following command:

sudo nano ~/.config/lxsession/LXDE-pi/autostart

Add the following line to the end (bottom) of the file:




@lxterminal -e /home/pi/pi_weather_station/start-station.sh

To save your changes, press Ctrl-O then press the Enter key. Next, press Ctrl-X to exit the nano application. Reboot the Raspberry Pi. When it restarts, the weather station’s Python process should execute in a terminal window.

This command updates the Pi’s indexes of available software packages. Next, execute:

If you want, use this opportunity to change the host name for the Pi device, so you can easily find it on the network later. You can see I’ve named mine pi_weather. If you’re a U.K.-based reader, you’re done; click the OK button and let the Pi reboot.

If you’re outside the U.K., switch to the Localisation tab and make sure the settings are properly configured for your locale, time zone, and keyboard. Click OK and reboot.

Next you’ll need to update the Pi’s core software. Open a terminal window and execute the command:

sudo apt-get update

This command updates the Pi’s indexes of available software packages. Next, execute:

sudo apt-get upgrade

This command fetches and installs the latest and greatest versions of the Raspbian OS and other software packages installed on the Pi. It will take quite a while.

Install ProjecT Software
The Sense HAT uses its own Python libraries. To install them, go to the terminal window and execute the command:

sudo apt-get install sense-hat

Next, create a directory for the project files:

cd ~
mkdir pi_weather_station
cd pi_weather_station

Then copy the project’s Python source code to the new directory with this command:

wget https://github.com/johnwargo/pi_weather_station/archive/master.zip

and extract the files with this command:

unzip -j master.zip

ConfigurE Project Software
In order to upload data to the Weather Underground service, our Python app needs access to the station ID and station access key you created earlier in the setup process. Open the project’s config.py file in your text editor of choice then populate the STATION_ID and STATION_KEY fields with the appropriate values from your Weather Underground Personal Weather Station:

class Config:
# Weather Underground
STATION_ID = “YOUR_STATION_ID”
STATION_KEY = “YOUR_STATION_KEY”

The project’s main Python app, weather_station.py, has two configuration settings that control how it works. To change these values, open the file in your text editor and look for these lines near the top:

# specifies how often to upload values from the Sense HAT (in minutes)
UPLOAD_INTERVAL = 10 # minutes

The app reads the temperature sensor on the Sense HAT every 10 seconds, for use in calculating ambient temperature. But we don’t want to upload data to Weather Underground that frequently. So, the UPLOAD_INTERVAL variable controls how often the app sends measurements to WU. To change this interval, just change the value to the right of the equal sign.

If you’re testing the app and don’t want your data uploaded to WU until you’re ready, change the value for WEATHER_UPLOAD to False (in Python, case matters, so it has to be False, not false):

# Set to False when testing the code and/or hardware
# Set to True to enable upload of weather data to Weather Underground
WEATHER_UPLOAD = False

Test the Project’s Python App
To run your weather station Python application, open a terminal window, navigate to the folder where you copied the project files and execute the following:

python ./weather_station.py

The terminal window should quickly sprout the following output:

##################################
# Pi Weather Station #
# By John M. Wargo (www.johnwargo.com) #
##################################

Initializing Weather Underground configuration
Successfully read Weather Underground configuration values
Station ID: YOUR_STATION_ID
Initializing the Sense HAT client
Initialization complete!

If you see something like that, you’re golden. If not, figure out what any error messages mean, fix things, then try again. At this point, the application will start collecting data every 10 seconds and uploading it to the Weather Underground every 10 minutes (unless you changed the app’s configuration to change the upload interval).

Start the App Automatically
Finally, you must configure the Raspberry Pi so it executes the Python app on startup. In a terminal window, navigate to the folder where you extracted the project files. Then make the project’s Bash script file executable by executing the following command:

chmod +x start-station.sh

Next, open the Pi user’s session autostart file using the following command:

sudo nano ~/.config/lxsession/LXDE-pi/autostart

Add the following line to the end (bottom) of the file:

@lxterminal -e /home/pi/pi_weather_station/start-station.sh

To save your changes, press Ctrl-O then press the Enter key. Next, press Ctrl-X to exit the nano application. Reboot the Raspberry Pi. When it restarts, the weather station’s Python process should execute in a terminal window.

This command fetches and installs the latest and greatest versions of the Raspbian OS and other software packages installed on the Pi. It will take quite a while.

Install ProjecT Software
The Sense HAT uses its own Python libraries. To install them, go to the terminal window and execute the command:

sudo apt-get install sense-hat

Next, create a directory for the project files:

cd ~
mkdir pi_weather_station
cd pi_weather_station

STEP FOUR
Then copy the project’s Python source code to the new directory with this command:

wget https://github.com/johnwargo/pi_weather_station/archive/master.zip

and extract the files with this command:

unzip -j master.zip

ConfigurE Project Software
In order to upload data to the Weather Underground service, our Python app needs access to the station ID and station access key you created earlier in the setup process. Open the project’s config.py file in your text editor of choice then populate the STATION_ID and STATION_KEY fields with the appropriate values from your Weather Underground Personal Weather Station:

STEP FIVE
class Config:
# Weather Underground
STATION_ID = “YOUR_STATION_ID”
STATION_KEY = “YOUR_STATION_KEY”

The project’s main Python app, weather_station.py, has two configuration settings that control how it works. To change these values, open the file in your text editor and look for these lines near the top:

# specifies how often to upload values from the Sense HAT (in minutes)
UPLOAD_INTERVAL = 10 # minutes

The app reads the temperature sensor on the Sense HAT every 10 seconds, for use in calculating ambient temperature. But we don’t want to upload data to Weather Underground that frequently. So, the UPLOAD_INTERVAL variable controls how often the app sends measurements to WU. To change this interval, just change the value to the right of the equal sign.

STEP SIX
If you’re testing the app and don’t want your data uploaded to WU until you’re ready, change the value for WEATHER_UPLOAD to False (in Python, case matters, so it has to be False, not false):

# Set to False when testing the code and/or hardware
# Set to True to enable upload of weather data to Weather Underground
WEATHER_UPLOAD = False

Test the Project’s Python App
To run your weather station Python application, open a terminal window, navigate to the folder where you copied the project files and execute the following:

python ./weather_station.py

The terminal window should quickly sprout the following output:

##################################
# Pi Weather Station #
# By John M. Wargo (www.johnwargo.com) #
##################################

STEP SEVEN
Initializing Weather Underground configuration
Successfully read Weather Underground configuration values
Station ID: YOUR_STATION_ID
Initializing the Sense HAT client
Initialization complete!

If you see something like that, you’re golden. If not, figure out what any error messages mean, fix things, then try again. At this point, the application will start collecting data every 10 seconds and uploading it to the Weather Underground every 10 minutes (unless you changed the app’s configuration to change the upload interval).

STEP EIGHT
Start the App Automatically
Finally, you must configure the Raspberry Pi so it executes the Python app on startup. In a terminal window, navigate to the folder where you extracted the project files. Then make the project’s Bash script file executable by executing the following command:

chmod +x start-station.sh

Next, open the Pi user’s session autostart file using the following command:

sudo nano ~/.config/lxsession/LXDE-pi/autostart

Add the following line to the end (bottom) of the file:

@lxterminal -e /home/pi/pi_weather_station/start-station.sh

To save your changes, press Ctrl-O then press the Enter key. Next, press Ctrl-X to exit the nano application. Reboot the Raspberry Pi. When it restarts, the weather station’s Python process should execute in a terminal window.


I used these instructions from   makezine.com/projects/raspberry-pi-weather-station-mount/
willow











Comments

Popular posts from this blog

Labled Raspberry Pi Diagram.