4.6 Advanced Concepts
What to expect
In this optional activity, you will learn how to add advanced features and workarounds to your weather station project such as remotely resetting the TX device, remotely changing the time, and creating a “signal relay network” to make your wireless signals travel further.
Connections
This activity uses “coding tricks” to help make your weather station project more robust. You may consider using these in your project, but they are not required for basic functionality.
Materials (Vary Depending on Project)
3+ micro:bits with the battery pack connected
Weather station project
Instructions
Remote-controlled Reset
Currently, the weather:bit extension only tracks accumulated rain since the micro:bit is powered on (or reset). So, one workaround to clear the rain data back to zero is to send a remote signal to the TX device to reset. This is easily performed as follows.
Create a new makecode project and name it “4.6.1 TX Reset”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
For testing purposes, use a pair of micro:bits that are not attached to your weather station project. (You’ll be able to update those later if you want.) On micro:bit #1 (TX) add the following code:
Create a new makecode project and name it “4.6.2 RX Reset”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
Add the following code. Download to micro:bit #2 (RX). Test it out by pressing the ‘A’ button on TX. You should see an ‘X’ appear on the RX, then it will reset. Once it is reset, it will show a heart icon again. The ‘reset’ command can be found under the advanced blocks, in the ‘control’ group.
Programmer’s note: Test this functionality carefully (i.e., make sure your radio set group is correct, or you might be resetting someone else’s project!) Hint: You can use a different number than what is shown, which may provide a bit more “security”. Right-click and choose help on ‘radio send number’ for more info about using the block.
Optional: Apply this concept to your weather station project. Hint: You can use the time and date blocks to do something after a certain number of hours. Hint 2: There can only be one instance of the ‘On radio received number’ in a program, so you’ll have to get creative with your logic conditions…
Adjusting the Time and Date Remotely
This experiment will work best if you use two different computers, each connected to a micro:bit (should not be connected to the weather:bit or the IAQ board). In this experiment we will send the new date information from the TX micro:bit as strings. Once the strings are received on the RX micro:bit, it will set these new values as the date.
Programmer #1 (micro:bit #1)
Create a new makecode project and name it “4.6.3 TX Time Changer Remote”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME!
Create the following code on a micro:bit #1. Important: Make sure your unique radio set group matches your other devices!
Programmer #2 (micro:bit #2)
Create a new makecode project and name it “4.6.4 RX Time Changer Remote”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME! Add the following code, download it, and test it out by using the serial monitor for debugging.
Programming note: Attach the RX micro:bit to the computer and check the serial monitor. Press the ‘A’ button on the TX micro:bit. You should then see values appear in the monitor.
Optional: Apply this concept to your weather station project.
Signal Relay Network
In this experiment, you will make your wireless data travel farther by using one (or more) micro:bits to “relay” the signal. You will need 3 or 4 micro:bits for this experiment, so pair up with additional group members.
Since the micro:bits in this activity perform similar functions, the code for each micro:bit will be very similar. The exception to this general rule is the ID# that you will set for each one.
Create a new makecode project and name it “4.6.5 Signal Relay A”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME! Add the following code.
Download the code to micro:bit (A). Disconnect from the computer, but keep it connected to the battery pack for now.
Duplicate the program you just created, but call the new program “4.6.5 Signal Relay B”. Add the following code that listens for the number you sent from (A). Once micro:bit (B) receives the number, it will confirm that it was received. Micro:bit (B) will also send a signal out when it receives another number. This is an example of a “signal chain”.
Download and test your program. Does micro:bit (B) get the signal from micro:bit (A)? If so, disconnect it and keep it connected to a battery.
Duplicate the program you just created, but call the new program “4.6.6 Signal Relay C”. MAKE SURE TO COPY NAME EXACTLY BECAUSE SPECIFIC MAKECODE PROJECT MAY BE REFERENCED LATER BY NAME! Add the following code that listens for the number you sent from (B). Note: Try spacing the three micro:bits out as far as possible. In theory, you could add a fourth or more micro:bits in this same way to create the signal relay chain. You can also set the radio transmit power level to 7 in the ‘on start’ block. (Default is 6 if not included).
Press the ‘A’ button on micro:bit (A) and notice it sends a signal to micro:bit (B), then micro:bit (B) sends a signal to micro:bit (C). To verify this, disconnect the battery from micro:bit (B) and try to send the signal from micro:bit (A) again. Does micro:bit (C) work like you expect?
Wrap-up
You learned how to create a remote-controlled reset, remote-control time adjuster, and how to add multiple micro:bit devices into a signal chain to increase the distance from the transmitter to the final receiver.
Feedback Link
How did you feel about this activity? Change the emoji to show your feelings.
This project is intended for experimental and academic purposes only.