In this resource, you will be creating a basic weather dashboard to monitor Weather Stations all over the world.
For Scratch to be able to talk to Weather Stations, it needs a little help. There's a complicated Python script you can run that will help Scratch communicate with them.
-
Open a terminal by pressing the
Ctrl
,Alt
andT
keys at the same time, or by clicking on the icon in the left-hand corner of the screen. -
Type the following command into the terminal to get the Python file:
wget -O interface.py rpf.io/wsd
-
That's it: you've downloaded the file. Keep the terminal open though, as you'll need it in a minute.
Now we need to help Scratch talk to the file you've downloaded.
-
Open Scratch by clicking on
Menu
>Programming
>Scratch
. -
Once Scratch opens, you need to enable
remote sensors
. Click on thesensing
button to reveal thesensing blocks
: -
Now find the block called
slider sensor value
and right-click on it. Click onenable remote sensor connections
:
-
Now that Scratch can talk to Python, you need to start the Python script so that it can fetch lots of Weather Station data and send it to Scratch.
-
Go back to the terminal, and type the following:
python3 interface.py
-
If you have your own Weather Station at your school, ask your teacher for the Weather Station's ID. If you don't have one, then you can use the ID in the code below.
-
The first step is simple. You can make the Scratch cat tell you the weather for any particular Weather Station you like. First, grab a
when green flag clicked
block: -
Then click on
Variables
and thenMake a variable
. Call itid
: -
Once you've created the variable, you can set it to your Weather Station's ID. You can find a list of Weather Station IDs here.
-
Now if you go back to the
Sensing
menu in Scratch and find theslider sensor value
block, you should see there's a little black arrow that points downwards, next to the wordslider
. Click this menu and you can change the sensor value to lots of different things: -
To start off with, you can choose
air_pressure
, and then use asay for 2 secs
block (selected fromLooks
) so that the cat will tell you the air pressure at the Weather Station: -
If nothing happens, go back to the terminal and check the output of the
interfaces.py
script. It might be displaying the messageStation data not found. Please choose another ID
. If this is the case, then choose another ID from the list of stations.
Have a play around with different sensor values to see what they do, and what readings they produce. If you like, you could use join
blocks to also get the cat to tell you more than one sensor value:
- In the next worksheet you will learn how to produce a graphical dashboard, to show you the weather at your station using images and animations.