Radio Messaging
What you'll build¶
micro:bits can talk to each other wirelessly. Flash the sender onto one micro:bit and the receiver onto a second one. Press button A on the sender and the receiver scrolls the message.
Code¶
Flash this onto the first micro:bit.
Flash this onto the second micro:bit.
| 5 radio-receiver.py | |
|---|---|
How it works¶
radio.config(group=5)puts both micro:bits on group 5. Only boards in the same group hear each other, so the sender and receiver must match.radio.on()powers up the radio, which is off by default to save battery.radio.send()broadcasts a string to every micro:bit in range on the same group.radio.receive()returns the next queued message as a string, orNoneif nothing has arrived.
Try this next¶
- Send a different message for button B, and show a different image for each one on the receiver.
- Pick your own group number (0–255) so you don't clash with classmates.
- Add a short
sleep(200)on the sender so holding the button doesn't flood the radio. - Reply from the receiver so both boards can chat.
- Use
radio.receive_full()to read the signal strength and estimate distance.