You can already work with micro:bit inputs and the display. Today you will connect two micro:bits with radio so one can send a message and the other can show it.
This is the next part of your coding project. Open the project you saved earlier and keep building at your device: predict first, then build, run and fix.
Keep this short. Devices ready, students logged in, MakeCode open. Frame today as connecting two micro:bits with radio as the next part of the project they already have. Optional predict: before anyone runs code, ask what they think must be true for one micro:bit’s message to appear on the other. Pairs, not whole-class typing. Circulate only if someone cannot open the saved project.
Microbits have a radio transceiver built into them. A transceiver is an electronic device which is a combination of a radio transmitter and a receiver, hence the name. It can both send and receive radio waves using an antenna, for communication purposes.
For this project you will need 2 Microbits so you can send and receive messages.
Read or paraphrase the idea of a transceiver briefly. Stress that every pair needs two micro:bits for a real test. Key question: why does one device alone not prove radio works? No code to type yet. Differentiation: if a pair has only one board, plan for them to use the simulator’s second micro:bit until hardware is free.
Go to the https://makecode.microbit.org website and create a new project.
Model creating or reopening the project on the board. Watch for students starting a blank project when they should continue the saved one, or landing on the wrong editor. Keep pace brisk so time stays on radio blocks.
The first thing we need to do is set the radio group that our Micorbits will be broadcasting on. A radio group is the channel that the Microbit both sends it's messages and listens for other messages. A Microbit can only send or receive in one group at a time.
A Microbit that is on radio group 2 will not be able to receive a message from another Microbit that is on radio group 3. However if they are both on radio group 3 then then we can communicate with each other.
Add the following code to set the radio group to 1.
radio.setGroup(1)
Model radio.setGroup on the board and say both devices must use the same group. Key question: what happens if one micro:bit is on group 1 and the other on group 2? Common bug: pairs pick different numbers. Differentiation: agree a class default group (for example 1) to cut interference between tables, or assign nearby pairs different groups if the room is crowded.
We can send different types of messages, we can send:
Let's start off my sending a string message. Add the following code to send the message "Hello" when you press the A button.
input.onButtonPressed(Button.A, function () {
radio.sendString("Hello")
})
PRIMM: predict what pressing A should do, then add the send-string on button A. Model the onButtonPressed and radio.sendString shape without rewriting the given code. Watch for send placed outside the button handler. Pairs run only after both have the block in place.
You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.