Page 11 of 36
Start Weather Monitoring
When the script starts, we use this block to start or initiate the BME280
sensor and get it ready to take readings. Anytime you want to use the
temperature, humidity, pressure or altitude blocks, you need to have this
block in your
block.
on start
Set Item To
We use a variable called
to keep track of which data are being
item
displayed on the LED array. If
is equal to 0, it shows the temperature;
item
if 1, it shows the humidity; if 2, the pressure. If the variable goes over 2, we
reset it to 0. We increment the variable by pressing the A button.
Temperature (°C)
This variable returns a number that you then have to divide by 100 to get
the temperature in Celsius.
Humidity
This variable returns a number that you need to divide by 1,024 to get the
relative humidity.
Pressure
This variable returns a number that you divide by 25,600 to get the
atmospheric pressure in hPa.
Why All of the Math?
This is a good question! It all comes down to accuracy of the data that you
receive. MakeCode cannot handle floating point numbers (numbers with
decimal points) yet. Which can be troublesome for getting really accurate
readings from the BME280 with a single variable block. So, to as accurate
of values as possible you have to do some math in the programming
environment. We know, not fun! But, hey now you might pay attention in
math class a bit more now.
What You Should See
Once your code is loaded, you should start to see numbers scroll across
the LED array on your micro:bit, beginning with the temperature in Celsius.
If you press the left button on your micro:bit, the number will change to
percent humidity; press it again, and it will be pressure. Pretty cool...well,
hmmm...maybe warm?
Need help?
Do you have a question about the micro climate Kit and is the answer not in the manual?
Questions and answers