Radio & Communication on BBC micro:bit
Radio & Communication on BBC micro:bit
Send messages between micro:bits and use Bluetooth for phone connectivity.
Radio on the micro:bit
The micro:bit has a 2.4 GHz radio (using the same hardware as Bluetooth) that can communicate directly with other micro:bits ߀” no router or internet required. This is perfect for classroom projects where multiple boards need to talk to each other.
The radio module in MicroPython gives you a simple broadcast API ߀” all boards on the same channel and group receive each other's messages.
Setting Up Radio
import radio
from microbit import *
radio.on() # Must call this before using radio
radio.config(channel=7) # Channel 0߀“83 (default 7)
radio.config(group=1) # Group 0߀“255 (default 0) ߀” only same group receives
radio.config(power=7) # Transmit power 0߀“7 (default 6)
Sending a Message
import radio
from microbit import *
radio.on()
while True:
if button_a.was_pressed():
radio.send("hello")
display.show(Image.ARROW_E)
sleep(200)
display.clear()
Receiving a Message
import radio
from microbit import *
radio.on()
while True:
message = radio.receive()
if message:
display.scroll(message)
sleep(100)
radio.receive() returns a string if a message is waiting, or None if not.
Two-way Communication
Both boards run the same code ߀” they can send and receive:
import radio
from microbit import *
radio.on()
radio.config(group=42)
while True:
if button_a.was_pressed():
radio.send("ping")
display.show(Image.ARROW_E)
sleep(200)
msg = radio.receive()
if msg == "ping":
display.scroll("pong!")
radio.send("pong")
elif msg == "pong":
display.show(Image.HAPPY)
sleep(500)
display.clear()
sleep(50)
Sending Numbers and Data
Radio sends and receives strings. Convert other types explicitly:
# Sender
temp = temperature()
radio.send(str(temp))
# Receiver
msg = radio.receive()
if msg:
value = int(msg)
display.scroll(str(value) + "C")
For structured data, encode as CSV or simple key=value:
radio.send("temp=" + str(temperature()) + ",x=" + str(accelerometer.get_x()))
Radio Details
| Parameter | Range | Default | Effect |
|---|---|---|---|
channel |
0߀“83 | 7 | Frequency offset ߀” change to avoid interference |
group |
0߀“255 | 0 | Logical group ߀” messages only received within same group |
power |
0߀“7 | 6 | Transmit power (7 = maximum range ~70 m line-of-sight) |
length |
max bytes | 32 | Maximum message length |
Bluetooth Overview
The micro:bit also supports Bluetooth Low Energy (BLE) for connecting to phones or tablets via the micro:bit iOS/Android app.
BLE on the micro:bit is primarily used through MakeCode Bluetooth extensions or via the official app. BLE and radio cannot be used simultaneously in MicroPython ߀” the radio module takes over the 2.4 GHz hardware.
Pairing with the micro:bit App
- Download the "micro:bit" app from the App Store or Google Play
- In MakeCode, add the Bluetooth extension
- Use the "Bluetooth Event" blocks to handle connections
- Pair via the app ߀” hold A+B+RESET together when prompted
UART Serial Communication
The micro:bit can also communicate with computers or other devices via UART (serial):
from microbit import uart
uart.init(baudrate=9600, tx=pin0, rx=pin1)
while True:
if uart.any():
data = uart.read()
print("Received:", data)
uart.write("Hello from micro:bit\r\n")
sleep(1000)
I2C on the micro:bit
Connect I2C sensors to pin 19 (SCL) and pin 20 (SDA):
from microbit import i2c
devices = i2c.scan()
print([hex(d) for d in devices])
# Write to address 0x3C
i2c.write(0x3C, bytes([0x00, 0xAF]))
# Read 6 bytes from address 0x68
data = i2c.read(0x68, 6)