What to expect
In this activity, you will use the Kitronik Indoor Air Quality (IAQ) board attached to a second micro:bit that will receive the information being broadcast from your weather station (micro:bit #1, connected to the weather:bit). Then, you will display the outdoor climate data on the OLED display of the IAQ board.
Connections
This activity uses the OLED display of the IAQ board and radio signal concepts similar to previous activities.
Materials
(2) micro:bits
Kitronik IAQ board
weather:bit
Instructions
Part 1 of 2: TX micro:bit #1 is used to transmit the climate sensor data over radio.
Dock micro:bit #1 (TX) into the weather:bit board with the LED matrix facing up (towards you). Connect the battery pack.
2. Create a new makecode project and name it “4.2.1 TX Sensors”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
3. Add the BME 280 extension.
4. Create the following code. The way you’ll send your sensor data here is a little different than in the previous activity. In this example, sensor data is broadcast over radio using “key values”. Key values are a good way to encode/ decode data to be sent over the radio, but the string (key) must be 8 characters or less, and the value must be a number. For more info on how any blocks work, you can always right-click on them and look at their help menu! 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 the code and disconnect the TX micro:bit from the computer, but leave it powered on by the connected battery pack.
Programming note: You will need to create the RX program on micro:bit #2 to get these values (next part.)
Part 2 of 2: RX
Using a second micro:bit docked to the IAQ board, you will receive the signal(s) broadcast from the TX micro:bit and display them on the IAQ board OLED display.
Create a new makecode project and name it “4.2.2 RX Console”. Install the IAQ extension. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
Programming note: Only the extension for micro:bit V2 called “kitronik-air-quality-v2-only” will work with our version of the micro:bit
2. Create the following code on the RX micro:bit. In this example, you’ll send a number to micro:bit to tell it to report the sensor values back to you. Make sure to use the same “radio set group” value as you used on TX! (Or you may get someone else’s broadcast by mistake…)
Programming note: Comments have been added to describe the operation of the program. You can add your own or leave these out of your code. There are two “=” blocks: one with quotations and one without. The “=” with quotations should be used in this step to avoid an error.
3. Once you verify that your micro:bits are communicating sensor data and it's displayed correctly on the IAQ OLED display, modify your program to include the time and date. Don’t forget to add the RTC extension.
Programming note: You can drag and drop the red ‘name’ and ‘value’ blocks from the pink ‘on radio received name value’ block into other sections of code.
4. In the ‘On start’ block, you’ll need to set the current time and date. In this example, you’ll need to update this any time you make changes to your program and download it to keep the time current. You’ll see another way to deal with this in a later activity.
5. Your modified program should look something like this.
6. Finally, include the ability to send and receive sensor data when the ‘A’ button is pressed or on each new minute of time. Download and test everything out to make sure it works as expected.
Programming note: Comments have been added to describe the operation of the program. You can add your own or leave these out of your code.
Wrap-up
Congratulations! You now have a wireless weather station console that displays data that is being captured from a remote location. In the next activity, you will add additional sensors and meters that measure wind speed and direction.
Did you notice that micro:bit #1 is acting a little like an RX, as it is “listening for any number coming from micro:bit #2? And micro:bit #2 is acting like a TX at times, when you are sending number values to micro:bit #1?
What types of challenges did you experience in this activity and how did you overcome them?
Feedback Link
How did you feel about this activity? Change the emoji to show your feelings.
Next Activity
Acknowledgments
Activities from this unit utilize the SparkFun micro:climate kit. Activities have been adapted and/or derived from https://learn.sparkfun.com/tutorials/microclimate-kit-experiment-guide
This project is intended for experimental and academic purposes only.