4.1
Capturing Climate Data
Capturing Climate Data
What to expect
In this activity, you will begin working on a “smart wireless weather station” that captures, displays, and logs outdoor climate data such as temperature, humidity, pressure, and more. For initial testing purposes, you can measure indoor conditions, then move outdoors if weather/ conditions permit.
Connections
You have measured temperature and other sensor data in previous activities. You have also logged data and analyzed the results via the serial monitor. This activity ultimately uses the radio to send and receive data between two micro:bits. This activity should feel familiar to you!
Materials
2 micro:bits with the battery pack connected
1 will act as the data collector and transmitter (TX)
1 (or more) will act as the data receiver (RX) and organizer
1 Weather:bit development board (from the SparkFun micro:climate kit)
Optional: IR Thermometer (from Unit 1)
Instructions
Part 1 of 3: Capturing BME280 Sensor Data
The serial monitor is a helpful way to see what data is “streaming” through the micro:bit and is useful for debugging.
Dock micro:bit #1 (TX) into the weather:bit board with the LED matrix facing up (towards you). Connect the battery pack (you’ll need this later).
Create a new makecode project and name it “4.1.1 Weather Station Climate Data SERIAL”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
As you begin, it may be helpful to compare your data with a reference. Take a look at: https://openweathermap.org/city/4887398 for current outdoor climate conditions. You may also find it helpful to use the IR thermometer (from Unit 1) to verify temperature.
Although there is an extension for the weather:bit board, we will not use that for this activity. Instead, find and add the extension that reports values from the BME280 sensor directly.
4. Add the following code blocks to capture BME280 sensor (light blue blocks are found in “BME280” extension tab) data and display results via the serial monitor.
Programming note: The dark blue “serial write value” and similar blocks are found in “Serial” under the “Advanced” tab.
Temperature in degrees celsius (C).
Humidity (%).
Dew Point in degrees celsius (C).
Barometric pressure in hectopascals (hPa).
5. Download the code onto your microbit.
6. You can test the climate sensors by looking at the serial monitor. Make sure you choose “Show data Device” to see the real data coming from your weather:bit.
7. Based on the code you created, when you press the ‘A’ button, you should see your results updated in the stream.
Programming note: The data shown here will be unique to your environment, but should be somewhat similar to this example.
Part 2 of 3: Organizing a Collection of Data
Sometimes systems work better when data is organized into a collection of related items. In databases, this data is often grouped by “comma-separated values” or CSV. Then, CSV files can be imported into spreadsheet programs for easier analysis and visualization, especially if you have a lot of data points!
Create a new makecode project and name it “4.1.2 Weather Station Climate Data CSV”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
Programming note: Similarly to part 1, download the “BME280” micro:bit extension
Create the following code to group your collection of sensor data in a CSV. Find the “join” block in the text blocks (under advanced). To add more places for text (a.k.a. String values), use the + sign in the block. You’ll need to manually add commas in between each sensor value.
3. Press the ‘A’ button to collect data, upload your data, and view it in the serial monitor to make sure it looks like a string of sensor values with a comma in between each value in the serial data stream.
4. While there is an option to export your data as a CSV directly, it seems to work best if you export your serial stream as a text (.TXT) file. Export this file to an easy to find location for the next step.
5. Analyze your data in a spreadsheet. Open Google Sheets. Choose ‘File’ > ‘Import’… Then, UPLOAD your .txt file (what you exported from makecode). Make sure to choose ‘replace spreadsheet’. For separator type, you can select ‘comma’, or ‘detect automatically’. Click on ‘Import data’ to create your table
6. When the data is created, it will be just the raw results, so you may want to do some formatting and a header row with the titles of each climate sensor like this:
7. Your dataset would be more useful if it had timestamps with each row of sensor data. Return to your makecode program and make some modifications: Go to add extensions and search for “time”. Add the software-based Real-time Clock (RTC).
7. In the start block, set up the current date and time. You can use 12- or 24-hour time.
9.Add timestamp functionality to your CSV output program.
Programming note: Refer back to step 2 for guidance on how to achieve this.
10.Follow the steps from the previous section to create a table that now includes timestamp data. You can split the timestamp data into two separate columns by adding a blank column to the right of the timestamp in your sheet (if it isn’t already blank), then highlight the timestamp column. Go to the Data menu and choose “Split text to columns”. Make any formatting changes you’d like. Your table will now look similar to the example below.
11. Try making a graph of the sensor data over time. If you want to come back to this later, you can. The last part of this activity is brief, but essential for upcoming activities! Try highlighting the entire ‘Time’ column. Next, hold ‘control’ on your keyboard and highlight another row of data you would like to plot. Hit ‘Insert’ > ‘Chart’... Then, use the ‘Chart Editor’ to customize your graph.
Part 3 of 3: Sending and Receiving Data Wirelessly Between Devices
The final part of this activity is designed to help get you started with sending (or transmitting a.k.a. “TX”) and receiving (a.k.a “RX) climate sensor data between multiple devices. This will be an important part of your wireless weather station system in future activities.
TX
Micro:bit #1 is used to transmit the data over radio.
Dock micro:bit #1 (TX) into the weather:bit board and connect the battery pack.
Create a new makecode project and name it “4.1.3.1 Weather Station Climate Data TX”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
Add the BME280 extension.
Create the following code. Make sure that your “radio set group” value is unique to your group and that no one else is using the same value.
5. Download your program, then disconnect the TX micro:bit, but leave it connected to the battery pack (and weather:bit) for the next step.
RX
Micro:bit #2 (RX) will stay connected to the computer for serial monitoring.
6. Create a new makecode project and name it “4.1.3.2 Weather Station Climate Data RX”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
7. Create the following code on the RX micro:bit. Make sure to use the SAME “radio set group” value as you used on TX! (Or you may get someone else’s broadcast…)
Programming note: Drag ‘receivedString’ down to the text bubble.
Keep the RX micro:bit connected to your computer. Open makecode and ‘show device’. Note: The program in makecode doesn’t matter here, because you are just looking at the serial monitor.
When you press the ‘A button’ on TX, you should see the results on RX!
Wrap-up
You created examples of capturing, collecting, sending, and receiving climate data.
Programming note: The micro:bit radio has a maximum unobstructed range (a.k.a line-of-sight) of about 70 meters (at power level 7 – default without coding it is level 6). Try moving the TX micro:bit around to see how far you can send and receive the signals!
How far could you move the TX? Could you go outdoors?
How often do you think weather station data needs to be collected?
Feedback Link
How did you feel about this activity? Change the emoji to show your feelings.
Next Activity
In the next activity, you will incorporate the OLED display from the Kitronik IAQ board to create a wireless weather station console!
Acknowledgments
Activities from this unit utilize the SparkFun micro:climate kit. Some parts of these activities have been adapted or inspired by https://learn.sparkfun.com/tutorials/microclimate-kit-experiment-guide
This project is intended for experimental and academic purposes only.