Radio Communication - Wireless Messaging

What is Radio Communication? 📻

Think about walkie-talkies!

🎙️ One person talks → waves travel through the air → another person hears it

micro:bits can do the same thing!

📱 One micro:bit sends a message → 📡 Radio waves → 📱 Other micro:bits receive it

Just like texting, but without phones or WiFi!

Radio Groups 📻

What’s a radio group?

It’s like a channel or chat room number!

Only micro:bits on the SAME group number can talk to each other!

Think: Different group chats on your phone 💬


Project: Wireless Messenger 📱

Let’s build a simple messaging system between micro:bits!

Step 1: Set Up Radio Group

First, we need to choose which “channel” to use.

radio.set_group(1)

This goes at the start of your program (not in a function).

The number can be 0-255 (we’ll use 1)

⚠️ Everyone in your group must use the SAME number!

Step 2: Send a Message (Button A)

When we press button A, let’s send a message!

def on_button_pressed_a():
    radio.send_string("Hello!")

input.on_button_pressed(Button.A, on_button_pressed_a)

This sends “Hello!” to everyone on group 1! 📤

Step 3: Receive Messages 📥

Now we need to LISTEN for incoming messages!

def on_received_string(receivedString):
    # What should we do with the message?

radio.on_received_string(on_received_string)

This function runs automatically when a message arrives!

Step 4: Display Received Messages

Let’s show the message on the LED screen!

def on_received_string(receivedString):
    basic.show_string(receivedString)

radio.on_received_string(on_received_string)

The receivedString variable holds the message that was sent!

Complete Code! 🎉

radio.set_group(1)

def on_button_pressed_a():
    radio.send_string("Hello!")

def on_received_string(receivedString):
    basic.show_string(receivedString)

input.on_button_pressed(Button.A, on_button_pressed_a)
radio.on_received_string(on_received_string)

That’s it! Now let’s test it! 🚀

Step 5: Test in Simulator 🖥️

Let’s try it out!

  1. Click the simulator’s button A
  2. A second micro:bit will appear! 📱📱
  3. Press A again
  4. Watch the message appear on the second micro:bit!

The simulator shows how two micro:bits would communicate!

Time to Chat! 💬

Partner up and try it!

  1. Find a partner with a micro:bit
  2. Make sure you’re both on group 1
  3. One person press button A
  4. Watch the message appear on the other micro:bit!
  5. Try sending messages back and forth!

It’s like texting, but with micro:bits! 📱✨


Advanced Radio Features

Sending Numbers

You can send numbers instead of strings!

def on_button_pressed_a():
    radio.send_number(42)

def on_received_number(receivedNumber):
    basic.show_number(receivedNumber)

input.on_button_pressed(Button.A, on_button_pressed_a)
radio.on_received_number(on_received_number)

Sending Multiple Types

You can send different types of data:

radio.set_group(1)

def on_button_pressed_a():
    radio.send_string("Hello!")

def on_button_pressed_b():
    radio.send_number(100)

def on_received_string(receivedString):
    basic.show_string(receivedString)

def on_received_number(receivedNumber):
    basic.show_number(receivedNumber)

input.on_button_pressed(Button.A, on_button_pressed_a)
input.on_button_pressed(Button.B, on_button_pressed_b)
radio.on_received_string(on_received_string)
radio.on_received_number(on_received_number)

Changing Radio Groups

You can change groups during your program:

radio.set_group(1)  # Start on group 1

def on_button_pressed_a():
    radio.set_group(2)  # Switch to group 2
    basic.show_string("Group 2")

def on_button_pressed_b():
    radio.set_group(1)  # Switch back to group 1
    basic.show_string("Group 1")

input.on_button_pressed(Button.A, on_button_pressed_a)
input.on_button_pressed(Button.B, on_button_pressed_b)

Challenges

Challenge 1: Custom Messages

Can you send different messages with different buttons?

Solution
radio.set_group(1)

def on_button_pressed_a():
    radio.send_string("Hello!")

def on_button_pressed_b():
    radio.send_string("How are you?")

def on_button_pressed_ab():
    radio.send_string("Goodbye!")

def on_received_string(receivedString):
    basic.show_string(receivedString)

input.on_button_pressed(Button.A, on_button_pressed_a)
input.on_button_pressed(Button.B, on_button_pressed_b)
input.on_button_pressed(Button.AB, on_button_pressed_ab)
radio.on_received_string(on_received_string)

Challenge 2: Secret Code System

Create a secret code system! Send numbers that represent different messages:

Solution
radio.set_group(1)

def on_button_pressed_a():
    radio.send_number(1)  # Hello

def on_button_pressed_b():
    radio.send_number(2)  # Goodbye

def on_button_pressed_ab():
    radio.send_number(3)  # Help!

def on_received_number(receivedNumber):
    if receivedNumber == 1:
        basic.show_string("Hello")
    elif receivedNumber == 2:
        basic.show_string("Goodbye")
    elif receivedNumber == 3:
        basic.show_string("Help!")

input.on_button_pressed(Button.A, on_button_pressed_a)
input.on_button_pressed(Button.B, on_button_pressed_b)
input.on_button_pressed(Button.AB, on_button_pressed_ab)
radio.on_received_number(on_received_number)

Challenge 3: Multi-Player Game

Can you create a simple game using radio?

Ideas:

Challenge 4: Remote Control

Make one micro:bit control another!


Radio Communication Tips 💡

  1. Same Group: Make sure all micro:bits you want to communicate are on the same group number
  2. Range: Radio works best within a few meters
  3. Interference: Too many micro:bits on the same group can cause interference
  4. Testing: Use the simulator first to test your code!
  5. Battery: Radio uses more battery, so keep that in mind

Common Issues and Solutions

Problem: Messages not received

Solutions:

Problem: Wrong messages received

Solutions:


What We Learned Today

✓ What radio communication is and how it works
✓ How to set up radio groups
✓ How to send messages between micro:bits
✓ How to receive and display messages
✓ How to send different types of data (strings and numbers)
✓ How to build wireless messaging systems

Key Takeaways

Next Steps

Try creating your own radio projects! Can you make:

The possibilities are endless! Radio communication opens up a whole new world of projects where multiple micro:bits can work together!


Project Ideas

1. Secret Messenger

Create a system where you can send secret coded messages to friends!

2. Multi-Player Rock Paper Scissors

Two micro:bits play Rock, Paper, Scissors and announce the winner!

3. Remote LED Controller

One micro:bit controls the LEDs on another micro:bit!

4. Collaborative Counter

Multiple micro:bits work together to count something!

5. Radio Tag Game

A game where micro:bits send signals to each other - like a digital version of tag!

Have fun experimenting with radio communication! 📻✨

References and Acknowledgements